@sdflc/backend-helpers 1.0.12 → 1.0.13
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.d.ts +2 -0
- package/build/baseGateway.js +50 -2
- package/package.json +1 -1
package/build/baseGateway.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ declare class BaseGateway {
|
|
|
19
19
|
create(args: any): Promise<any>;
|
|
20
20
|
update(where: any, params: any): Promise<any>;
|
|
21
21
|
updateMany(params: any): Promise<any[]>;
|
|
22
|
+
increment(where: any, params: any): Promise<any>;
|
|
23
|
+
decrement(where: any, params: any): Promise<any>;
|
|
22
24
|
/**
|
|
23
25
|
* Inserts or updates data in the database.
|
|
24
26
|
* If the element of given array has not empty id field then the record is updated
|
package/build/baseGateway.js
CHANGED
|
@@ -65,7 +65,7 @@ var defaultUpdateFormatter = function (args) {
|
|
|
65
65
|
};
|
|
66
66
|
var defaultUpdateRemoveFilter = function (config) { return function (query, params) {
|
|
67
67
|
var idName = config.idField || ID_FIELD;
|
|
68
|
-
|
|
68
|
+
query.where(idName, params[idName]);
|
|
69
69
|
}; };
|
|
70
70
|
var BaseGateway = /** @class */ (function () {
|
|
71
71
|
function BaseGateway(props) {
|
|
@@ -232,7 +232,7 @@ var BaseGateway = /** @class */ (function () {
|
|
|
232
232
|
return [4 /*yield*/, this.update(item.where, item.params)];
|
|
233
233
|
case 2:
|
|
234
234
|
items = _a.sent();
|
|
235
|
-
results.push(items);
|
|
235
|
+
results.push.apply(results, items);
|
|
236
236
|
_a.label = 3;
|
|
237
237
|
case 3:
|
|
238
238
|
++idx;
|
|
@@ -242,6 +242,54 @@ var BaseGateway = /** @class */ (function () {
|
|
|
242
242
|
});
|
|
243
243
|
});
|
|
244
244
|
};
|
|
245
|
+
BaseGateway.prototype.increment = function (where, params) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
247
|
+
var object, query, items;
|
|
248
|
+
var _this = this;
|
|
249
|
+
return __generator(this, function (_a) {
|
|
250
|
+
switch (_a.label) {
|
|
251
|
+
case 0: return [4 /*yield*/, this.updateFormatter(params)];
|
|
252
|
+
case 1:
|
|
253
|
+
object = _a.sent();
|
|
254
|
+
query = this.getBuilder().increment(object).returning(this.returnFields);
|
|
255
|
+
return [4 /*yield*/, this.updateFilter(query, where)];
|
|
256
|
+
case 2:
|
|
257
|
+
_a.sent();
|
|
258
|
+
return [4 /*yield*/, query];
|
|
259
|
+
case 3:
|
|
260
|
+
items = _a.sent();
|
|
261
|
+
if (items.length > 0 && this.config.noCache !== true) {
|
|
262
|
+
items.forEach(function (item) { return _this.loader.clear(item[_this.getIdField()]); });
|
|
263
|
+
}
|
|
264
|
+
return [2 /*return*/, items];
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
BaseGateway.prototype.decrement = function (where, params) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
271
|
+
var object, query, items;
|
|
272
|
+
var _this = this;
|
|
273
|
+
return __generator(this, function (_a) {
|
|
274
|
+
switch (_a.label) {
|
|
275
|
+
case 0: return [4 /*yield*/, this.updateFormatter(params)];
|
|
276
|
+
case 1:
|
|
277
|
+
object = _a.sent();
|
|
278
|
+
query = this.getBuilder().decrement(object).returning(this.returnFields);
|
|
279
|
+
return [4 /*yield*/, this.updateFilter(query, where)];
|
|
280
|
+
case 2:
|
|
281
|
+
_a.sent();
|
|
282
|
+
return [4 /*yield*/, query];
|
|
283
|
+
case 3:
|
|
284
|
+
items = _a.sent();
|
|
285
|
+
if (items.length > 0 && this.config.noCache !== true) {
|
|
286
|
+
items.forEach(function (item) { return _this.loader.clear(item[_this.getIdField()]); });
|
|
287
|
+
}
|
|
288
|
+
return [2 /*return*/, items];
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
};
|
|
245
293
|
/**
|
|
246
294
|
* Inserts or updates data in the database.
|
|
247
295
|
* If the element of given array has not empty id field then the record is updated
|
package/package.json
CHANGED