@sdflc/backend-helpers 1.0.75 → 1.0.77

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,6 +26,7 @@ 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
32
  buildListQuery(args?: BuildListQueryArgsInterface): 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,8 @@ 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
+ const idName = this.getIdFieldUpdateRemove();
134
+ query = query.whereIn(idName, arr.map((item) => item[idName]));
133
135
  }
134
136
  if (hasStatus === true) {
135
137
  filtersAppliedQty++;
@@ -283,6 +285,9 @@ class BaseGateway {
283
285
  getIdField() {
284
286
  return this.config.idField || constants_1.ID_FIELD;
285
287
  }
288
+ getIdFieldUpdateRemove() {
289
+ return this.config.idFieldUpdateRemove || this.config.idField || constants_1.ID_FIELD;
290
+ }
286
291
  get(id) {
287
292
  return __awaiter(this, void 0, void 0, function* () {
288
293
  return this.loader.load(id);
@@ -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.75",
3
+ "version": "1.0.77",
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",