Browse Source

fix(nocodb): Added default sort to exclude api

pull/3853/head
Muhammed Mustafa 2 years ago
parent
commit
33f20d6ad6
  1. 26
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  2. 36
      packages/nocodb/tests/unit/rest/tests/tableRow.test.ts

26
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -878,6 +878,14 @@ class BaseModelSqlv2 {
const filterObj = extractFilterFromXwhere(where, aliasColObjMap);
await conditionV2(filterObj, qb, this.dbDriver);
// sort by primary key if not autogenerated string
// if autogenerated string sort by created_at column if present
if (childTable.primaryKey && childTable.primaryKey.ai) {
qb.orderBy(childTable.primaryKey.column_name);
} else if (childTable.columns.find((c) => c.column_name === 'created_at')) {
qb.orderBy('created_at');
}
applyPaginate(qb, rest);
const proto = await childModel.getProto();
@ -978,6 +986,14 @@ class BaseModelSqlv2 {
const filterObj = extractFilterFromXwhere(where, aliasColObjMap);
await conditionV2(filterObj, qb, this.dbDriver);
// sort by primary key if not autogenerated string
// if autogenerated string sort by created_at column if present
if (childTable.primaryKey && childTable.primaryKey.ai) {
qb.orderBy(childTable.primaryKey.column_name);
} else if (childTable.columns.find((c) => c.column_name === 'created_at')) {
qb.orderBy('created_at');
}
applyPaginate(qb, rest);
const proto = await childModel.getProto();
@ -1079,6 +1095,16 @@ class BaseModelSqlv2 {
const filterObj = extractFilterFromXwhere(where, aliasColObjMap);
await conditionV2(filterObj, qb, this.dbDriver);
// sort by primary key if not autogenerated string
// if autogenerated string sort by created_at column if present
if (parentTable.primaryKey && parentTable.primaryKey.ai) {
qb.orderBy(parentTable.primaryKey.column_name);
} else if (
parentTable.columns.find((c) => c.column_name === 'created_at')
) {
qb.orderBy('created_at');
}
applyPaginate(qb, rest);
const proto = await parentModel.getProto();

36
packages/nocodb/tests/unit/rest/tests/tableRow.test.ts

@ -2077,6 +2077,42 @@ function tableTest() {
}
})
it('Exclude list bt', async () => {
const rowId = 1;
const addressTable = await getTable({project: sakilaProject, name: 'address'});
const cityColumn = (await addressTable.getColumns()).find(
(column) => column.title === 'City'
)!;
const response = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${addressTable.id}/${rowId}/bt/${cityColumn.id}/exclude`)
.set('xc-auth', context.token)
.expect(200);
expect(response.body.pageInfo.totalRows).equal(599)
expect(response.body.list[0]['City']).equal('A Corua (La Corua)')
})
it('Exclude list bt with offset', async () => {
const rowId = 1;
const addressTable = await getTable({project: sakilaProject, name: 'address'});
const cityColumn = (await addressTable.getColumns()).find(
(column) => column.title === 'City'
)!;
const response = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${addressTable.id}/${rowId}/bt/${cityColumn.id}/exclude`)
.set('xc-auth', context.token)
.query({
limit: 40,
offset: 60
})
.expect(200);
expect(response.body.pageInfo.totalRows).equal(599)
expect(response.body.list[0]['City']).equal('Baybay')
})
it('Create nested hm relation with invalid table id', async () => {
const rowId = 1;
const rentalListColumn = (await customerTable.getColumns()).find(

Loading…
Cancel
Save