From 37ba072ded1698b327521b5fcf54d544bf30c44e Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 11 Nov 2023 16:52:49 +0300 Subject: [PATCH] fix: options object for list Signed-off-by: mertmit --- packages/nocodb/src/db/BaseModelSqlv2.ts | 29 +++++++++++++++---- packages/nocodb/src/services/datas.service.ts | 8 ++--- packages/nocodb/tests/unit/factory/row.ts | 2 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 6018d06e04..8391b05a4a 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -265,10 +265,20 @@ class BaseModelSqlv2 { sort?: string | string[]; fieldsSet?: Set; } = {}, - ignoreViewFilterAndSort = false, - validateFormula = false, - throwErrorIfInvalidParams = false, + options: { + ignoreViewFilterAndSort?: boolean; + ignorePagination?: boolean; + validateFormula?: boolean; + throwErrorIfInvalidParams?: boolean; + } = {}, ): Promise { + const { + ignoreViewFilterAndSort = false, + ignorePagination = false, + validateFormula = false, + throwErrorIfInvalidParams = false, + } = options; + const { where, fields, ...rest } = this._getListArgs(args as any); const qb = this.dbDriver(this.tnPath); @@ -359,7 +369,7 @@ class BaseModelSqlv2 { qb.orderBy('created_at'); } - applyPaginate(qb, rest); + if (!ignorePagination) applyPaginate(qb, rest); const proto = await this.getProto(); let data; @@ -370,7 +380,11 @@ class BaseModelSqlv2 { if (validateFormula || !haveFormulaColumn(await this.model.getColumns())) throw e; console.log(e); - return this.list(args, ignoreViewFilterAndSort, true); + return this.list(args, { + ignoreViewFilterAndSort, + ignorePagination, + validateFormula: true, + }); } return data?.map((d) => { d.__proto__ = proto; @@ -1891,7 +1905,10 @@ class BaseModelSqlv2 { }), ], }, - true, + { + ignoreViewFilterAndSort: true, + ignorePagination: true, + }, ); const groupedList = groupBy(data, pCol.title); diff --git a/packages/nocodb/src/services/datas.service.ts b/packages/nocodb/src/services/datas.service.ts index 2eea3c1c84..1b9b886e2d 100644 --- a/packages/nocodb/src/services/datas.service.ts +++ b/packages/nocodb/src/services/datas.service.ts @@ -170,12 +170,10 @@ export class DatasService { try { data = await nocoExecute( ast, - await baseModel.list( - listArgs, + await baseModel.list(listArgs, { ignoreViewFilterAndSort, - false, - param.throwErrorIfInvalidParams, - ), + throwErrorIfInvalidParams: param.throwErrorIfInvalidParams, + }), {}, listArgs, ); diff --git a/packages/nocodb/tests/unit/factory/row.ts b/packages/nocodb/tests/unit/factory/row.ts index 286c0bed9f..3d0140ac5a 100644 --- a/packages/nocodb/tests/unit/factory/row.ts +++ b/packages/nocodb/tests/unit/factory/row.ts @@ -232,7 +232,7 @@ const listRow = async ({ const ignorePagination = !options; - return await baseModel.list(options, ignorePagination); + return await baseModel.list(options, { ignorePagination }); }; const getOneRow = async (