@futdevpro/nts-dynamo 1.5.53 → 1.5.55

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.
@@ -1,8 +1,9 @@
1
1
 
2
- import { Dynamo_Metadata, DynamoNTS_DataParams, DynamoNTS_DataPropertyParams, Dynamo_Error } from '@futdevpro/fsm-dynamo';
2
+ import { Dynamo_Metadata, DynamoNTS_DataParams, DynamoNTS_DataPropertyParams, Dynamo_Error, Dynamo_Shared } from '@futdevpro/fsm-dynamo';
3
3
 
4
4
  import { DynamoNTS_DBService } from './dynamo-nts-db.service';
5
5
  import { DynamoNTS_GlobalService } from './dynamo-nts-global.service';
6
+ import { DynamoNTS_Shared } from './dynamo-nts-shared.service';
6
7
 
7
8
  /**
8
9
  * Basic Data Service that is connected to the relevant DBServices
@@ -27,13 +28,12 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
27
28
  dataDBService: DynamoNTS_DBService<T>;
28
29
  data: T;
29
30
  dataList: T[] = [];
30
- issuer?: string;
31
+ issuer: string;
31
32
 
32
33
  depKey?: string;
33
34
  depDBServiceKey?: string;
34
35
  private depDataDBService: DynamoNTS_DBService<any>;
35
36
 
36
- // dataModelParams?: DynamoBEDataPropertyParams[] = [];
37
37
  dataParams: DynamoNTS_DataParams;
38
38
 
39
39
  defaultErrorUserMsg = 'We encountered an unhandled Data Error, please contact the responsible development team.';
@@ -42,12 +42,11 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
42
42
  constructor(
43
43
  data: T,
44
44
  dataParams: DynamoNTS_DataParams,
45
- issuer?: string,
45
+ issuer: string,
46
46
  ) {
47
47
  this.dataDBService = DynamoNTS_GlobalService.getDBService<T>(dataParams);
48
48
  this.data = data;
49
49
  this.dataParams = dataParams;
50
- // this.dataModelParams = dataParams.modelParams;
51
50
  this.lookForDependencyDataSettings();
52
51
  this.issuer = issuer;
53
52
  }
@@ -55,9 +54,21 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
55
54
  /**
56
55
  * returns all data from database to service dataList
57
56
  */
58
- async getAll(): Promise<void> {
57
+ async getAll(dontSetToService?: boolean): Promise<T[]> {
59
58
  try {
60
- this.dataList = await this.dataDBService.getAll();
59
+ const dataListExists: T[] = await this.dataDBService.getAll().catch(error => {
60
+ if (error?.errorCodes?.includes('NTS-DBS-GA1')) {
61
+ Dynamo_Shared.logWarning(`getAll ${this.dataParams.dataName} didn't found any.`);
62
+ return [];
63
+ } else {
64
+ throw error;
65
+ }
66
+ });
67
+ if (!dontSetToService) {
68
+ this.dataList = dataListExists;
69
+ }
70
+
71
+ return dataListExists;
61
72
  } catch (error) {
62
73
  throw new Dynamo_Error({
63
74
  status: 417,
@@ -74,7 +85,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
74
85
  * @description
75
86
  * returns data from database by id
76
87
  * also if dontSetToService is false or not setted,
77
- * the data will be saved to the service
88
+ * the data will be saved to the service, even if its not found
78
89
  *
79
90
  * @remarks
80
91
  * If you need to get-save a data, if possible,
@@ -87,13 +98,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
87
98
  */
88
99
  async getDataById(id?: string, dontSetToService?: boolean): Promise<T> {
89
100
  try {
90
- if (id || this.data._id) {
91
- let dataExists: T = await this.dataDBService.getDataById(id ? id : this.data._id);
92
- if (!dontSetToService && dataExists) {
93
- this.data = dataExists;
94
- }
95
- return dataExists;
96
- } else {
101
+ if (!id && !this.data._id) {
97
102
  throw new Dynamo_Error({
98
103
  status: 417,
99
104
  errorCode: 'NTS-DS0-GI1',
@@ -102,15 +107,33 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
102
107
  userMessage: this.defaultErrorUserMsg
103
108
  });
104
109
  }
105
- } catch (error) {
106
- throw new Dynamo_Error({
107
- status: 417,
108
- errorCode: 'NTS-DS0-GI0',
109
- addECToUserMsg: true,
110
- message: `getDataById was unsuccessful (${this.dataParams.dataName})`,
111
- userMessage: this.defaultErrorUserMsg,
112
- error: error
110
+
111
+ const dataExists: T = await this.dataDBService.getDataById(id ?? this.data._id).catch(error => {
112
+ if (error?.errorCodes?.includes('NTS-DBS-GI1')) {
113
+ Dynamo_Shared.logWarning(`getDataById ${this.dataParams.dataName} (${id ?? this.data._id}) didn't found any.`);
114
+ return null;
115
+ } else {
116
+ throw error;
117
+ }
113
118
  });
119
+ if (!dontSetToService) {
120
+ this.data = dataExists;
121
+ }
122
+
123
+ return dataExists;
124
+ } catch (error) {
125
+ if (error?.errorCode == 'NTS-DS0-GI1') {
126
+ throw error;
127
+ } else {
128
+ throw new Dynamo_Error({
129
+ status: 417,
130
+ errorCode: 'NTS-DS0-GI0',
131
+ addECToUserMsg: true,
132
+ message: `getDataById was unsuccessful (${this.dataParams.dataName})`,
133
+ userMessage: this.defaultErrorUserMsg,
134
+ error: error
135
+ });
136
+ }
114
137
  }
115
138
  }
116
139
 
@@ -120,40 +143,52 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
120
143
  */
121
144
  async getDataByDependencyId(dependencyId?: string, dontSetToService?: boolean): Promise<T> {
122
145
  try {
123
- if (this.depKey) {
124
- if (dependencyId || this.data[this.depKey]) {
125
- let dataExists: T = await this.dataDBService.getDataByDependencyId(dependencyId ? dependencyId : this.data[this.depKey]);
126
- if (!dontSetToService && dataExists) {
127
- this.data = dataExists;
128
- }
129
- return dataExists;
130
- } else {
131
- throw new Dynamo_Error({
132
- status: 417,
133
- errorCode: 'NTS-DS0-GD3',
134
- addECToUserMsg: true,
135
- message: `${this.depKey} is missing! (${this.dataParams.dataName})`,
136
- userMessage: this.defaultErrorUserMsg
137
- });
138
- }
139
- } else {
146
+ if (!this.depKey) {
140
147
  throw new Dynamo_Error({
141
148
  status: 417,
142
- errorCode: 'NTS-DS0-GD2',
149
+ errorCode: 'NTS-DS0-GD1',
143
150
  addECToUserMsg: true,
144
151
  message: `'dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
145
152
  userMessage: this.defaultErrorUserMsg
146
153
  });
147
154
  }
148
- } catch (error) {
149
- throw new Dynamo_Error({
150
- status: 417,
151
- errorCode: 'NTS-DS0-GD0',
152
- addECToUserMsg: true,
153
- message: `getDataByDependencyId was unsuccessful (${this.dataParams.dataName})`,
154
- userMessage: this.defaultErrorUserMsg,
155
- error: error
155
+
156
+ if (!dependencyId && !this.data[this.depKey]) {
157
+ throw new Dynamo_Error({
158
+ status: 417,
159
+ errorCode: 'NTS-DS0-GD2',
160
+ addECToUserMsg: true,
161
+ message: `${this.depKey} is missing! (${this.dataParams.dataName})`,
162
+ userMessage: this.defaultErrorUserMsg
163
+ });
164
+ }
165
+
166
+ const dataExists: T = await this.dataDBService.getDataByDependencyId(dependencyId ?? this.data[this.depKey]).catch(error => {
167
+ if (error?.errorCodes?.includes('NTS-DBS-GD2')) {
168
+ Dynamo_Shared.logWarning(`getDataByDependencyId ${this.dataParams.dataName} (${this.depKey}: ${dependencyId ?? this.data[this.depKey]}) didn't found any.`);
169
+ return null;
170
+ } else {
171
+ throw error;
172
+ }
156
173
  });
174
+ if (!dontSetToService) {
175
+ this.data = dataExists;
176
+ }
177
+
178
+ return dataExists;
179
+ } catch (error) {
180
+ if (['NTS-DS0-GD1', 'NTS-DS0-GD2'].includes(error?.errorCode)) {
181
+ throw error;
182
+ } else {
183
+ throw new Dynamo_Error({
184
+ status: 417,
185
+ errorCode: 'NTS-DS0-GD0',
186
+ addECToUserMsg: true,
187
+ message: `getDataByDependencyId was unsuccessful (${this.dataParams.dataName})`,
188
+ userMessage: this.defaultErrorUserMsg,
189
+ error: error
190
+ });
191
+ }
157
192
  }
158
193
  }
159
194
 
@@ -161,35 +196,165 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
161
196
  * returns dataList from database by dependencyId to the service
162
197
  * @param dependencyId
163
198
  */
164
- async getDataListByDependencyId(dependencyId?: string): Promise<void> {
199
+ async getDataListByDependencyId(dependencyId?: string, dontSetToService?: boolean): Promise<T[]> {
165
200
  try {
166
- if (this.depKey) {
167
- if (dependencyId || this.data[this.depKey]) {
168
- this.dataList = await this.dataDBService.getDataListByDependencyId(dependencyId ? dependencyId : this.data[this.depKey]);
201
+ if (!this.depKey) {
202
+ throw new Dynamo_Error({
203
+ status: 417,
204
+ errorCode: 'NTS-DS0-GLD1',
205
+ addECToUserMsg: true,
206
+ message: `dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
207
+ userMessage: this.defaultErrorUserMsg
208
+ });
209
+ }
210
+
211
+ if (!dependencyId && !this.data[this.depKey]) {
212
+ throw new Dynamo_Error({
213
+ status: 417,
214
+ errorCode: 'NTS-DS0-GLD2',
215
+ addECToUserMsg: true,
216
+ message: `${this.depKey} is missing (${this.dataParams.dataName})`,
217
+ userMessage: this.defaultErrorUserMsg
218
+ });
219
+ }
220
+
221
+ const dataListExists: T[] = await this.dataDBService.getDataListByDependencyId(dependencyId ?? this.data[this.depKey]).catch(error => {
222
+ if (error?.errorCodes?.includes('NTS-DBS-GLD2')) {
223
+ Dynamo_Shared.logWarning(`getDataListByDependencyId ${this.dataParams.dataName} (${this.depKey}: ${dependencyId ?? this.data[this.depKey]}) didn't found any.`);
224
+ return [];
169
225
  } else {
170
- throw new Dynamo_Error({
171
- status: 417,
172
- errorCode: 'NTS-DS0-GLD3',
173
- addECToUserMsg: true,
174
- message: `${this.depKey} is missing (${this.dataParams.dataName})`,
175
- userMessage: this.defaultErrorUserMsg
176
- });
226
+ throw error;
177
227
  }
228
+ });
229
+ if (!dontSetToService) {
230
+ this.dataList = dataListExists;
231
+ }
232
+
233
+ return dataListExists;
234
+ } catch (error) {
235
+ if (['NTS-DS0-GLD1', 'NTS-DS0-GLD2'].includes(error?.errorCode)) {
236
+ throw error;
178
237
  } else {
179
238
  throw new Dynamo_Error({
180
239
  status: 417,
181
- errorCode: 'NTS-DS0-GLD2',
240
+ errorCode: 'NTS-DS0-GLD0',
182
241
  addECToUserMsg: true,
183
- message: `dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
184
- userMessage: this.defaultErrorUserMsg
242
+ message: `getDataListByDependencyId was unsuccessful (${this.dataParams.dataName})`,
243
+ userMessage: this.defaultErrorUserMsg,
244
+ error: error
185
245
  });
186
246
  }
247
+ }
248
+ }
249
+
250
+ /**
251
+ *
252
+ * // findOne desc:
253
+ *
254
+ * Find the data first by any of its parameters,
255
+ * also if dontSetToService is false or not setted,
256
+ * the data will be saved to the service, even if non found
257
+ *
258
+ * @param filter if you can, use unique parameters for find!
259
+ *
260
+ * @example
261
+ * // by email:
262
+ * { email: email }
263
+ * //
264
+ * @example
265
+ * // or by id that is in list:
266
+ * { userIds: { $in: this.userId } }
267
+ * //
268
+ * @example
269
+ * // or by number or Date that is Greater Than AND Less Than:
270
+ * { points: { $gt: 2, $lt: 14 } }
271
+ * // further tools (syntax matches with $gt):
272
+ * $eq: // Matches values that are EQual to a specified value.
273
+ * $gte: // Matches values that are Greater Than OR Equal to a specified value.
274
+ * $lte: // Matches values that are Less Than or Equal to a specified value.
275
+ * $ne: // Matches all values that are Not Equal to a specified value.
276
+ * $nin: // Matches None of the values specified IN an array.
277
+ * //
278
+ * @returns {T} data: T
279
+ */
280
+ async findData(findBy: any, dontSetToService?: boolean): Promise<T> {
281
+ try {
282
+ const dataExists: T = await this.dataDBService.findOne(findBy).catch(error => {
283
+ if (error?.errorCodes?.includes('NTS-DBS-FO1')) {
284
+ Dynamo_Shared.logWarning(`findData ${this.dataParams.dataName} didn't found any.`);
285
+ return null;
286
+ } else {
287
+ throw error;
288
+ }
289
+ });
290
+ if (!dontSetToService) {
291
+ this.data = dataExists;
292
+ }
293
+
294
+ return dataExists;
187
295
  } catch (error) {
188
296
  throw new Dynamo_Error({
189
297
  status: 417,
190
- errorCode: 'NTS-DS0-GLD0',
298
+ errorCode: 'NTS-DS0-FD0',
191
299
  addECToUserMsg: true,
192
- message: `getDataListByDependencyId was unsuccessful (${this.dataParams.dataName})`,
300
+ message: `findData was unsuccessful (${this.dataParams.dataName})`,
301
+ userMessage: this.defaultErrorUserMsg,
302
+ error: error
303
+ });
304
+ }
305
+ }
306
+
307
+ /**
308
+ *
309
+ * // find desc:
310
+ *
311
+ * Find the data first by any of its parameters,
312
+ * also if dontSetToService is false or not setted,
313
+ * the data will be saved to the service, even if non found
314
+ *
315
+ * @param filter if you can, use unique parameters for find!
316
+ *
317
+ * @example
318
+ * // by email:
319
+ * { email: email }
320
+ * //
321
+ * @example
322
+ * // or by id that is in list:
323
+ * { userIds: { $in: this.userId } }
324
+ * //
325
+ * @example
326
+ * // or by number or Date that is Greater Than AND Less Than:
327
+ * { points: { $gt: 2, $lt: 14 } }
328
+ * // further tools (syntax matches with $gt):
329
+ * $eq: // Matches values that are EQual to a specified value.
330
+ * $gte: // Matches values that are Greater Than OR Equal to a specified value.
331
+ * $lte: // Matches values that are Less Than or Equal to a specified value.
332
+ * $ne: // Matches all values that are Not Equal to a specified value.
333
+ * $nin: // Matches None of the values specified IN an array.
334
+ * //
335
+ * @returns {T[]} dataList: T[]
336
+ */
337
+ async findDatas(findBy: any, dontSetToService?: boolean): Promise<T[]> {
338
+ try {
339
+ const dataListExists: T[] = await this.dataDBService.find(findBy).catch(error => {
340
+ if (error?.errorCodes?.includes('NTS-DBS-F1')) {
341
+ Dynamo_Shared.logWarning(`findDatas ${this.dataParams.dataName} didn't found any.`);
342
+ return [];
343
+ } else {
344
+ throw error;
345
+ }
346
+ });
347
+ if (!dontSetToService) {
348
+ this.dataList = dataListExists;
349
+ }
350
+
351
+ return dataListExists;
352
+ } catch (error) {
353
+ throw new Dynamo_Error({
354
+ status: 417,
355
+ errorCode: 'NTS-DS0-FDS0',
356
+ addECToUserMsg: true,
357
+ message: `findDatas was unsuccessful (${this.dataParams.dataName})`,
193
358
  userMessage: this.defaultErrorUserMsg,
194
359
  error: error
195
360
  });
@@ -200,6 +365,57 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
200
365
  * This function uses the dataDBService.updateOne function.
201
366
  * This uses updateBy if setted, or data._id if its setted or this.data[this.dependencyKey]
202
367
  * @param set
368
+ *
369
+ * // updateOne desc:
370
+ *
371
+ * Find the data first by any of its parameters, throws error if not found
372
+ * @param filter This uses the basic Mongoose updateOne.
373
+ * If you can, use unique parameters for find!
374
+ * @example
375
+ * // by email:
376
+ * { email: email }
377
+ * //
378
+ * @example
379
+ * // or by id that is in list:
380
+ * { userIds: { $in: this.userId } }
381
+ * //
382
+ * @example
383
+ * // or by number or Date that is Greater Than AND Less Than:
384
+ * { points: { $gt: 2, $lt: 14 } }
385
+ * // further tools (syntax matches with $gt):
386
+ * $eq: // Matches values that are EQual to a specified value.
387
+ * $gte: // Matches values that are Greater Than OR Equal to a specified value.
388
+ * $lte: // Matches values that are Less Than or Equal to a specified value.
389
+ * $ne: // Matches all values that are Not Equal to a specified value.
390
+ * $nin: // Matches None of the values specified IN an array.
391
+ * //
392
+ *
393
+ * @param update this uses the basic Mongoose updateOne
394
+ * @example
395
+ * // increase a specific value (here by 15):
396
+ * { $inc: { popularity: 15 } }
397
+ * //
398
+ * @example
399
+ * // or add element to a list:
400
+ * { $push: { reactions: this.newReaction }
401
+ * // or add multiple elements to a list
402
+ * { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
403
+ * //
404
+ * @example
405
+ * // or all at once
406
+ * {
407
+ * $inc: { popularity: this.newVote.amount },
408
+ * emailVerified: true,
409
+ * $push: { reactions: this.newReaction }
410
+ * }
411
+ * // further tools (syntax matches with $inc):
412
+ * $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
413
+ * $min: // Only updates the field if the specified value is less than the existing field value.
414
+ * $max: // Only updates the field if the specified value is greater than the existing field value.
415
+ * $mul: // Multiplies the value of the field by the specified amount.
416
+ * $rename: // Renames a field.
417
+ * $unset: // Removes the specified field from a document. (set: "" to value)
418
+ * //
203
419
  */
204
420
  async updateData(set: { updateBy?: any, update: any }): Promise<void> {
205
421
  try {
@@ -219,14 +435,18 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
219
435
  });
220
436
  }
221
437
  } 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})`,
227
- userMessage: this.defaultErrorUserMsg,
228
- error: error
229
- });
438
+ if (error?.errorCode == 'NTS-DS0-UD1') {
439
+ throw error;
440
+ } else {
441
+ throw new Dynamo_Error({
442
+ status: 417,
443
+ errorCode: 'NTS-DS0-UD0',
444
+ addECToUserMsg: true,
445
+ message: `updateData was unsuccessful (${this.dataParams.dataName})`,
446
+ userMessage: this.defaultErrorUserMsg,
447
+ error: error
448
+ });
449
+ }
230
450
  }
231
451
  }
232
452
 
@@ -234,6 +454,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
234
454
  * modifies data if the data have ID and already exists in the DB,
235
455
  * creates new if the ID is not present or cant find in DB,
236
456
  * and if dependency data setted up, will check before creation,
457
+ *
237
458
  * @warning
238
459
  * but the proper way to update data, if you use update method instead,
239
460
  * this way, you can avoid data override errors
@@ -244,7 +465,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
244
465
  try {
245
466
  if (this.data._id) {
246
467
  // check if already exists
247
- let dataExists: T = await this.getDataById(null, true).catch(() => null);
468
+ const dataExists: T = await this.getDataById(null, true);
248
469
  if (dataExists) {
249
470
  // if data exists do modify
250
471
  this.data = await this.dataDBService.modifyData(this.data, this.issuer);
@@ -261,8 +482,21 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
261
482
  });
262
483
  }
263
484
 
264
- let dependencyExists = await this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
265
- if (!dependencyExists) {
485
+ /* const dependencyExists = */
486
+ await this.getDependencyDataDBService().getDataById(this.data[this.depKey]).catch(error => {
487
+ if (error?.errorCodes?.includes('NTS-DBS-GI1')) {
488
+ throw new Dynamo_Error({
489
+ status: 417,
490
+ errorCode: 'NTS-DS0-SD2',
491
+ addECToUserMsg: true,
492
+ message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]})`,
493
+ userMessage: this.defaultErrorUserMsg
494
+ });
495
+ } else {
496
+ throw error;
497
+ }
498
+ });
499
+ /* if (!dependencyExists) {
266
500
  throw new Dynamo_Error({
267
501
  status: 417,
268
502
  errorCode: 'NTS-DS0-SD2',
@@ -270,8 +504,9 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
270
504
  message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]})`,
271
505
  userMessage: this.defaultErrorUserMsg
272
506
  });
273
- }
507
+ } */
274
508
  }
509
+
275
510
  // if data not exists create new data
276
511
  this.data = await this.dataDBService.createData(this.data, this.issuer);
277
512
  }
@@ -280,14 +515,18 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
280
515
  this.data = await this.dataDBService.createData(this.data, this.issuer);
281
516
  }
282
517
  } catch (error) {
283
- throw new Dynamo_Error({
284
- status: 417,
285
- errorCode: 'NTS-DS0-SD0',
286
- addECToUserMsg: true,
287
- message: `modifyData was unsuccessful (${this.dataParams.dataName})`,
288
- userMessage: this.defaultErrorUserMsg,
289
- error: error
290
- });
518
+ if (['NTS-DS0-SD1', 'NTS-DS0-SD2'].includes(error?.errorCode)) {
519
+ throw error;
520
+ } else {
521
+ throw new Dynamo_Error({
522
+ status: 417,
523
+ errorCode: 'NTS-DS0-SD0',
524
+ addECToUserMsg: true,
525
+ message: `modifyData was unsuccessful (${this.dataParams.dataName})`,
526
+ userMessage: this.defaultErrorUserMsg,
527
+ error: error
528
+ });
529
+ }
291
530
  }
292
531
  }
293
532
 
@@ -308,14 +547,18 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
308
547
 
309
548
  await this.dataDBService.deleteDataById(this.data._id);
310
549
  } catch (error) {
311
- throw new Dynamo_Error({
312
- status: 417,
313
- errorCode: 'NTS-DS0-DD0',
314
- addECToUserMsg: true,
315
- message: `deleteData was unsuccessful (${this.dataParams.dataName})`,
316
- userMessage: this.defaultErrorUserMsg,
317
- error: error
318
- });
550
+ if (error?.errorCode == 'NTS-DS0-DD1') {
551
+ throw error;
552
+ } else {
553
+ throw new Dynamo_Error({
554
+ status: 417,
555
+ errorCode: 'NTS-DS0-DD0',
556
+ addECToUserMsg: true,
557
+ message: `deleteData was unsuccessful (${this.dataParams.dataName})`,
558
+ userMessage: this.defaultErrorUserMsg,
559
+ error: error
560
+ });
561
+ }
319
562
  }
320
563
  }
321
564
 
@@ -326,8 +569,17 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
326
569
  try {
327
570
  for (let i = 0; i < this.dataParams.modelParams.length; i++) {
328
571
  // basic required validations
329
- if ((this.dataParams.modelParams[i].required && (this.data[this.dataParams.modelParams[i].key] === null || this.data[this.dataParams.modelParams[i].key] === undefined)) ||
330
- (this.dataParams.modelParams[i].index && (this.data[this.dataParams.modelParams[i].key] === null || this.data[this.dataParams.modelParams[i].key] === undefined))) {
572
+ if ((this.dataParams.modelParams[i].required &&
573
+ (this.data[this.dataParams.modelParams[i].key] === null ||
574
+ this.data[this.dataParams.modelParams[i].key] === undefined
575
+ )
576
+ ) ||
577
+ (this.dataParams.modelParams[i].index &&
578
+ (this.data[this.dataParams.modelParams[i].key] === null ||
579
+ this.data[this.dataParams.modelParams[i].key] === undefined
580
+ )
581
+ )
582
+ ) {
331
583
  throw new Dynamo_Error({
332
584
  status: 422,
333
585
  errorCode: 'NTS-DS0-VD1',
@@ -338,7 +590,9 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
338
590
  }
339
591
 
340
592
  // specific Date validation
341
- if (this.dataParams.modelParams[i].type === 'Date' && !(new Date(this.data[this.dataParams.modelParams[i].key]) instanceof Date)) {
593
+ if (this.dataParams.modelParams[i].type === 'Date' &&
594
+ !(new Date(this.data[this.dataParams.modelParams[i].key]) instanceof Date)
595
+ ) {
342
596
  throw new Dynamo_Error({
343
597
  status: 422,
344
598
  errorCode: 'NTS-DS0-VD2',
@@ -356,14 +610,18 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
356
610
  }
357
611
  }
358
612
  } catch (error) {
359
- throw new Dynamo_Error({
360
- status: 422,
361
- errorCode: 'NTS-DS0-VD0',
362
- addECToUserMsg: true,
363
- message: `validateForSave was unsuccessful (${this.dataParams.dataName})`,
364
- userMessage: this.defaultErrorUserMsg,
365
- error: error
366
- });
613
+ if (['NTS-DS0-VD1', 'NTS-DS0-VD2'].includes(error?.errorCode)) {
614
+ throw error;
615
+ } else {
616
+ throw new Dynamo_Error({
617
+ status: 422,
618
+ errorCode: 'NTS-DS0-VD0',
619
+ addECToUserMsg: true,
620
+ message: `validateForSave was unsuccessful (${this.dataParams.dataName})`,
621
+ userMessage: this.defaultErrorUserMsg,
622
+ error: error
623
+ });
624
+ }
367
625
  }
368
626
  }
369
627