@sdflc/backend-helpers 1.0.73 → 1.0.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,9 +26,10 @@ declare class BaseGateway {
26
26
  getDb(): Database;
27
27
  getBuilder(): any;
28
28
  getIdField(): string;
29
+ getIdFieldUpdateRemove(): string;
29
30
  get(id: any): Promise<any>;
30
31
  getMany(ids: any[]): Promise<any>;
31
- buildListQuery(args?: BuildListQueryArgsInterface): any;
32
+ buildListQuery(args?: BuildListQueryArgsInterface): Promise<any>;
32
33
  list(args?: ListArgsInterface): Promise<any>;
33
34
  create(args: any): Promise<any[]>;
34
35
  update(where: any, params: any): Promise<any>;
@@ -81,8 +81,9 @@ class BaseGateway {
81
81
  if (hasLang && (filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]) != undefined) {
82
82
  query.whereIn(`${table}.${constants_1.FIELDS.LANG}`, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.LANG]));
83
83
  }
84
- if (filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]) {
85
- query.whereIn(`${table}.${constants_1.FIELDS.ID}`, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[this.getIdField()]));
84
+ const idField = this.getIdField();
85
+ if (filterParams === null || filterParams === void 0 ? void 0 : filterParams[idField]) {
86
+ query.whereIn(idField.includes('.') ? `${idField}` : `${table}.${idField}`, (0, lodash_1.castArray)(filterParams === null || filterParams === void 0 ? void 0 : filterParams[idField]));
86
87
  }
87
88
  if (fieldForKeyword && filterParams.keyword) {
88
89
  query.whereRaw(`${fieldForKeyword} ILIKE ?`, `%${filterParams.keyword}%`);
@@ -97,7 +98,7 @@ class BaseGateway {
97
98
  return __awaiter(this, void 0, void 0, function* () {
98
99
  // This function should be overriden
99
100
  const { hasStatus, hasVersion } = this.config;
100
- const idName = this.getIdField();
101
+ const idName = this.getIdFieldUpdateRemove();
101
102
  let filtersAppliedQty = 0;
102
103
  if (filterParams[idName]) {
103
104
  filtersAppliedQty++;
@@ -129,7 +130,7 @@ class BaseGateway {
129
130
  let filtersAppliedQty = 1;
130
131
  if (arr.length > 0) {
131
132
  filtersAppliedQty++;
132
- query = query.whereIn(this.getIdField(), arr.map((item) => item[this.getIdField()]));
133
+ query = query.whereIn(this.getIdFieldUpdateRemove(), arr.map((item) => item[this.getIdField()]));
133
134
  }
134
135
  if (hasStatus === true) {
135
136
  filtersAppliedQty++;
@@ -283,6 +284,9 @@ class BaseGateway {
283
284
  getIdField() {
284
285
  return this.config.idField || constants_1.ID_FIELD;
285
286
  }
287
+ getIdFieldUpdateRemove() {
288
+ return this.config.idFieldUpdateRemove || this.config.idField || constants_1.ID_FIELD;
289
+ }
286
290
  get(id) {
287
291
  return __awaiter(this, void 0, void 0, function* () {
288
292
  return this.loader.load(id);
@@ -294,10 +298,12 @@ class BaseGateway {
294
298
  });
295
299
  }
296
300
  buildListQuery(args) {
297
- const { fieldsToUse } = args || {};
298
- const query = this.getBuilder();
299
- query.select(fieldsToUse);
300
- return query;
301
+ return __awaiter(this, void 0, void 0, function* () {
302
+ const { fieldsToUse } = args || {};
303
+ const query = this.getBuilder();
304
+ query.select(fieldsToUse);
305
+ return { query };
306
+ });
301
307
  }
302
308
  list(args) {
303
309
  return __awaiter(this, void 0, void 0, function* () {
@@ -308,7 +314,7 @@ class BaseGateway {
308
314
  }
309
315
  const shouldUseCache = useCache != null ? useCache : !this.config.noCache;
310
316
  const fieldsToUse = !shouldUseCache && Array.isArray(this.config.selectFields) ? this.config.selectFields : this.getIdField();
311
- const query = this.buildListQuery({ filter, params, fieldsToUse, useCache: shouldUseCache });
317
+ const { query } = yield this.buildListQuery({ filter, params, fieldsToUse, useCache: shouldUseCache });
312
318
  yield this.onListFilter(query, filter);
313
319
  if (limit && !isNaN(limit) && limit > 0) {
314
320
  query.offset(offset).limit(limit);
@@ -7,6 +7,7 @@ export interface BaseGatewayPropsInterface extends CacheInterface {
7
7
  context: ApiContext;
8
8
  table?: string;
9
9
  idField?: string;
10
+ idFieldUpdateRemove?: string;
10
11
  idFieldAs?: string;
11
12
  setFields?: string[] | string;
12
13
  mergeFields?: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdflc/backend-helpers",
3
- "version": "1.0.73",
3
+ "version": "1.0.76",
4
4
  "description": "Set of helper functions and classes to simplify building backend apps within @sdflc ecosystem",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",