@sdflc/backend-helpers 1.0.75 → 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,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,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);
@@ -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.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",