@sdflc/backend-helpers 1.0.42 → 1.0.45
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.
package/build/BaseGateway.js
CHANGED
|
@@ -84,10 +84,10 @@ var BaseGateway = /** @class */ (function () {
|
|
|
84
84
|
};
|
|
85
85
|
BaseGateway.prototype.onListFilter = function (query, filterParams) {
|
|
86
86
|
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
-
var _a, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword;
|
|
88
|
-
var _b;
|
|
89
|
-
return __generator(this, function (
|
|
90
|
-
_a = this.config || {}, hasStatus = _a.hasStatus, hasRemovedAt = _a.hasRemovedAt, hasSpace = _a.hasSpace, activeStatuses = _a.activeStatuses, hasLang = _a.hasLang, fieldForKeyword = _a.fieldForKeyword;
|
|
87
|
+
var _a, hasStatus, hasRemovedAt, hasSpace, activeStatuses, hasLang, fieldForKeyword, filterByUserField;
|
|
88
|
+
var _b, _c;
|
|
89
|
+
return __generator(this, function (_d) {
|
|
90
|
+
_a = this.config || {}, hasStatus = _a.hasStatus, hasRemovedAt = _a.hasRemovedAt, hasSpace = _a.hasSpace, activeStatuses = _a.activeStatuses, hasLang = _a.hasLang, fieldForKeyword = _a.fieldForKeyword, filterByUserField = _a.filterByUserField;
|
|
91
91
|
// This function should be overriden
|
|
92
92
|
if (hasStatus) {
|
|
93
93
|
query.whereIn(constants_1.FIELDS.STATUS, Array.isArray(filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS]) ? filterParams === null || filterParams === void 0 ? void 0 : filterParams[constants_1.FIELDS.STATUS] : (0, lodash_1.castArray)(activeStatuses));
|
|
@@ -109,6 +109,9 @@ var BaseGateway = /** @class */ (function () {
|
|
|
109
109
|
if (fieldForKeyword && filterParams.keyword) {
|
|
110
110
|
query.whereRaw("".concat(fieldForKeyword, " ILIKE ?"), "%".concat(filterParams.keyword, "%"));
|
|
111
111
|
}
|
|
112
|
+
if (filterByUserField) {
|
|
113
|
+
query.where((_c = {}, _c[filterByUserField] = this.getContext().userId, _c));
|
|
114
|
+
}
|
|
112
115
|
return [2 /*return*/];
|
|
113
116
|
});
|
|
114
117
|
});
|
|
@@ -157,9 +160,9 @@ var BaseGateway = /** @class */ (function () {
|
|
|
157
160
|
};
|
|
158
161
|
BaseGateway.prototype.transformOnCreate = function (params) {
|
|
159
162
|
return __awaiter(this, void 0, void 0, function () {
|
|
160
|
-
var _a, hasCreatedAt, hasCreatedBy, hasSpace, hasVersion, hasLang, localizationForField;
|
|
163
|
+
var _a, hasCreatedAt, hasCreatedBy, hasSpace, hasVersion, hasLang, localizationForField, hasUserId;
|
|
161
164
|
return __generator(this, function (_b) {
|
|
162
|
-
_a = this.config, hasCreatedAt = _a.hasCreatedAt, hasCreatedBy = _a.hasCreatedBy, hasSpace = _a.hasSpace, hasVersion = _a.hasVersion, hasLang = _a.hasLang, localizationForField = _a.localizationForField;
|
|
165
|
+
_a = this.config, hasCreatedAt = _a.hasCreatedAt, hasCreatedBy = _a.hasCreatedBy, hasSpace = _a.hasSpace, hasVersion = _a.hasVersion, hasLang = _a.hasLang, localizationForField = _a.localizationForField, hasUserId = _a.hasUserId;
|
|
163
166
|
if (hasCreatedAt) {
|
|
164
167
|
params[constants_1.FIELDS.CREATED_AT] = this.dateTime.dbFormat(this.dateTimeNow);
|
|
165
168
|
}
|
|
@@ -168,6 +171,11 @@ var BaseGateway = /** @class */ (function () {
|
|
|
168
171
|
params[constants_1.FIELDS.CREATED_BY] = this.getContext().userId;
|
|
169
172
|
}
|
|
170
173
|
}
|
|
174
|
+
if (hasUserId) {
|
|
175
|
+
if (params[constants_1.FIELDS.USER_ID] === undefined) {
|
|
176
|
+
params[constants_1.FIELDS.USER_ID] = this.getContext().userId;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
171
179
|
if (hasSpace) {
|
|
172
180
|
params[constants_1.FIELDS.SPACE_ID] = this.getContext().spaceId;
|
|
173
181
|
}
|
|
@@ -209,9 +217,9 @@ var BaseGateway = /** @class */ (function () {
|
|
|
209
217
|
};
|
|
210
218
|
BaseGateway.prototype.transformOnSet = function (params) {
|
|
211
219
|
return __awaiter(this, void 0, void 0, function () {
|
|
212
|
-
var _a, hasCreatedAt, hasCreatedBy, hasSpace, hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField;
|
|
220
|
+
var _a, hasCreatedAt, hasCreatedBy, hasSpace, hasUpdatedAt, hasUpdatedBy, hasVersion, hasLang, localizationForField, hasUserId;
|
|
213
221
|
return __generator(this, function (_b) {
|
|
214
|
-
_a = this.config, hasCreatedAt = _a.hasCreatedAt, hasCreatedBy = _a.hasCreatedBy, hasSpace = _a.hasSpace, hasUpdatedAt = _a.hasUpdatedAt, hasUpdatedBy = _a.hasUpdatedBy, hasVersion = _a.hasVersion, hasLang = _a.hasLang, localizationForField = _a.localizationForField;
|
|
222
|
+
_a = this.config, hasCreatedAt = _a.hasCreatedAt, hasCreatedBy = _a.hasCreatedBy, hasSpace = _a.hasSpace, hasUpdatedAt = _a.hasUpdatedAt, hasUpdatedBy = _a.hasUpdatedBy, hasVersion = _a.hasVersion, hasLang = _a.hasLang, localizationForField = _a.localizationForField, hasUserId = _a.hasUserId;
|
|
215
223
|
if (hasCreatedAt) {
|
|
216
224
|
params[constants_1.FIELDS.CREATED_AT] = this.dateTime.dbFormat(this.dateTimeNow);
|
|
217
225
|
}
|
|
@@ -220,6 +228,11 @@ var BaseGateway = /** @class */ (function () {
|
|
|
220
228
|
params[constants_1.FIELDS.CREATED_BY] = this.getContext().userId;
|
|
221
229
|
}
|
|
222
230
|
}
|
|
231
|
+
if (hasUserId) {
|
|
232
|
+
if (params[constants_1.FIELDS.USER_ID] === undefined) {
|
|
233
|
+
params[constants_1.FIELDS.USER_ID] = this.getContext().userId;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
223
236
|
if (hasSpace) {
|
|
224
237
|
params[constants_1.FIELDS.SPACE_ID] = this.getContext().spaceId;
|
|
225
238
|
}
|
|
@@ -18,9 +18,11 @@ export interface BaseGatewayPropsInterface extends CacheInterface {
|
|
|
18
18
|
hasSpace?: boolean;
|
|
19
19
|
hasVersion?: boolean;
|
|
20
20
|
hasLang?: boolean;
|
|
21
|
+
hasUserId?: boolean;
|
|
21
22
|
localizationForField?: string;
|
|
22
23
|
defaultSorting?: SortItemInterface[];
|
|
23
24
|
fieldForKeyword?: string;
|
|
25
|
+
filterByUserField?: string;
|
|
24
26
|
insertChunkSize?: number;
|
|
25
27
|
hardRemove?: boolean;
|
|
26
28
|
loader?: LoaderInterface;
|
package/package.json
CHANGED