@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.
@@ -50,14 +50,18 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
50
50
  });
51
51
  }
52
52
  }).catch(error => {
53
- throw new Dynamo_Error({
54
- status: 422,
55
- errorCode: 'NTS-DBS-CD0',
56
- addECToUserMsg: true,
57
- message: `Create new ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
58
- userMessage: this.defaultErrorUserMsg,
59
- error
60
- });
53
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
54
+ throw error;
55
+ } else {
56
+ throw new Dynamo_Error({
57
+ status: 422,
58
+ errorCode: 'NTS-DBS-CD0',
59
+ addECToUserMsg: true,
60
+ message: `Create new ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
61
+ userMessage: this.defaultErrorUserMsg,
62
+ error
63
+ });
64
+ }
61
65
  });
62
66
 
63
67
  if (typeof newData._id === 'object') {
@@ -92,14 +96,18 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
92
96
  });
93
97
  }
94
98
  }).catch(error => {
95
- throw new Dynamo_Error({
96
- status: 417,
97
- errorCode: 'NTS-DBS-FU0',
98
- addECToUserMsg: true,
99
- message: `modify ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
100
- userMessage: this.defaultErrorUserMsg,
101
- error
102
- });
99
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
100
+ throw error;
101
+ } else {
102
+ throw new Dynamo_Error({
103
+ status: 417,
104
+ errorCode: 'NTS-DBS-FU0',
105
+ addECToUserMsg: true,
106
+ message: `modify ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
107
+ userMessage: this.defaultErrorUserMsg,
108
+ error
109
+ });
110
+ }
103
111
  });
104
112
 
105
113
  if (typeof newData._id === 'object') {
@@ -112,7 +120,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
112
120
  }
113
121
 
114
122
  /**
115
- * returns data by _id, throws error if not found
123
+ * returns data by _id,
124
+ * !!!: throws error if not found (errorCode on not found: NTS-DBS-GI1)
116
125
  * @param id id
117
126
  * @returns data
118
127
  */
@@ -121,17 +130,28 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
121
130
  if (res) {
122
131
  return res.toObject() as T;
123
132
  } else {
124
- return null;
133
+ /* return null; */
134
+ throw new Dynamo_Error({
135
+ status: 417,
136
+ errorCode: 'NTS-DBS-GI1',
137
+ addECToUserMsg: true,
138
+ message: `get ${this.dataParams.dbName} by ID was unsuccessful: data not found by id: ${id} (NTS DB)`,
139
+ userMessage: this.defaultErrorUserMsg
140
+ });
125
141
  }
126
142
  }).catch(error => {
127
- throw new Dynamo_Error({
128
- status: 417,
129
- errorCode: 'NTS-DBS-GI0',
130
- addECToUserMsg: true,
131
- message: `get ${this.dataParams.dbName} by ID was unsuccessful (NTS DB)`,
132
- userMessage: this.defaultErrorUserMsg,
133
- error
134
- });
143
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
144
+ throw error;
145
+ } else {
146
+ throw new Dynamo_Error({
147
+ status: 417,
148
+ errorCode: 'NTS-DBS-GI0',
149
+ addECToUserMsg: true,
150
+ message: `get ${this.dataParams.dbName} by ID was unsuccessful (NTS DB)`,
151
+ userMessage: this.defaultErrorUserMsg,
152
+ error
153
+ });
154
+ }
135
155
  });
136
156
 
137
157
  if (data && typeof data._id === 'object') {
@@ -142,7 +162,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
142
162
  }
143
163
 
144
164
  /**
145
- * get data by dependency data id, throws error if not found
165
+ * get data by dependency data id,
166
+ * !!!: throws error if not found (errorCode on not found: NTS-DBS-GD2)
167
+ *
146
168
  * @param dependencyId id
147
169
  * @returns data
148
170
  */
@@ -161,17 +183,28 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
161
183
  if (res) {
162
184
  return res.toObject() as T;
163
185
  } else {
164
- return null;
186
+ /* return null; */
187
+ throw new Dynamo_Error({
188
+ status: 417,
189
+ errorCode: 'NTS-DBS-GD2',
190
+ addECToUserMsg: true,
191
+ message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful: data not found by id: ${dependencyId} (NTS DB)`,
192
+ userMessage: this.defaultErrorUserMsg
193
+ });
165
194
  }
166
195
  }).catch(error => {
167
- throw new Dynamo_Error({
168
- status: 417,
169
- errorCode: 'NTS-DBS-GD1',
170
- addECToUserMsg: true,
171
- message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
172
- userMessage: this.defaultErrorUserMsg,
173
- error
174
- });
196
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
197
+ throw error;
198
+ } else {
199
+ throw new Dynamo_Error({
200
+ status: 417,
201
+ errorCode: 'NTS-DBS-GD1',
202
+ addECToUserMsg: true,
203
+ message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
204
+ userMessage: this.defaultErrorUserMsg,
205
+ error
206
+ });
207
+ }
175
208
  });
176
209
 
177
210
  if (data && typeof data._id === 'object') {
@@ -182,7 +215,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
182
215
  }
183
216
 
184
217
  /**
185
- * get data by dependency data id, throws error if not found
218
+ * get data by dependency data id,
219
+ * !!!: throws error if not found (errorCode on not found: NTS-DBS-GLD2)
220
+ *
186
221
  * @param dependencyId id
187
222
  * @returns dataList
188
223
  */
@@ -198,16 +233,32 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
198
233
  }
199
234
 
200
235
  let dataList: T[] = await this.dataModel.find({ [this.depDataName]: dependencyId })
201
- .then(res => res ?? [])
202
- .catch(error => {
203
- throw new Dynamo_Error({
204
- status: 417,
205
- errorCode: 'NTS-DBS-GLD1',
206
- addECToUserMsg: true,
207
- message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
208
- userMessage: this.defaultErrorUserMsg,
209
- error
210
- });
236
+ .then(res => {
237
+ if (res) {
238
+ return res as T[];
239
+ } else {
240
+ /* return []; */
241
+ throw new Dynamo_Error({
242
+ status: 417,
243
+ errorCode: 'NTS-DBS-GLD2',
244
+ addECToUserMsg: true,
245
+ message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful: no data found by id: ${dependencyId} (NTS DB)`,
246
+ userMessage: this.defaultErrorUserMsg
247
+ });
248
+ }
249
+ }).catch(error => {
250
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
251
+ throw error;
252
+ } else {
253
+ throw new Dynamo_Error({
254
+ status: 417,
255
+ errorCode: 'NTS-DBS-GLD1',
256
+ addECToUserMsg: true,
257
+ message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
258
+ userMessage: this.defaultErrorUserMsg,
259
+ error
260
+ });
261
+ }
211
262
  });
212
263
 
213
264
  if (0 < dataList.length) {
@@ -222,7 +273,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
222
273
  }
223
274
 
224
275
  /**
225
- * get multiple data objects by a list of DependencyIDs, throws error if not found
276
+ * get multiple data objects by a list of DependencyIDs,
277
+ * !!!: throws error if not found (errorCode on not found: NTS-DBS-GLDS2)
278
+ *
226
279
  * @param ids ids
227
280
  * @returns dataList
228
281
  */
@@ -238,16 +291,32 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
238
291
  }
239
292
 
240
293
  let dataList: T[] = await this.dataModel.find({ [this.depDataName]: { $in: ids }})
241
- .then(res => res ?? [])
242
- .catch(error => {
243
- throw new Dynamo_Error({
244
- status: 417,
245
- errorCode: 'NTS-DBS-GLDS1',
246
- addECToUserMsg: true,
247
- message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (NTS DB)`,
248
- userMessage: this.defaultErrorUserMsg,
249
- error
250
- });
294
+ .then(res => {
295
+ if (res) {
296
+ return res as T[];
297
+ } else {
298
+ /* return []; */
299
+ throw new Dynamo_Error({
300
+ status: 417,
301
+ errorCode: 'NTS-DBS-GLDS2',
302
+ addECToUserMsg: true,
303
+ message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful: no data found by ids: ${ids} (NTS DB)`,
304
+ userMessage: this.defaultErrorUserMsg
305
+ });
306
+ }
307
+ }).catch(error => {
308
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
309
+ throw error;
310
+ } else {
311
+ throw new Dynamo_Error({
312
+ status: 417,
313
+ errorCode: 'NTS-DBS-GLDS1',
314
+ addECToUserMsg: true,
315
+ message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (NTS DB)`,
316
+ userMessage: this.defaultErrorUserMsg,
317
+ error
318
+ });
319
+ }
251
320
  });
252
321
 
253
322
  if (0 < dataList.length) {
@@ -264,6 +333,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
264
333
  /**
265
334
  * returns search result for searchBy object params
266
335
  * can use lists or xRange values for searchBy obj properties
336
+ *
267
337
  * @param searchBy filter
268
338
  * @param narrowByDependencyIds id
269
339
  * @returns dataList
@@ -357,21 +427,39 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
357
427
  }
358
428
 
359
429
  /**
360
- * returns all data from database, throws error if not found
430
+ * returns all data from database,
431
+ * !!!: throws error if not found (errorCode on not found: NTS-DBS-GA1)
432
+ *
361
433
  * @returns dataList
362
434
  */
363
435
  async getAll(): Promise<T[]> {
364
436
  let dataList: T[] = await this.dataModel.find({})
365
- .then(res => res ?? [])
366
- .catch(error => {
367
- throw new Dynamo_Error({
368
- status: 417,
369
- errorCode: 'NTS-DBS-GA0',
370
- addECToUserMsg: true,
371
- message: `get all ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
372
- userMessage: this.defaultErrorUserMsg,
373
- error
374
- });
437
+ .then(res => {
438
+ if (res) {
439
+ return res as T[];
440
+ } else {
441
+ /* return null; */
442
+ throw new Dynamo_Error({
443
+ status: 417,
444
+ errorCode: 'NTS-DBS-GA1',
445
+ addECToUserMsg: true,
446
+ message: `get all ${this.dataParams.dbName} was unsuccessful: no data found (NTS DB)`,
447
+ userMessage: this.defaultErrorUserMsg
448
+ });
449
+ }
450
+ }).catch(error => {
451
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
452
+ throw error;
453
+ } else {
454
+ throw new Dynamo_Error({
455
+ status: 417,
456
+ errorCode: 'NTS-DBS-GA0',
457
+ addECToUserMsg: true,
458
+ message: `get all ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
459
+ userMessage: this.defaultErrorUserMsg,
460
+ error
461
+ });
462
+ }
375
463
  });
376
464
 
377
465
  if (0 < dataList.length && typeof dataList[0]._id === 'object') {
@@ -415,8 +503,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
415
503
  });
416
504
  }
417
505
 
418
- await this.dataModel.deleteMany({ [this.depDataName]: dependencyId })
419
- .catch(error => {
506
+ await this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
420
507
  throw new Dynamo_Error({
421
508
  status: 417,
422
509
  errorCode: 'NTS-DBS-DDD1',
@@ -434,7 +521,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
434
521
  // DIRECT Basic MONGOOSE FUNCTIONS (with error handlings)
435
522
 
436
523
  /**
437
- * Find the data first by any of its parameters, throws error if not found
524
+ * Find the data first by any of its parameters,
525
+ * !!!: throws error if not found (errorCode on not found: NTS-DBS-FO1)
526
+ *
438
527
  * @param filter if you can, use unique parameters for find!
439
528
  *
440
529
  * @example
@@ -460,19 +549,30 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
460
549
  async findOne(filter: any): Promise<T> {
461
550
  let data: T = await this.dataModel.findOne(filter).then(res => {
462
551
  if (res) {
463
- return res.toObject() as T;
552
+ return res as T;
464
553
  } else {
465
- return null;
554
+ /* return null; */
555
+ throw new Dynamo_Error({
556
+ status: 417,
557
+ errorCode: 'NTS-DBS-FO1',
558
+ addECToUserMsg: true,
559
+ message: `findOne ${this.dataParams.dbName} was unsuccessful, no data found (NTS DB) fliter: ${filter}`,
560
+ userMessage: this.defaultErrorUserMsg
561
+ });
466
562
  }
467
563
  }).catch(error => {
468
- throw new Dynamo_Error({
469
- status: 417,
470
- errorCode: 'NTS-DBS-FO0',
471
- addECToUserMsg: true,
472
- message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
473
- userMessage: this.defaultErrorUserMsg,
474
- error
475
- });
564
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
565
+ throw error;
566
+ } else {
567
+ throw new Dynamo_Error({
568
+ status: 417,
569
+ errorCode: 'NTS-DBS-FO0',
570
+ addECToUserMsg: true,
571
+ message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB) fliter: ${filter}`,
572
+ userMessage: this.defaultErrorUserMsg,
573
+ error
574
+ });
575
+ }
476
576
  });
477
577
 
478
578
  if (data && typeof data._id === 'object') {
@@ -484,7 +584,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
484
584
 
485
585
  /**
486
586
  * #MONGOOSE FUNCTION
487
- * Find the data first by any of its parameters, throws error if not found
587
+ * Find the data first by any of its parameters,
588
+ * !!!: throws error if not found (errorCode on not found: NTS-DBS-F1)
589
+ *
488
590
  * @param filter if you can, use unique parameters for find!
489
591
  *
490
592
  * @example
@@ -509,16 +611,32 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
509
611
  */
510
612
  async find(filter: any): Promise<T[]> {
511
613
  let dataList: T[] = await this.dataModel.find(filter)
512
- .then(res => res ?? [])
513
- .catch(error => {
514
- throw new Dynamo_Error({
515
- status: 417,
516
- errorCode: 'NTS-DBS-F0',
517
- addECToUserMsg: true,
518
- message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
519
- userMessage: this.defaultErrorUserMsg,
520
- error
521
- });
614
+ .then(res => {
615
+ if (res) {
616
+ return res as T[];
617
+ } else {
618
+ /* return null; */
619
+ throw new Dynamo_Error({
620
+ status: 417,
621
+ errorCode: 'NTS-DBS-F1',
622
+ addECToUserMsg: true,
623
+ message: `find ${this.dataParams.dbName} was unsuccessful, no data found (NTS DB) fliter: ${filter}`,
624
+ userMessage: this.defaultErrorUserMsg
625
+ });
626
+ }
627
+ }).catch(error => {
628
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
629
+ throw error;
630
+ } else {
631
+ throw new Dynamo_Error({
632
+ status: 417,
633
+ errorCode: 'NTS-DBS-F0',
634
+ addECToUserMsg: true,
635
+ message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
636
+ userMessage: this.defaultErrorUserMsg,
637
+ error
638
+ });
639
+ }
522
640
  });
523
641
 
524
642
  if (0 < dataList.length) {
@@ -534,7 +652,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
534
652
 
535
653
  /**
536
654
  * #MONGOOSE FUNCTION
537
- * Find the data first by any of its parameters, throws error if not found
655
+ * Find the data first by any of its parameters
656
+ *
538
657
  * @param filter if you can, use unique parameters for find!
539
658
  *
540
659
  * @example
@@ -595,6 +714,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
595
714
  /**
596
715
  * #MONGOOSE FUNCTION
597
716
  * Find data by _id and update
717
+ * !!!: throws error if not found (errorCode on not found: )
718
+ *
598
719
  * @param id id
599
720
  * @param update update
600
721
  * @returns data
@@ -611,19 +732,23 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
611
732
  status: 204,
612
733
  errorCode: 'NTS-DBS-FIU1',
613
734
  addECToUserMsg: true,
614
- message: `${this.dataParams.dbName} not found! (NTS DB)`,
735
+ message: `${this.dataParams.dbName} not found! (by id: ${id}) (NTS DB)`,
615
736
  userMessage: this.defaultErrorUserMsg
616
737
  });
617
738
  }
618
739
  }).catch(error => {
619
- throw new Dynamo_Error({
620
- status: 417,
621
- errorCode: 'NTS-DBS-FIU0',
622
- addECToUserMsg: true,
623
- message: `findByIdAndUpdate ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
624
- userMessage: this.defaultErrorUserMsg,
625
- error
626
- });
740
+ if (error?.flag == 'DYNAMO ERROR OBJECT') {
741
+ throw error;
742
+ } else {
743
+ throw new Dynamo_Error({
744
+ status: 417,
745
+ errorCode: 'NTS-DBS-FIU0',
746
+ addECToUserMsg: true,
747
+ message: `findByIdAndUpdate ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
748
+ userMessage: this.defaultErrorUserMsg,
749
+ error
750
+ });
751
+ }
627
752
  });
628
753
 
629
754
  if (typeof newData._id === 'object') {
@@ -635,7 +760,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
635
760
 
636
761
  /**
637
762
  * #MONGOOSE FUNCTION
638
- * Find the data first by any of its parameters, throws error if not found
763
+ * Find the data first by any of its parameters
764
+ *
639
765
  * @param filter This uses the basic Mongoose updateOne.
640
766
  * If you can, use unique parameters for find!
641
767
  * @example
@@ -704,6 +830,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
704
830
  /**
705
831
  * #MONGOOSE FUNCTION
706
832
  * update one parameter by a specific
833
+ *
707
834
  * @param filter This uses the basic Mongoose updateMany.
708
835
  * @example
709
836
  * // by email: