@sdflc/backend-helpers 1.0.47 → 1.0.50
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/BaseController.js +21 -62
- package/build/BaseCore.d.ts +2 -2
- package/build/BaseCore.js +425 -690
- package/build/BaseGateway.js +350 -554
- package/build/DataCache.js +47 -98
- package/build/Database.js +104 -177
- package/build/DbMigratorAndSeeder.js +131 -238
- package/build/apiContext.js +102 -191
- package/build/checkItHelpers.js +10 -10
- package/build/commonValidators.js +49 -91
- package/build/configBulder.js +8 -19
- package/build/constants.js +3 -3
- package/build/dbHelpers.js +72 -126
- package/build/dbSeeder.js +38 -90
- package/build/dbTableHelpers.js +25 -26
- package/build/interfaces/CoreActionInterface.d.ts +2 -1
- package/build/knexConfigBuilder.js +17 -28
- package/build/passwordHelpers.js +13 -59
- package/build/redisClient.d.ts +1 -0
- package/build/redisClient.js +50 -84
- package/build/resolversHelpers.js +17 -27
- package/build/userToken.js +24 -24
- package/build/utils.js +4 -5
- package/package.json +32 -34
package/build/BaseCore.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,42 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
9
|
});
|
|
21
10
|
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
12
|
exports.BaseCore = void 0;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
13
|
+
const api_helpers_1 = require("@sdflc/api-helpers");
|
|
14
|
+
const utils_1 = require("@sdflc/utils");
|
|
15
|
+
const userToken_1 = require("./userToken");
|
|
16
|
+
const defaultValidate = ( /*params: any, opt?: BaseCoreActionsInterface*/) => {
|
|
55
17
|
return [true, {}];
|
|
56
18
|
};
|
|
57
|
-
|
|
19
|
+
const defaultValidators = {
|
|
58
20
|
list: defaultValidate,
|
|
59
21
|
get: defaultValidate,
|
|
60
22
|
getMany: defaultValidate,
|
|
@@ -66,29 +28,29 @@ var defaultValidators = {
|
|
|
66
28
|
remove: defaultValidate,
|
|
67
29
|
removeMany: defaultValidate,
|
|
68
30
|
};
|
|
69
|
-
|
|
70
|
-
|
|
31
|
+
class BaseCore {
|
|
32
|
+
constructor(props) {
|
|
71
33
|
this.config = props;
|
|
72
34
|
this.logger = props.logger;
|
|
73
35
|
}
|
|
74
|
-
|
|
36
|
+
getDb() {
|
|
75
37
|
return this.config.db;
|
|
76
|
-
}
|
|
77
|
-
|
|
38
|
+
}
|
|
39
|
+
getRequestId() {
|
|
78
40
|
return this.config.context.requestId;
|
|
79
|
-
}
|
|
80
|
-
|
|
41
|
+
}
|
|
42
|
+
getContext() {
|
|
81
43
|
return this.config.context;
|
|
82
|
-
}
|
|
83
|
-
|
|
44
|
+
}
|
|
45
|
+
getGateways() {
|
|
84
46
|
return this.config.context.gateways || {};
|
|
85
|
-
}
|
|
86
|
-
|
|
47
|
+
}
|
|
48
|
+
getValidators() {
|
|
87
49
|
return defaultValidators;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
50
|
+
}
|
|
51
|
+
success(data, code) {
|
|
52
|
+
const code2use = code != null ? code : api_helpers_1.OP_RESULT_CODES.OK;
|
|
53
|
+
let data2use = data;
|
|
92
54
|
if (!Array.isArray(data2use)) {
|
|
93
55
|
if (data) {
|
|
94
56
|
data2use = [data];
|
|
@@ -102,25 +64,25 @@ var BaseCore = /** @class */ (function () {
|
|
|
102
64
|
data: data2use,
|
|
103
65
|
errors: [],
|
|
104
66
|
}).toJS();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
67
|
+
}
|
|
68
|
+
failure(code, errorMsg, data) {
|
|
69
|
+
const result = new api_helpers_1.OpResult({ data });
|
|
108
70
|
result.addError('', errorMsg, code);
|
|
109
71
|
return result.toJS();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Object.keys(ex.errors).forEach(
|
|
72
|
+
}
|
|
73
|
+
validationFailure(ex) {
|
|
74
|
+
const result = new api_helpers_1.OpResult({ code: api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED });
|
|
75
|
+
Object.keys(ex.errors).forEach((key) => {
|
|
114
76
|
result.addError(key, ex.errors[key].message);
|
|
115
77
|
});
|
|
116
78
|
return result.toJS();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
79
|
+
}
|
|
80
|
+
exceptionFailure(ex, doingWhat, data) {
|
|
81
|
+
const [isDbError, dbErrorMsg] = this.getDb().isDbError(ex);
|
|
82
|
+
const isOpResult = typeof ex.getErrorSummary === 'function';
|
|
83
|
+
const message = isOpResult ? ex.getErrorSummary() : ex.message;
|
|
84
|
+
const sysMsg = `An exception has occurred on ${doingWhat} with message ${message}:`;
|
|
85
|
+
let msg = '';
|
|
124
86
|
if (isDbError) {
|
|
125
87
|
msg = dbErrorMsg;
|
|
126
88
|
}
|
|
@@ -129,697 +91,470 @@ var BaseCore = /** @class */ (function () {
|
|
|
129
91
|
msg = doingWhat['message'];
|
|
130
92
|
}
|
|
131
93
|
else {
|
|
132
|
-
msg = isOpResult ? ex.getErrorSummary() :
|
|
94
|
+
msg = isOpResult ? ex.getErrorSummary() : `Sorry, something went wrong on ${doingWhat}`;
|
|
133
95
|
}
|
|
134
96
|
this.logger.error(sysMsg, ex);
|
|
135
97
|
}
|
|
136
|
-
|
|
98
|
+
const result = new api_helpers_1.OpResult({ data });
|
|
137
99
|
result.addError('', msg, api_helpers_1.OP_RESULT_CODES.EXCEPTION);
|
|
138
100
|
return result.toJS();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
if (!(hasTransaction && result)) return [3 /*break*/, 4];
|
|
151
|
-
if (!(result.code >= api_helpers_1.OP_RESULT_CODES.OK)) return [3 /*break*/, 2];
|
|
152
|
-
return [4 /*yield*/, this.getDb().commitTransaction()];
|
|
153
|
-
case 1:
|
|
154
|
-
_a.sent();
|
|
155
|
-
return [3 /*break*/, 4];
|
|
156
|
-
case 2: return [4 /*yield*/, this.getDb().rollbackTransaction()];
|
|
157
|
-
case 3:
|
|
158
|
-
_a.sent();
|
|
159
|
-
_a.label = 4;
|
|
160
|
-
case 4: return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
checkResult(args) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const { hasTransaction, result, sameRequest } = args;
|
|
105
|
+
if (sameRequest) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (hasTransaction && result) {
|
|
109
|
+
if (result.code >= api_helpers_1.OP_RESULT_CODES.OK) {
|
|
110
|
+
yield this.getDb().commitTransaction();
|
|
161
111
|
}
|
|
162
|
-
|
|
112
|
+
else {
|
|
113
|
+
yield this.getDb().rollbackTransaction();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
163
116
|
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return [4 /*yield*/, this.getDb().startTransaction()];
|
|
189
|
-
case 2:
|
|
190
|
-
_d.sent();
|
|
191
|
-
_d.label = 3;
|
|
192
|
-
case 3:
|
|
193
|
-
if (!(doAuth === true || (doAuth == null && this.config.doAuth))) return [3 /*break*/, 5];
|
|
194
|
-
return [4 /*yield*/, this.authenticate(opt, actionOpt)];
|
|
195
|
-
case 4:
|
|
196
|
-
_b = _d.sent(), authResult = _b[0], errMsg = _b[1];
|
|
117
|
+
}
|
|
118
|
+
runAction(opt) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const { args, validate, doAuth, action, hasTransaction, doingWhat } = opt || {};
|
|
121
|
+
// If we process action with the same requestId as requestId passed to the constructor it means
|
|
122
|
+
// we are processing the same request from FE and can skip some of the operations like transactions and etc
|
|
123
|
+
const sameRequest = !!this.config.context.requestId && (args === null || args === void 0 ? void 0 : args.requestId) === this.config.context.requestId;
|
|
124
|
+
let step = doingWhat || '';
|
|
125
|
+
const setStep = (stepName) => {
|
|
126
|
+
step = stepName;
|
|
127
|
+
};
|
|
128
|
+
const actionOpt = {
|
|
129
|
+
core: this,
|
|
130
|
+
setStep,
|
|
131
|
+
sameRequest,
|
|
132
|
+
hasTransaction,
|
|
133
|
+
};
|
|
134
|
+
try {
|
|
135
|
+
if (!sameRequest) {
|
|
136
|
+
if (hasTransaction) {
|
|
137
|
+
yield this.getDb().startTransaction();
|
|
138
|
+
}
|
|
139
|
+
if (doAuth === true || (doAuth == null && this.config.doAuth)) {
|
|
140
|
+
const [authResult, errMsg] = yield this.authenticate(opt, actionOpt);
|
|
197
141
|
if (!authResult) {
|
|
198
|
-
return
|
|
142
|
+
return new api_helpers_1.OpResult({ code: api_helpers_1.OP_RESULT_CODES.UNAUTHORIZED }).addError('', errMsg);
|
|
199
143
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
_c = _d.sent(), spaceResult = _c[0], errMsg = _c[1];
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
const [spaceResult, errMsg] = yield this.findSpace();
|
|
204
147
|
if (spaceResult !== true) {
|
|
205
|
-
return
|
|
206
|
-
}
|
|
207
|
-
_d.label = 7;
|
|
208
|
-
case 7:
|
|
209
|
-
validatedItems = {};
|
|
210
|
-
if (!(typeof validate === 'function')) return [3 /*break*/, 10];
|
|
211
|
-
return [4 /*yield*/, validate(args, actionOpt)];
|
|
212
|
-
case 8:
|
|
213
|
-
valideResult = _d.sent();
|
|
214
|
-
result_1 = valideResult;
|
|
215
|
-
if (Array.isArray(valideResult)) {
|
|
216
|
-
result_1 = valideResult[0];
|
|
217
|
-
validatedItems = valideResult[1] || {};
|
|
148
|
+
return new api_helpers_1.OpResult({ code: api_helpers_1.OP_RESULT_CODES.UNAUTHORIZED }).addError('', errMsg);
|
|
218
149
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
let validatedItems = {};
|
|
153
|
+
if (typeof validate === 'function') {
|
|
154
|
+
// If we have validator provided, use it to validate data before running action
|
|
155
|
+
// validator is expected to return an array:
|
|
156
|
+
// [0] - true or validation error object,
|
|
157
|
+
// [1] - an object with some fetched data to pass ot the action handler
|
|
158
|
+
const valideResult = yield validate(args, actionOpt);
|
|
159
|
+
let result = valideResult;
|
|
160
|
+
if (Array.isArray(valideResult)) {
|
|
161
|
+
result = valideResult[0];
|
|
162
|
+
validatedItems = valideResult[1] || {};
|
|
163
|
+
}
|
|
164
|
+
// If validator returned null then consider the validation passed
|
|
165
|
+
result = result != null ? result : true;
|
|
166
|
+
if (result !== true) {
|
|
225
167
|
// if there was an error then `result` is expected to be an object with the same structure as the checkit library does
|
|
226
|
-
|
|
227
|
-
return
|
|
228
|
-
|
|
229
|
-
case 11:
|
|
230
|
-
result = _d.sent();
|
|
231
|
-
return [4 /*yield*/, this.checkResult({ hasTransaction: hasTransaction, result: result, sameRequest: sameRequest })];
|
|
232
|
-
case 12:
|
|
233
|
-
_d.sent();
|
|
234
|
-
return [2 /*return*/, result];
|
|
235
|
-
case 13:
|
|
236
|
-
ex_1 = _d.sent();
|
|
237
|
-
if (!(!sameRequest && hasTransaction)) return [3 /*break*/, 15];
|
|
238
|
-
return [4 /*yield*/, this.getDb().rollbackTransaction()];
|
|
239
|
-
case 14:
|
|
240
|
-
_d.sent();
|
|
241
|
-
_d.label = 15;
|
|
242
|
-
case 15: return [4 /*yield*/, this.onException(args, __assign(__assign({}, actionOpt), { doingWhat: doingWhat, exception: ex_1 }))];
|
|
243
|
-
case 16:
|
|
244
|
-
_d.sent();
|
|
245
|
-
what = doingWhat;
|
|
246
|
-
if (doingWhat !== step) {
|
|
247
|
-
what = {
|
|
248
|
-
message: "".concat(step, " failed on ").concat(doingWhat),
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
return [2 /*return*/, this.exceptionFailure(ex_1, what)];
|
|
252
|
-
case 17: return [2 /*return*/];
|
|
168
|
+
yield this.checkResult({ hasTransaction, result, sameRequest });
|
|
169
|
+
return result.code != null ? result : new api_helpers_1.OpResult({ code: api_helpers_1.OP_RESULT_CODES.VALIDATION_FAILED });
|
|
170
|
+
}
|
|
253
171
|
}
|
|
254
|
-
|
|
172
|
+
const result = yield action(args, Object.assign(Object.assign({}, actionOpt), { validatedItems }));
|
|
173
|
+
yield this.checkResult({ hasTransaction, result, sameRequest });
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
catch (ex) {
|
|
177
|
+
if (!sameRequest && hasTransaction) {
|
|
178
|
+
yield this.getDb().rollbackTransaction();
|
|
179
|
+
}
|
|
180
|
+
yield this.onException(args, Object.assign(Object.assign({}, actionOpt), { doingWhat, exception: ex }));
|
|
181
|
+
let what = doingWhat;
|
|
182
|
+
if (doingWhat !== step) {
|
|
183
|
+
what = {
|
|
184
|
+
message: `${step} failed on ${doingWhat}`,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return this.exceptionFailure(ex, what);
|
|
188
|
+
}
|
|
255
189
|
});
|
|
256
|
-
}
|
|
257
|
-
|
|
190
|
+
}
|
|
191
|
+
list(args) {
|
|
258
192
|
var _a, _b, _c;
|
|
259
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
object = _b.sent();
|
|
276
|
-
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.list(object))];
|
|
277
|
-
case 2:
|
|
278
|
-
items = _b.sent();
|
|
279
|
-
return [4 /*yield*/, this.afterList(items, opt)];
|
|
280
|
-
case 3:
|
|
281
|
-
result = _b.sent();
|
|
282
|
-
// ON NO DATA RETURN EMPTY CODE
|
|
283
|
-
return [2 /*return*/, this.success(result /*, result.length > 0 OP_RESULT_CODES.OK : OP_RESULT_CODES.*/)];
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
}); },
|
|
287
|
-
hasTransaction: false,
|
|
288
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'listing',
|
|
289
|
-
})];
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
return this.runAction({
|
|
195
|
+
args,
|
|
196
|
+
validate: this.getValidators().list,
|
|
197
|
+
accessRights: [utils_1.ACCESS_RIGHTS.LIST],
|
|
198
|
+
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
var _d;
|
|
200
|
+
this.logger.log(`Requesting a list for ${this.config.name}:`, args);
|
|
201
|
+
const object = yield this.beforeList(args, opt);
|
|
202
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.list(object));
|
|
203
|
+
const result = yield this.afterList(items, opt);
|
|
204
|
+
// ON NO DATA RETURN EMPTY CODE
|
|
205
|
+
return this.success(result /*, result.length > 0 OP_RESULT_CODES.OK : OP_RESULT_CODES.*/);
|
|
206
|
+
}),
|
|
207
|
+
hasTransaction: false,
|
|
208
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.list) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'listing',
|
|
290
209
|
});
|
|
291
210
|
});
|
|
292
|
-
}
|
|
293
|
-
|
|
211
|
+
}
|
|
212
|
+
get(args) {
|
|
294
213
|
var _a, _b, _c;
|
|
295
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
this.logger.log("Requesting an item for ".concat(this.config.name, ":"), args);
|
|
310
|
-
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.get(id))];
|
|
311
|
-
case 1:
|
|
312
|
-
item = _b.sent();
|
|
313
|
-
return [2 /*return*/, this.success([item], item ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
}); },
|
|
317
|
-
hasTransaction: false,
|
|
318
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.get) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'getting an item',
|
|
319
|
-
})];
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
return this.runAction({
|
|
216
|
+
args,
|
|
217
|
+
validate: this.getValidators().get,
|
|
218
|
+
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
219
|
+
action: (args) => __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
var _d;
|
|
221
|
+
const { id } = args || {};
|
|
222
|
+
this.logger.log(`Requesting an item for ${this.config.name}:`, args);
|
|
223
|
+
const item = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.get(id));
|
|
224
|
+
return this.success([item], item ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
|
|
225
|
+
}),
|
|
226
|
+
hasTransaction: false,
|
|
227
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.get) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'getting an item',
|
|
320
228
|
});
|
|
321
229
|
});
|
|
322
|
-
}
|
|
323
|
-
|
|
230
|
+
}
|
|
231
|
+
getMany(args) {
|
|
324
232
|
var _a, _b, _c;
|
|
325
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
this.logger.log("Requesting multiple items for ".concat(this.config.name, ":"), args);
|
|
340
|
-
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.getMany(ids))];
|
|
341
|
-
case 1:
|
|
342
|
-
items = _b.sent();
|
|
343
|
-
return [2 /*return*/, this.success(items, items.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
}); },
|
|
347
|
-
hasTransaction: false,
|
|
348
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.getMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'geting multiple items',
|
|
349
|
-
})];
|
|
233
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
234
|
+
return this.runAction({
|
|
235
|
+
args,
|
|
236
|
+
validate: this.getValidators().getMany,
|
|
237
|
+
accessRights: [utils_1.ACCESS_RIGHTS.GET],
|
|
238
|
+
action: (args) => __awaiter(this, void 0, void 0, function* () {
|
|
239
|
+
var _d;
|
|
240
|
+
const { ids } = args || {};
|
|
241
|
+
this.logger.log(`Requesting multiple items for ${this.config.name}:`, args);
|
|
242
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.getMany(ids));
|
|
243
|
+
return this.success(items, items.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
|
|
244
|
+
}),
|
|
245
|
+
hasTransaction: false,
|
|
246
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.getMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'geting multiple items',
|
|
350
247
|
});
|
|
351
248
|
});
|
|
352
|
-
}
|
|
353
|
-
|
|
249
|
+
}
|
|
250
|
+
create(args) {
|
|
354
251
|
var _a, _b, _c;
|
|
355
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
case 1:
|
|
372
|
-
object = _b.sent();
|
|
373
|
-
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.create(object))];
|
|
374
|
-
case 2:
|
|
375
|
-
item = _b.sent();
|
|
376
|
-
return [4 /*yield*/, this.afterCreate(item, opt)];
|
|
377
|
-
case 3:
|
|
378
|
-
result = _b.sent();
|
|
379
|
-
return [2 /*return*/, this.success(result)];
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
}); },
|
|
383
|
-
hasTransaction: true,
|
|
384
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.create) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'creating an item',
|
|
385
|
-
})];
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
return this.runAction({
|
|
254
|
+
args,
|
|
255
|
+
validate: this.getValidators().create,
|
|
256
|
+
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
257
|
+
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
258
|
+
var _d;
|
|
259
|
+
const { params } = args || {};
|
|
260
|
+
this.logger.log(`Requesting creation of an item for ${this.config.name}:`, args);
|
|
261
|
+
const object = yield this.beforeCreate(params, opt);
|
|
262
|
+
const item = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.create(object));
|
|
263
|
+
const result = yield this.afterCreate(item, opt);
|
|
264
|
+
return this.success(result);
|
|
265
|
+
}),
|
|
266
|
+
hasTransaction: true,
|
|
267
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.create) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'creating an item',
|
|
386
268
|
});
|
|
387
269
|
});
|
|
388
|
-
}
|
|
389
|
-
|
|
270
|
+
}
|
|
271
|
+
createMany(args) {
|
|
390
272
|
var _a, _b, _c;
|
|
391
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
case 1:
|
|
408
|
-
objects = _b.sent();
|
|
409
|
-
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.create(objects))];
|
|
410
|
-
case 2:
|
|
411
|
-
items = _b.sent();
|
|
412
|
-
return [4 /*yield*/, this.afterCreateMany(items, opt)];
|
|
413
|
-
case 3:
|
|
414
|
-
result = _b.sent();
|
|
415
|
-
return [2 /*return*/, this.success(result)];
|
|
416
|
-
}
|
|
417
|
-
});
|
|
418
|
-
}); },
|
|
419
|
-
hasTransaction: true,
|
|
420
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.createMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'creating multiple items',
|
|
421
|
-
})];
|
|
273
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
274
|
+
return this.runAction({
|
|
275
|
+
args,
|
|
276
|
+
validate: this.getValidators().createMany,
|
|
277
|
+
accessRights: [utils_1.ACCESS_RIGHTS.CREATE],
|
|
278
|
+
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
var _d;
|
|
280
|
+
const { params } = args || {};
|
|
281
|
+
this.logger.log(`Requesting creation of multiple items for ${this.config.name}:`, args);
|
|
282
|
+
const objects = yield this.beforeCreateMany(params, opt);
|
|
283
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.create(objects));
|
|
284
|
+
const result = yield this.afterCreateMany(items, opt);
|
|
285
|
+
return this.success(result);
|
|
286
|
+
}),
|
|
287
|
+
hasTransaction: true,
|
|
288
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.createMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'creating multiple items',
|
|
422
289
|
});
|
|
423
290
|
});
|
|
424
|
-
}
|
|
425
|
-
|
|
291
|
+
}
|
|
292
|
+
update(args) {
|
|
426
293
|
var _a, _b, _c;
|
|
427
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
case 1:
|
|
444
|
-
object = _c.sent();
|
|
445
|
-
return [4 /*yield*/, ((_b = this.getContext().gateways[this.config.gatewayName]) === null || _b === void 0 ? void 0 : _b.update(where, object))];
|
|
446
|
-
case 2:
|
|
447
|
-
item = _c.sent();
|
|
448
|
-
return [4 /*yield*/, this.afterUpdate(item, opt)];
|
|
449
|
-
case 3:
|
|
450
|
-
result = _c.sent();
|
|
451
|
-
return [2 /*return*/, this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
}); },
|
|
455
|
-
hasTransaction: true,
|
|
456
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.update) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'updating an item',
|
|
457
|
-
})];
|
|
294
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
return this.runAction({
|
|
296
|
+
args,
|
|
297
|
+
validate: this.getValidators().update,
|
|
298
|
+
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
299
|
+
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
var _d;
|
|
301
|
+
const { where, params } = args || {};
|
|
302
|
+
this.logger.log(`Requesting update of an item for ${this.config.name}:`, args);
|
|
303
|
+
const object = yield this.beforeUpdate(params, opt);
|
|
304
|
+
const item = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.update(where, object));
|
|
305
|
+
const result = yield this.afterUpdate(item, opt);
|
|
306
|
+
return this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
|
|
307
|
+
}),
|
|
308
|
+
hasTransaction: true,
|
|
309
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.update) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'updating an item',
|
|
458
310
|
});
|
|
459
311
|
});
|
|
460
|
-
}
|
|
461
|
-
|
|
312
|
+
}
|
|
313
|
+
updateMany(args) {
|
|
462
314
|
var _a, _b, _c;
|
|
463
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
case 1:
|
|
480
|
-
object = _b.sent();
|
|
481
|
-
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.updateMany(object))];
|
|
482
|
-
case 2:
|
|
483
|
-
items = _b.sent();
|
|
484
|
-
return [4 /*yield*/, this.afterUpdateMany(items, opt)];
|
|
485
|
-
case 3:
|
|
486
|
-
result = _b.sent();
|
|
487
|
-
return [2 /*return*/, this.success(result)];
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
}); },
|
|
491
|
-
hasTransaction: true,
|
|
492
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.updateMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'updating multiple items',
|
|
493
|
-
})];
|
|
315
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
316
|
+
return this.runAction({
|
|
317
|
+
args,
|
|
318
|
+
validate: this.getValidators().updateMany,
|
|
319
|
+
accessRights: [utils_1.ACCESS_RIGHTS.UPDATE],
|
|
320
|
+
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
321
|
+
var _d;
|
|
322
|
+
const { params } = args || {};
|
|
323
|
+
this.logger.log(`Requesting update of an item for ${this.config.name}:`, args);
|
|
324
|
+
const object = yield this.beforeUpdateMany(params, opt);
|
|
325
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.updateMany(object));
|
|
326
|
+
const result = yield this.afterUpdateMany(items, opt);
|
|
327
|
+
return this.success(result);
|
|
328
|
+
}),
|
|
329
|
+
hasTransaction: true,
|
|
330
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.updateMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'updating multiple items',
|
|
494
331
|
});
|
|
495
332
|
});
|
|
496
|
-
}
|
|
497
|
-
|
|
333
|
+
}
|
|
334
|
+
set(args) {
|
|
498
335
|
var _a, _b, _c;
|
|
499
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
case 1:
|
|
516
|
-
object = _b.sent();
|
|
517
|
-
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.set(object))];
|
|
518
|
-
case 2:
|
|
519
|
-
items = _b.sent();
|
|
520
|
-
return [4 /*yield*/, this.afterSet(items, opt)];
|
|
521
|
-
case 3:
|
|
522
|
-
result = _b.sent();
|
|
523
|
-
return [2 /*return*/, this.success(result)];
|
|
524
|
-
}
|
|
525
|
-
});
|
|
526
|
-
}); },
|
|
527
|
-
hasTransaction: true,
|
|
528
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.updateMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'updating multiple items',
|
|
529
|
-
})];
|
|
336
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
+
return this.runAction({
|
|
338
|
+
args,
|
|
339
|
+
validate: this.getValidators().set,
|
|
340
|
+
accessRights: [utils_1.ACCESS_RIGHTS.CREATE, utils_1.ACCESS_RIGHTS.UPDATE],
|
|
341
|
+
action: (args, opt /* { setStep, validatedItems, sameRequest } */) => __awaiter(this, void 0, void 0, function* () {
|
|
342
|
+
var _d;
|
|
343
|
+
const { params } = args || {};
|
|
344
|
+
this.logger.log(`Requesting setting of item(s) for ${this.config.name}:`, args);
|
|
345
|
+
const object = yield this.beforeSet(params, opt);
|
|
346
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.set(object));
|
|
347
|
+
const result = yield this.afterSet(items, opt);
|
|
348
|
+
return this.success(result);
|
|
349
|
+
}),
|
|
350
|
+
hasTransaction: true,
|
|
351
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.updateMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'updating multiple items',
|
|
530
352
|
});
|
|
531
353
|
});
|
|
532
|
-
}
|
|
533
|
-
|
|
354
|
+
}
|
|
355
|
+
remove(args) {
|
|
534
356
|
var _a, _b, _c;
|
|
535
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
case 1:
|
|
552
|
-
object = _b.sent();
|
|
553
|
-
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.remove(object))];
|
|
554
|
-
case 2:
|
|
555
|
-
items = _b.sent();
|
|
556
|
-
return [4 /*yield*/, this.afterRemove(items, opt)];
|
|
557
|
-
case 3:
|
|
558
|
-
result = _b.sent();
|
|
559
|
-
return [2 /*return*/, this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
|
|
560
|
-
}
|
|
561
|
-
});
|
|
562
|
-
}); },
|
|
563
|
-
hasTransaction: false,
|
|
564
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.remove) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'removing an item',
|
|
565
|
-
})];
|
|
357
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
358
|
+
return this.runAction({
|
|
359
|
+
args,
|
|
360
|
+
validate: this.getValidators().remove,
|
|
361
|
+
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
362
|
+
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
363
|
+
var _d;
|
|
364
|
+
const { where } = args || {};
|
|
365
|
+
this.logger.log(`Requesting removal of an item for ${this.config.name}:`, args);
|
|
366
|
+
const object = yield this.beforeRemove(where, opt);
|
|
367
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.remove(object));
|
|
368
|
+
const result = yield this.afterRemove(items, opt);
|
|
369
|
+
return this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
|
|
370
|
+
}),
|
|
371
|
+
hasTransaction: false,
|
|
372
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.remove) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'removing an item',
|
|
566
373
|
});
|
|
567
374
|
});
|
|
568
|
-
}
|
|
569
|
-
|
|
375
|
+
}
|
|
376
|
+
removeMany(args) {
|
|
570
377
|
var _a, _b, _c;
|
|
571
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
case 1:
|
|
588
|
-
object = _b.sent();
|
|
589
|
-
return [4 /*yield*/, ((_a = this.getContext().gateways[this.config.gatewayName]) === null || _a === void 0 ? void 0 : _a.remove(object))];
|
|
590
|
-
case 2:
|
|
591
|
-
items = _b.sent();
|
|
592
|
-
return [4 /*yield*/, this.afterRemoveMany(items, opt)];
|
|
593
|
-
case 3:
|
|
594
|
-
result = _b.sent();
|
|
595
|
-
return [2 /*return*/, this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND)];
|
|
596
|
-
}
|
|
597
|
-
});
|
|
598
|
-
}); },
|
|
599
|
-
hasTransaction: false,
|
|
600
|
-
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.removeMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'removing multiple items',
|
|
601
|
-
})];
|
|
378
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
379
|
+
return this.runAction({
|
|
380
|
+
args,
|
|
381
|
+
validate: this.getValidators().removeMany,
|
|
382
|
+
accessRights: [utils_1.ACCESS_RIGHTS.REMOVE],
|
|
383
|
+
action: (args, opt) => __awaiter(this, void 0, void 0, function* () {
|
|
384
|
+
var _d;
|
|
385
|
+
const { where } = args || {};
|
|
386
|
+
this.logger.log(`Requesting removal of multiple items for ${this.config.name}:`, args);
|
|
387
|
+
const object = yield this.beforeRemoveMany(where, opt);
|
|
388
|
+
const items = yield ((_d = this.getContext().gateways[this.config.gatewayName]) === null || _d === void 0 ? void 0 : _d.remove(object));
|
|
389
|
+
const result = yield this.afterRemoveMany(items, opt);
|
|
390
|
+
return this.success(result, result.length > 0 ? api_helpers_1.OP_RESULT_CODES.OK : api_helpers_1.OP_RESULT_CODES.NOT_FOUND);
|
|
391
|
+
}),
|
|
392
|
+
hasTransaction: false,
|
|
393
|
+
doingWhat: (_c = (_b = (_a = this.config.doingWhat) === null || _a === void 0 ? void 0 : _a.removeMany) !== null && _b !== void 0 ? _b : this.config.name) !== null && _c !== void 0 ? _c : 'removing multiple items',
|
|
602
394
|
});
|
|
603
395
|
});
|
|
604
|
-
}
|
|
396
|
+
}
|
|
605
397
|
// eslint-disable-next-line
|
|
606
|
-
|
|
607
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
608
|
-
return
|
|
609
|
-
return [2 /*return*/, params];
|
|
610
|
-
});
|
|
398
|
+
defaultAfterAndBefore(params, opt) {
|
|
399
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
return params;
|
|
611
401
|
});
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
615
|
-
return
|
|
616
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
617
|
-
});
|
|
402
|
+
}
|
|
403
|
+
beforeList(params, opt) {
|
|
404
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
405
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
618
406
|
});
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
622
|
-
return
|
|
623
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
624
|
-
});
|
|
407
|
+
}
|
|
408
|
+
afterList(params, opt) {
|
|
409
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
410
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
625
411
|
});
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
629
|
-
return
|
|
630
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
631
|
-
});
|
|
412
|
+
}
|
|
413
|
+
beforeCreate(params, opt) {
|
|
414
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
415
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
632
416
|
});
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
636
|
-
return
|
|
637
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
638
|
-
});
|
|
417
|
+
}
|
|
418
|
+
afterCreate(params, opt) {
|
|
419
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
639
421
|
});
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
643
|
-
return
|
|
644
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
645
|
-
});
|
|
422
|
+
}
|
|
423
|
+
beforeCreateMany(params, opt) {
|
|
424
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
425
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
646
426
|
});
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
650
|
-
return
|
|
651
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
652
|
-
});
|
|
427
|
+
}
|
|
428
|
+
afterCreateMany(params, opt) {
|
|
429
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
653
431
|
});
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
657
|
-
return
|
|
658
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
659
|
-
});
|
|
432
|
+
}
|
|
433
|
+
beforeUpdate(params, opt) {
|
|
434
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
435
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
660
436
|
});
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
664
|
-
return
|
|
665
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
666
|
-
});
|
|
437
|
+
}
|
|
438
|
+
afterUpdate(params, opt) {
|
|
439
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
440
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
667
441
|
});
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
671
|
-
return
|
|
672
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
673
|
-
});
|
|
442
|
+
}
|
|
443
|
+
beforeUpdateMany(params, opt) {
|
|
444
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
445
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
674
446
|
});
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
678
|
-
return
|
|
679
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
680
|
-
});
|
|
447
|
+
}
|
|
448
|
+
afterUpdateMany(params, opt) {
|
|
449
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
450
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
681
451
|
});
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
685
|
-
return
|
|
686
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
687
|
-
});
|
|
452
|
+
}
|
|
453
|
+
beforeSet(params, opt) {
|
|
454
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
455
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
688
456
|
});
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
692
|
-
return
|
|
693
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
694
|
-
});
|
|
457
|
+
}
|
|
458
|
+
afterSet(params, opt) {
|
|
459
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
460
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
695
461
|
});
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
699
|
-
return
|
|
700
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
701
|
-
});
|
|
462
|
+
}
|
|
463
|
+
beforeRemove(params, opt) {
|
|
464
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
465
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
702
466
|
});
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
706
|
-
return
|
|
707
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
708
|
-
});
|
|
467
|
+
}
|
|
468
|
+
afterRemove(params, opt) {
|
|
469
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
470
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
709
471
|
});
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
713
|
-
return
|
|
714
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
715
|
-
});
|
|
472
|
+
}
|
|
473
|
+
beforeRemoveMany(params, opt) {
|
|
474
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
475
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
716
476
|
});
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
720
|
-
return
|
|
721
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
722
|
-
});
|
|
477
|
+
}
|
|
478
|
+
afterRemoveMany(params, opt) {
|
|
479
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
480
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
723
481
|
});
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
727
|
-
return
|
|
728
|
-
return [2 /*return*/, this.defaultAfterAndBefore(params, opt)];
|
|
729
|
-
});
|
|
482
|
+
}
|
|
483
|
+
onException(params, opt) {
|
|
484
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
485
|
+
return this.defaultAfterAndBefore(params, opt);
|
|
730
486
|
});
|
|
731
|
-
}
|
|
487
|
+
}
|
|
732
488
|
/**
|
|
733
489
|
* Returns JWT secret and its settings to verify received JWT token
|
|
734
490
|
* @param params Object of parameters passed to the authenticate method
|
|
735
491
|
* @returns Object with the jwtSecret and verifyTokenArgs
|
|
736
492
|
*/
|
|
737
493
|
// eslint-disable-next-line
|
|
738
|
-
|
|
739
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
740
|
-
|
|
741
|
-
return
|
|
742
|
-
space
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
verifyTokenArgs: this.config.verifyTokenArgs,
|
|
746
|
-
}];
|
|
747
|
-
});
|
|
494
|
+
getJwtTokenSecretAndSettings(params) {
|
|
495
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
const { space } = this.getContext();
|
|
497
|
+
return {
|
|
498
|
+
jwtSecret: (space === null || space === void 0 ? void 0 : space.tokenSecret) || this.config.jwtSecret || '',
|
|
499
|
+
verifyTokenArgs: this.config.verifyTokenArgs,
|
|
500
|
+
};
|
|
748
501
|
});
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
space = null;
|
|
761
|
-
if (!context.spaceGw) return [3 /*break*/, 2];
|
|
762
|
-
if (!context.spaceId) {
|
|
763
|
-
return [2 /*return*/, [false, 'Space not specified']];
|
|
764
|
-
}
|
|
765
|
-
return [4 /*yield*/, context.spaceGw.get(context.spaceId || '')];
|
|
766
|
-
case 1:
|
|
767
|
-
// Lookup space in case we have gateway
|
|
768
|
-
space = _a.sent();
|
|
769
|
-
if (!space) {
|
|
770
|
-
return [2 /*return*/, [false, 'Space not found']];
|
|
771
|
-
}
|
|
772
|
-
context.space = space;
|
|
773
|
-
_a.label = 2;
|
|
774
|
-
case 2: return [2 /*return*/, [true, space]];
|
|
502
|
+
}
|
|
503
|
+
findSpace() {
|
|
504
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
505
|
+
const { context } = this.config;
|
|
506
|
+
if (context.space) {
|
|
507
|
+
return [true, context.space];
|
|
508
|
+
}
|
|
509
|
+
let space = null;
|
|
510
|
+
if (context.spaceGw) {
|
|
511
|
+
if (!context.spaceId) {
|
|
512
|
+
return [false, 'Space not specified'];
|
|
775
513
|
}
|
|
776
|
-
|
|
514
|
+
// Lookup space in case we have gateway
|
|
515
|
+
space = yield context.spaceGw.get(context.spaceId || '');
|
|
516
|
+
if (!space) {
|
|
517
|
+
return [false, 'Space not found'];
|
|
518
|
+
}
|
|
519
|
+
context.space = space;
|
|
520
|
+
}
|
|
521
|
+
return [true, space];
|
|
777
522
|
});
|
|
778
|
-
}
|
|
523
|
+
}
|
|
779
524
|
// eslint-disable-next-line
|
|
780
|
-
|
|
781
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
return [4 /*yield*/, this.getJwtTokenSecretAndSettings(params)];
|
|
795
|
-
case 2:
|
|
796
|
-
_b = _c.sent(), jwtSecret = _b.jwtSecret, verifyTokenArgs = _b.verifyTokenArgs;
|
|
797
|
-
if (context.authorization && jwtSecret) {
|
|
798
|
-
verifyResult = (0, userToken_1.verifyUserToken)(context.authorization, jwtSecret, verifyTokenArgs);
|
|
799
|
-
if (verifyResult.didFail()) {
|
|
800
|
-
return [2 /*return*/, [false, verifyResult.getErrorSummary('')]];
|
|
801
|
-
}
|
|
802
|
-
token = verifyResult.getDataFirst();
|
|
803
|
-
context.accountId = token.accountId;
|
|
804
|
-
context.roleId = token.roleId;
|
|
805
|
-
context.userId = token.userId;
|
|
806
|
-
context.spaceId = token.spaceId || context.spaceId;
|
|
807
|
-
context.lang = token.lang || context.requestedLang;
|
|
808
|
-
authByToken = true;
|
|
809
|
-
}
|
|
810
|
-
if (!authByToken) {
|
|
811
|
-
if (this.config.interserviceApiKey && context.apiKey === this.config.interserviceApiKey) {
|
|
812
|
-
return [2 /*return*/, [true, '']];
|
|
813
|
-
}
|
|
814
|
-
else if ((space === null || space === void 0 ? void 0 : space.apiKey) && (space === null || space === void 0 ? void 0 : space.apiKey) !== context.apiKey) {
|
|
815
|
-
return [2 /*return*/, [false, 'API Key is invalid']];
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
return [2 /*return*/, [true, '']];
|
|
525
|
+
authenticate(params, opt) {
|
|
526
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
527
|
+
//const { accessRights } = params || {};
|
|
528
|
+
const { context } = this.config;
|
|
529
|
+
let authByToken = false;
|
|
530
|
+
const [spaceResult, space] = yield this.findSpace();
|
|
531
|
+
if (spaceResult !== true) {
|
|
532
|
+
return spaceResult;
|
|
533
|
+
}
|
|
534
|
+
const { jwtSecret, verifyTokenArgs } = yield this.getJwtTokenSecretAndSettings(params);
|
|
535
|
+
if (context.authorization && jwtSecret) {
|
|
536
|
+
const verifyResult = (0, userToken_1.verifyUserToken)(context.authorization, jwtSecret, verifyTokenArgs);
|
|
537
|
+
if (verifyResult.didFail()) {
|
|
538
|
+
return [false, verifyResult.getErrorSummary('')];
|
|
819
539
|
}
|
|
820
|
-
|
|
540
|
+
const token = verifyResult.getDataFirst();
|
|
541
|
+
context.accountId = token.accountId;
|
|
542
|
+
context.roleId = token.roleId;
|
|
543
|
+
context.userId = token.userId;
|
|
544
|
+
context.spaceId = token.spaceId || context.spaceId;
|
|
545
|
+
context.lang = token.lang || context.requestedLang;
|
|
546
|
+
authByToken = true;
|
|
547
|
+
}
|
|
548
|
+
if (!authByToken) {
|
|
549
|
+
if (this.config.interserviceApiKey && context.apiKey === this.config.interserviceApiKey) {
|
|
550
|
+
return [true, ''];
|
|
551
|
+
}
|
|
552
|
+
else if ((space === null || space === void 0 ? void 0 : space.apiKey) && (space === null || space === void 0 ? void 0 : space.apiKey) !== context.apiKey) {
|
|
553
|
+
return [false, 'API Key is invalid'];
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return [true, ''];
|
|
821
557
|
});
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
}());
|
|
558
|
+
}
|
|
559
|
+
}
|
|
825
560
|
exports.BaseCore = BaseCore;
|