@futdevpro/nts-dynamo 1.5.51 → 1.5.53
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/lib/_models/dynamo-nts-endpoint-params.js +3 -2
- package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.d.ts +87 -7
- package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.js +87 -7
- package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
- package/lib/_services/dynamo-nts-app.d.ts +131 -22
- package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app.js +104 -1
- package/lib/_services/dynamo-nts-app.js.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.d.ts +78 -5
- package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
- package/lib/_services/dynamo-nts-data.service.d.ts +28 -1
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +109 -75
- package/lib/_services/dynamo-nts-data.service.js.map +1 -1
- package/lib/_services/dynamo-nts-db.service.d.ts +165 -115
- package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-db.service.js +301 -277
- package/lib/_services/dynamo-nts-db.service.js.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.d.ts +39 -0
- package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.js +39 -0
- package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -12
- package/src/_models/dynamo-nts-endpoint-params.ts +2 -2
- package/src/_services/dynamo-nts-app-extended.ts +87 -7
- package/src/_services/dynamo-nts-app.ts +131 -22
- package/src/_services/dynamo-nts-auth.service.ts +79 -5
- package/src/_services/dynamo-nts-data.service.ts +110 -73
- package/src/_services/dynamo-nts-db.service.ts +323 -279
- package/src/_services/dynamo-nts-routing-module.service.ts +39 -0
|
@@ -31,6 +31,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
31
31
|
|
|
32
32
|
depKey?: string;
|
|
33
33
|
depDBServiceKey?: string;
|
|
34
|
+
private depDataDBService: DynamoNTS_DBService<any>;
|
|
34
35
|
|
|
35
36
|
// dataModelParams?: DynamoBEDataPropertyParams[] = [];
|
|
36
37
|
dataParams: DynamoNTS_DataParams;
|
|
@@ -56,15 +57,13 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
56
57
|
*/
|
|
57
58
|
async getAll(): Promise<void> {
|
|
58
59
|
try {
|
|
59
|
-
await this.dataDBService.getAll()
|
|
60
|
-
this.dataList = dataList;
|
|
61
|
-
});
|
|
60
|
+
this.dataList = await this.dataDBService.getAll();
|
|
62
61
|
} catch (error) {
|
|
63
62
|
throw new Dynamo_Error({
|
|
64
63
|
status: 417,
|
|
65
64
|
errorCode: 'NTS-DS0-GA0',
|
|
66
65
|
addECToUserMsg: true,
|
|
67
|
-
message:
|
|
66
|
+
message: `getAll was unsuccessful (${this.dataParams.dataName})`,
|
|
68
67
|
userMessage: this.defaultErrorUserMsg,
|
|
69
68
|
error: error
|
|
70
69
|
});
|
|
@@ -72,25 +71,34 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
/**
|
|
74
|
+
* @description
|
|
75
75
|
* returns data from database by id
|
|
76
|
+
* also if dontSetToService is false or not setted,
|
|
77
|
+
* the data will be saved to the service
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* If you need to get-save a data, if possible,
|
|
81
|
+
* use db-service update instead.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} id
|
|
84
|
+
* @param dontSetToService
|
|
85
|
+
*
|
|
86
|
+
* @return {T} data: T
|
|
76
87
|
*/
|
|
77
88
|
async getDataById(id?: string, dontSetToService?: boolean): Promise<T> {
|
|
78
89
|
try {
|
|
79
90
|
if (id || this.data._id) {
|
|
80
|
-
let dataExists: T;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
dataExists = data;
|
|
86
|
-
});
|
|
91
|
+
let dataExists: T = await this.dataDBService.getDataById(id ? id : this.data._id);
|
|
92
|
+
if (!dontSetToService && dataExists) {
|
|
93
|
+
this.data = dataExists;
|
|
94
|
+
}
|
|
87
95
|
return dataExists;
|
|
88
96
|
} else {
|
|
89
97
|
throw new Dynamo_Error({
|
|
90
98
|
status: 417,
|
|
91
99
|
errorCode: 'NTS-DS0-GI1',
|
|
92
100
|
addECToUserMsg: true,
|
|
93
|
-
message: `ID is missing! (maybe you wanted to use getDataByDependencyId instead...)`,
|
|
101
|
+
message: `ID is missing! (maybe you wanted to use getDataByDependencyId() instead...) (${this.dataParams.dataName})`,
|
|
94
102
|
userMessage: this.defaultErrorUserMsg
|
|
95
103
|
});
|
|
96
104
|
}
|
|
@@ -99,7 +107,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
99
107
|
status: 417,
|
|
100
108
|
errorCode: 'NTS-DS0-GI0',
|
|
101
109
|
addECToUserMsg: true,
|
|
102
|
-
message:
|
|
110
|
+
message: `getDataById was unsuccessful (${this.dataParams.dataName})`,
|
|
103
111
|
userMessage: this.defaultErrorUserMsg,
|
|
104
112
|
error: error
|
|
105
113
|
});
|
|
@@ -114,20 +122,17 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
114
122
|
try {
|
|
115
123
|
if (this.depKey) {
|
|
116
124
|
if (dependencyId || this.data[this.depKey]) {
|
|
117
|
-
let dataExists: T;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
dataExists = data;
|
|
123
|
-
});
|
|
125
|
+
let dataExists: T = await this.dataDBService.getDataByDependencyId(dependencyId ? dependencyId : this.data[this.depKey]);
|
|
126
|
+
if (!dontSetToService && dataExists) {
|
|
127
|
+
this.data = dataExists;
|
|
128
|
+
}
|
|
124
129
|
return dataExists;
|
|
125
130
|
} else {
|
|
126
131
|
throw new Dynamo_Error({
|
|
127
132
|
status: 417,
|
|
128
133
|
errorCode: 'NTS-DS0-GD3',
|
|
129
134
|
addECToUserMsg: true,
|
|
130
|
-
message: `${this.depKey} is missing
|
|
135
|
+
message: `${this.depKey} is missing! (${this.dataParams.dataName})`,
|
|
131
136
|
userMessage: this.defaultErrorUserMsg
|
|
132
137
|
});
|
|
133
138
|
}
|
|
@@ -136,7 +141,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
136
141
|
status: 417,
|
|
137
142
|
errorCode: 'NTS-DS0-GD2',
|
|
138
143
|
addECToUserMsg: true,
|
|
139
|
-
message: 'dependencyDataIdKey is missing from service!
|
|
144
|
+
message: `'dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
|
|
140
145
|
userMessage: this.defaultErrorUserMsg
|
|
141
146
|
});
|
|
142
147
|
}
|
|
@@ -145,7 +150,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
145
150
|
status: 417,
|
|
146
151
|
errorCode: 'NTS-DS0-GD0',
|
|
147
152
|
addECToUserMsg: true,
|
|
148
|
-
message:
|
|
153
|
+
message: `getDataByDependencyId was unsuccessful (${this.dataParams.dataName})`,
|
|
149
154
|
userMessage: this.defaultErrorUserMsg,
|
|
150
155
|
error: error
|
|
151
156
|
});
|
|
@@ -160,15 +165,13 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
160
165
|
try {
|
|
161
166
|
if (this.depKey) {
|
|
162
167
|
if (dependencyId || this.data[this.depKey]) {
|
|
163
|
-
await this.dataDBService.getDataListByDependencyId(dependencyId ? dependencyId : this.data[this.depKey])
|
|
164
|
-
this.dataList = data;
|
|
165
|
-
});
|
|
168
|
+
this.dataList = await this.dataDBService.getDataListByDependencyId(dependencyId ? dependencyId : this.data[this.depKey]);
|
|
166
169
|
} else {
|
|
167
170
|
throw new Dynamo_Error({
|
|
168
171
|
status: 417,
|
|
169
172
|
errorCode: 'NTS-DS0-GLD3',
|
|
170
173
|
addECToUserMsg: true,
|
|
171
|
-
message: `${this.depKey} is missing
|
|
174
|
+
message: `${this.depKey} is missing (${this.dataParams.dataName})`,
|
|
172
175
|
userMessage: this.defaultErrorUserMsg
|
|
173
176
|
});
|
|
174
177
|
}
|
|
@@ -177,7 +180,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
177
180
|
status: 417,
|
|
178
181
|
errorCode: 'NTS-DS0-GLD2',
|
|
179
182
|
addECToUserMsg: true,
|
|
180
|
-
message:
|
|
183
|
+
message: `dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
|
|
181
184
|
userMessage: this.defaultErrorUserMsg
|
|
182
185
|
});
|
|
183
186
|
}
|
|
@@ -186,7 +189,41 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
186
189
|
status: 417,
|
|
187
190
|
errorCode: 'NTS-DS0-GLD0',
|
|
188
191
|
addECToUserMsg: true,
|
|
189
|
-
message:
|
|
192
|
+
message: `getDataListByDependencyId was unsuccessful (${this.dataParams.dataName})`,
|
|
193
|
+
userMessage: this.defaultErrorUserMsg,
|
|
194
|
+
error: error
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* This function uses the dataDBService.updateOne function.
|
|
201
|
+
* This uses updateBy if setted, or data._id if its setted or this.data[this.dependencyKey]
|
|
202
|
+
* @param set
|
|
203
|
+
*/
|
|
204
|
+
async updateData(set: { updateBy?: any, update: any }): Promise<void> {
|
|
205
|
+
try {
|
|
206
|
+
if (set.updateBy) {
|
|
207
|
+
await this.dataDBService.updateOne(set.updateBy, set.update, this.issuer);
|
|
208
|
+
} else if (this.data._id) {
|
|
209
|
+
await this.dataDBService.updateOne({ _id: this.data._id }, set.update, this.issuer);
|
|
210
|
+
} else if (this.depKey && this.data[this.depKey]) {
|
|
211
|
+
await this.dataDBService.updateOne({ [this.depKey]: this.data[this.depKey] }, set.update, this.issuer);
|
|
212
|
+
} else {
|
|
213
|
+
throw new Dynamo_Error({
|
|
214
|
+
status: 417,
|
|
215
|
+
errorCode: 'NTS-DS0-UD1',
|
|
216
|
+
addECToUserMsg: true,
|
|
217
|
+
message: `no usable parameter provided for updateData; no updateBy, no id, no dependencyId (${this.dataParams.dataName})`,
|
|
218
|
+
userMessage: this.defaultErrorUserMsg,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
} catch (error) {
|
|
222
|
+
throw new Dynamo_Error({
|
|
223
|
+
status: 417,
|
|
224
|
+
errorCode: 'NTS-DS0-UD0',
|
|
225
|
+
addECToUserMsg: true,
|
|
226
|
+
message: `updateData was unsuccessful (${this.dataParams.dataName})`,
|
|
190
227
|
userMessage: this.defaultErrorUserMsg,
|
|
191
228
|
error: error
|
|
192
229
|
});
|
|
@@ -196,58 +233,51 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
196
233
|
/**
|
|
197
234
|
* modifies data if the data have ID and already exists in the DB,
|
|
198
235
|
* creates new if the ID is not present or cant find in DB,
|
|
199
|
-
* and if dependency data setted up, will check before creation
|
|
236
|
+
* and if dependency data setted up, will check before creation,
|
|
237
|
+
* @warning
|
|
238
|
+
* but the proper way to update data, if you use update method instead,
|
|
239
|
+
* this way, you can avoid data override errors
|
|
240
|
+
* (when you simultaneously trying to change the same data's
|
|
241
|
+
* different values from different flows)
|
|
200
242
|
*/
|
|
201
243
|
async saveData(): Promise<void> {
|
|
202
244
|
try {
|
|
203
245
|
if (this.data._id) {
|
|
204
246
|
// check if already exists
|
|
205
|
-
let dataExists: T;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
247
|
+
let dataExists: T = await this.getDataById(null, true).catch(() => null);
|
|
248
|
+
if (dataExists) {
|
|
249
|
+
// if data exists do modify
|
|
250
|
+
this.data = await this.dataDBService.modifyData(this.data, this.issuer);
|
|
251
|
+
} else {
|
|
210
252
|
// if data not exists check that dependency already exists for this
|
|
211
253
|
if (this.depKey) {
|
|
212
|
-
if (this.data[this.depKey]) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
254
|
+
if (!this.data[this.depKey]) {
|
|
255
|
+
throw new Dynamo_Error({
|
|
256
|
+
status: 417,
|
|
257
|
+
errorCode: 'NTS-DS0-SD1',
|
|
258
|
+
addECToUserMsg: true,
|
|
259
|
+
message: `saveData was unsuccessful: dependency data id missing from data (key: ${this.depKey})`,
|
|
260
|
+
userMessage: this.defaultErrorUserMsg
|
|
216
261
|
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
addECToUserMsg: true,
|
|
222
|
-
message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]})`,
|
|
223
|
-
userMessage: this.defaultErrorUserMsg
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
} else {
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
let dependencyExists = await this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
|
|
265
|
+
if (!dependencyExists) {
|
|
227
266
|
throw new Dynamo_Error({
|
|
228
267
|
status: 417,
|
|
229
268
|
errorCode: 'NTS-DS0-SD2',
|
|
230
269
|
addECToUserMsg: true,
|
|
231
|
-
message: `saveData was unsuccessful: dependency data
|
|
270
|
+
message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]})`,
|
|
232
271
|
userMessage: this.defaultErrorUserMsg
|
|
233
272
|
});
|
|
234
273
|
}
|
|
235
274
|
}
|
|
236
275
|
// if data not exists create new data
|
|
237
|
-
await this.dataDBService.createData(this.data, this.issuer)
|
|
238
|
-
this.data = data;
|
|
239
|
-
});
|
|
240
|
-
} else {
|
|
241
|
-
// if data exists do modify
|
|
242
|
-
await this.dataDBService.modifyData(this.data, this.issuer).then((data: T) => {
|
|
243
|
-
this.data = data;
|
|
244
|
-
});
|
|
276
|
+
this.data = await this.dataDBService.createData(this.data, this.issuer);
|
|
245
277
|
}
|
|
246
278
|
} else {
|
|
247
279
|
// if ID is not present, data not exists, create new data
|
|
248
|
-
await this.dataDBService.createData(this.data, this.issuer)
|
|
249
|
-
this.data = data;
|
|
250
|
-
});
|
|
280
|
+
this.data = await this.dataDBService.createData(this.data, this.issuer);
|
|
251
281
|
}
|
|
252
282
|
} catch (error) {
|
|
253
283
|
throw new Dynamo_Error({
|
|
@@ -266,23 +296,23 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
266
296
|
*/
|
|
267
297
|
async deleteData(): Promise<void> {
|
|
268
298
|
try {
|
|
269
|
-
if (this.data._id) {
|
|
270
|
-
await this.dataDBService.deleteDataById(this.data._id);
|
|
271
|
-
} else {
|
|
299
|
+
if (!this.data._id) {
|
|
272
300
|
throw new Dynamo_Error({
|
|
273
301
|
status: 417,
|
|
274
302
|
errorCode: 'NTS-DS0-DD1',
|
|
275
303
|
addECToUserMsg: true,
|
|
276
|
-
message:
|
|
304
|
+
message: `ID is missing! (${this.dataParams.dataName})` ,
|
|
277
305
|
userMessage: this.defaultErrorUserMsg,
|
|
278
306
|
});
|
|
279
307
|
}
|
|
308
|
+
|
|
309
|
+
await this.dataDBService.deleteDataById(this.data._id);
|
|
280
310
|
} catch (error) {
|
|
281
311
|
throw new Dynamo_Error({
|
|
282
312
|
status: 417,
|
|
283
313
|
errorCode: 'NTS-DS0-DD0',
|
|
284
314
|
addECToUserMsg: true,
|
|
285
|
-
message:
|
|
315
|
+
message: `deleteData was unsuccessful (${this.dataParams.dataName})`,
|
|
286
316
|
userMessage: this.defaultErrorUserMsg,
|
|
287
317
|
error: error
|
|
288
318
|
});
|
|
@@ -306,9 +336,10 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
306
336
|
userMessage: this.defaultValidationErrorUserMsg
|
|
307
337
|
});
|
|
308
338
|
}
|
|
339
|
+
|
|
309
340
|
// specific Date validation
|
|
310
341
|
if (this.dataParams.modelParams[i].type === 'Date' && !(new Date(this.data[this.dataParams.modelParams[i].key]) instanceof Date)) {
|
|
311
|
-
throw new Dynamo_Error({
|
|
342
|
+
throw new Dynamo_Error({
|
|
312
343
|
status: 422,
|
|
313
344
|
errorCode: 'NTS-DS0-VD2',
|
|
314
345
|
addECToUserMsg: true,
|
|
@@ -316,6 +347,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
316
347
|
userMessage: this.defaultValidationErrorUserMsg
|
|
317
348
|
});
|
|
318
349
|
}
|
|
350
|
+
|
|
319
351
|
// call additional validators
|
|
320
352
|
if (this.dataParams.modelParams[i].additionalValidators) {
|
|
321
353
|
for (let j = 0; j < this.dataParams.modelParams[i].additionalValidators.length; j++) {
|
|
@@ -328,7 +360,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
328
360
|
status: 422,
|
|
329
361
|
errorCode: 'NTS-DS0-VD0',
|
|
330
362
|
addECToUserMsg: true,
|
|
331
|
-
message:
|
|
363
|
+
message: `validateForSave was unsuccessful (${this.dataParams.dataName})`,
|
|
332
364
|
userMessage: this.defaultErrorUserMsg,
|
|
333
365
|
error: error
|
|
334
366
|
});
|
|
@@ -342,8 +374,8 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
342
374
|
const dependencyParam: DynamoNTS_DataPropertyParams = this.dataParams.modelParams.find((modelParams: DynamoNTS_DataPropertyParams) => modelParams.isDependencyHook);
|
|
343
375
|
if (dependencyParam) {
|
|
344
376
|
this.depKey = dependencyParam.key;
|
|
345
|
-
if (dependencyParam.
|
|
346
|
-
this.depDBServiceKey = dependencyParam.
|
|
377
|
+
if (dependencyParam.dependencyDataName) {
|
|
378
|
+
this.depDBServiceKey = dependencyParam.dependencyDataName;
|
|
347
379
|
}
|
|
348
380
|
}
|
|
349
381
|
}
|
|
@@ -353,9 +385,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
353
385
|
* @returns
|
|
354
386
|
*/
|
|
355
387
|
getDependencyDataDBService(): DynamoNTS_DBService<any> {
|
|
356
|
-
if (this.depDBServiceKey) {
|
|
357
|
-
return DynamoNTS_GlobalService.getDBService(this.dataParams);
|
|
358
|
-
} else {
|
|
388
|
+
if (!this.depDBServiceKey) {
|
|
359
389
|
throw new Dynamo_Error({
|
|
360
390
|
status: 501,
|
|
361
391
|
errorCode: 'NTS-DS0-GDDB0',
|
|
@@ -364,5 +394,12 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
364
394
|
userMessage: this.defaultErrorUserMsg
|
|
365
395
|
});
|
|
366
396
|
}
|
|
397
|
+
|
|
398
|
+
if (this.depDataDBService) {
|
|
399
|
+
return this.depDataDBService;
|
|
400
|
+
} else {
|
|
401
|
+
this.depDataDBService = DynamoNTS_GlobalService.getDBServiceByKey(this.depDBServiceKey);
|
|
402
|
+
return this.depDataDBService;
|
|
403
|
+
}
|
|
367
404
|
}
|
|
368
405
|
}
|