@futdevpro/nts-dynamo 1.5.52 → 1.5.54
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/_services/dynamo-nts-data.service.d.ts +122 -3
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +271 -41
- package/lib/_services/dynamo-nts-data.service.js.map +1 -1
- package/lib/_services/dynamo-nts-db.service.d.ts +35 -11
- package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-db.service.js +122 -56
- package/lib/_services/dynamo-nts-db.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/_services/dynamo-nts-data.service.ts +255 -40
- package/src/_services/dynamo-nts-db.service.ts +120 -62
|
@@ -112,7 +112,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
|
-
* returns data by _id,
|
|
115
|
+
* returns data by _id,
|
|
116
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GI1)
|
|
116
117
|
* @param id id
|
|
117
118
|
* @returns data
|
|
118
119
|
*/
|
|
@@ -121,7 +122,14 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
121
122
|
if (res) {
|
|
122
123
|
return res.toObject() as T;
|
|
123
124
|
} else {
|
|
124
|
-
return null;
|
|
125
|
+
/* return null; */
|
|
126
|
+
throw new Dynamo_Error({
|
|
127
|
+
status: 417,
|
|
128
|
+
errorCode: 'NTS-DBS-GI1',
|
|
129
|
+
addECToUserMsg: true,
|
|
130
|
+
message: `get ${this.dataParams.dbName} by ID was unsuccessful: data not found by id: ${id} (NTS DB)`,
|
|
131
|
+
userMessage: this.defaultErrorUserMsg
|
|
132
|
+
});
|
|
125
133
|
}
|
|
126
134
|
}).catch(error => {
|
|
127
135
|
throw new Dynamo_Error({
|
|
@@ -142,7 +150,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
142
150
|
}
|
|
143
151
|
|
|
144
152
|
/**
|
|
145
|
-
* get data by dependency data id,
|
|
153
|
+
* get data by dependency data id,
|
|
154
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GD2)
|
|
155
|
+
*
|
|
146
156
|
* @param dependencyId id
|
|
147
157
|
* @returns data
|
|
148
158
|
*/
|
|
@@ -161,7 +171,14 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
161
171
|
if (res) {
|
|
162
172
|
return res.toObject() as T;
|
|
163
173
|
} else {
|
|
164
|
-
return null;
|
|
174
|
+
/* return null; */
|
|
175
|
+
throw new Dynamo_Error({
|
|
176
|
+
status: 417,
|
|
177
|
+
errorCode: 'NTS-DBS-GD2',
|
|
178
|
+
addECToUserMsg: true,
|
|
179
|
+
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful: data not found by id: ${dependencyId} (NTS DB)`,
|
|
180
|
+
userMessage: this.defaultErrorUserMsg
|
|
181
|
+
});
|
|
165
182
|
}
|
|
166
183
|
}).catch(error => {
|
|
167
184
|
throw new Dynamo_Error({
|
|
@@ -182,7 +199,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
182
199
|
}
|
|
183
200
|
|
|
184
201
|
/**
|
|
185
|
-
* get data by dependency data id,
|
|
202
|
+
* get data by dependency data id,
|
|
203
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLD2)
|
|
204
|
+
*
|
|
186
205
|
* @param dependencyId id
|
|
187
206
|
* @returns dataList
|
|
188
207
|
*/
|
|
@@ -198,8 +217,20 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
198
217
|
}
|
|
199
218
|
|
|
200
219
|
let dataList: T[] = await this.dataModel.find({ [this.depDataName]: dependencyId })
|
|
201
|
-
.then(res =>
|
|
202
|
-
|
|
220
|
+
.then(res => {
|
|
221
|
+
if (res) {
|
|
222
|
+
return res as T[];
|
|
223
|
+
} else {
|
|
224
|
+
/* return []; */
|
|
225
|
+
throw new Dynamo_Error({
|
|
226
|
+
status: 417,
|
|
227
|
+
errorCode: 'NTS-DBS-GLD2',
|
|
228
|
+
addECToUserMsg: true,
|
|
229
|
+
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful: no data found by id: ${dependencyId} (NTS DB)`,
|
|
230
|
+
userMessage: this.defaultErrorUserMsg
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}).catch(error => {
|
|
203
234
|
throw new Dynamo_Error({
|
|
204
235
|
status: 417,
|
|
205
236
|
errorCode: 'NTS-DBS-GLD1',
|
|
@@ -222,7 +253,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
222
253
|
}
|
|
223
254
|
|
|
224
255
|
/**
|
|
225
|
-
* get multiple data objects by a list of DependencyIDs,
|
|
256
|
+
* get multiple data objects by a list of DependencyIDs,
|
|
257
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLDS2)
|
|
258
|
+
*
|
|
226
259
|
* @param ids ids
|
|
227
260
|
* @returns dataList
|
|
228
261
|
*/
|
|
@@ -238,8 +271,20 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
238
271
|
}
|
|
239
272
|
|
|
240
273
|
let dataList: T[] = await this.dataModel.find({ [this.depDataName]: { $in: ids }})
|
|
241
|
-
.then(res =>
|
|
242
|
-
|
|
274
|
+
.then(res => {
|
|
275
|
+
if (res) {
|
|
276
|
+
return res as T[];
|
|
277
|
+
} else {
|
|
278
|
+
/* return []; */
|
|
279
|
+
throw new Dynamo_Error({
|
|
280
|
+
status: 417,
|
|
281
|
+
errorCode: 'NTS-DBS-GLDS2',
|
|
282
|
+
addECToUserMsg: true,
|
|
283
|
+
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful: no data found by ids: ${ids} (NTS DB)`,
|
|
284
|
+
userMessage: this.defaultErrorUserMsg
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}).catch(error => {
|
|
243
288
|
throw new Dynamo_Error({
|
|
244
289
|
status: 417,
|
|
245
290
|
errorCode: 'NTS-DBS-GLDS1',
|
|
@@ -264,6 +309,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
264
309
|
/**
|
|
265
310
|
* returns search result for searchBy object params
|
|
266
311
|
* can use lists or xRange values for searchBy obj properties
|
|
312
|
+
*
|
|
267
313
|
* @param searchBy filter
|
|
268
314
|
* @param narrowByDependencyIds id
|
|
269
315
|
* @returns dataList
|
|
@@ -357,13 +403,27 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
357
403
|
}
|
|
358
404
|
|
|
359
405
|
/**
|
|
360
|
-
* returns all data from database,
|
|
406
|
+
* returns all data from database,
|
|
407
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GA1)
|
|
408
|
+
*
|
|
361
409
|
* @returns dataList
|
|
362
410
|
*/
|
|
363
411
|
async getAll(): Promise<T[]> {
|
|
364
412
|
let dataList: T[] = await this.dataModel.find({})
|
|
365
|
-
.then(res =>
|
|
366
|
-
|
|
413
|
+
.then(res => {
|
|
414
|
+
if (res) {
|
|
415
|
+
return res as T[];
|
|
416
|
+
} else {
|
|
417
|
+
/* return null; */
|
|
418
|
+
throw new Dynamo_Error({
|
|
419
|
+
status: 417,
|
|
420
|
+
errorCode: 'NTS-DBS-GA1',
|
|
421
|
+
addECToUserMsg: true,
|
|
422
|
+
message: `get all ${this.dataParams.dbName} was unsuccessful: no data found (NTS DB)`,
|
|
423
|
+
userMessage: this.defaultErrorUserMsg
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}).catch(error => {
|
|
367
427
|
throw new Dynamo_Error({
|
|
368
428
|
status: 417,
|
|
369
429
|
errorCode: 'NTS-DBS-GA0',
|
|
@@ -434,7 +494,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
434
494
|
// DIRECT Basic MONGOOSE FUNCTIONS (with error handlings)
|
|
435
495
|
|
|
436
496
|
/**
|
|
437
|
-
* Find the data first by any of its parameters,
|
|
497
|
+
* Find the data first by any of its parameters,
|
|
498
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-FO1)
|
|
499
|
+
*
|
|
438
500
|
* @param filter if you can, use unique parameters for find!
|
|
439
501
|
*
|
|
440
502
|
* @example
|
|
@@ -460,16 +522,23 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
460
522
|
async findOne(filter: any): Promise<T> {
|
|
461
523
|
let data: T = await this.dataModel.findOne(filter).then(res => {
|
|
462
524
|
if (res) {
|
|
463
|
-
return res
|
|
525
|
+
return res as T;
|
|
464
526
|
} else {
|
|
465
|
-
return null;
|
|
527
|
+
/* return null; */
|
|
528
|
+
throw new Dynamo_Error({
|
|
529
|
+
status: 417,
|
|
530
|
+
errorCode: 'NTS-DBS-FO1',
|
|
531
|
+
addECToUserMsg: true,
|
|
532
|
+
message: `findOne ${this.dataParams.dbName} was unsuccessful, no data found (NTS DB) fliter: ${filter}`,
|
|
533
|
+
userMessage: this.defaultErrorUserMsg
|
|
534
|
+
});
|
|
466
535
|
}
|
|
467
536
|
}).catch(error => {
|
|
468
537
|
throw new Dynamo_Error({
|
|
469
538
|
status: 417,
|
|
470
539
|
errorCode: 'NTS-DBS-FO0',
|
|
471
540
|
addECToUserMsg: true,
|
|
472
|
-
message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
541
|
+
message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB) fliter: ${filter}`,
|
|
473
542
|
userMessage: this.defaultErrorUserMsg,
|
|
474
543
|
error
|
|
475
544
|
});
|
|
@@ -483,7 +552,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
483
552
|
}
|
|
484
553
|
|
|
485
554
|
/**
|
|
486
|
-
*
|
|
555
|
+
* #MONGOOSE FUNCTION
|
|
556
|
+
* Find the data first by any of its parameters,
|
|
557
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-F1)
|
|
558
|
+
*
|
|
487
559
|
* @param filter if you can, use unique parameters for find!
|
|
488
560
|
*
|
|
489
561
|
* @example
|
|
@@ -508,8 +580,20 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
508
580
|
*/
|
|
509
581
|
async find(filter: any): Promise<T[]> {
|
|
510
582
|
let dataList: T[] = await this.dataModel.find(filter)
|
|
511
|
-
.then(res =>
|
|
512
|
-
|
|
583
|
+
.then(res => {
|
|
584
|
+
if (res) {
|
|
585
|
+
return res as T[];
|
|
586
|
+
} else {
|
|
587
|
+
/* return null; */
|
|
588
|
+
throw new Dynamo_Error({
|
|
589
|
+
status: 417,
|
|
590
|
+
errorCode: 'NTS-DBS-F1',
|
|
591
|
+
addECToUserMsg: true,
|
|
592
|
+
message: `find ${this.dataParams.dbName} was unsuccessful, no data found (NTS DB) fliter: ${filter}`,
|
|
593
|
+
userMessage: this.defaultErrorUserMsg
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
}).catch(error => {
|
|
513
597
|
throw new Dynamo_Error({
|
|
514
598
|
status: 417,
|
|
515
599
|
errorCode: 'NTS-DBS-F0',
|
|
@@ -532,7 +616,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
532
616
|
}
|
|
533
617
|
|
|
534
618
|
/**
|
|
535
|
-
*
|
|
619
|
+
* #MONGOOSE FUNCTION
|
|
620
|
+
* Find the data first by any of its parameters
|
|
621
|
+
*
|
|
536
622
|
* @param filter if you can, use unique parameters for find!
|
|
537
623
|
*
|
|
538
624
|
* @example
|
|
@@ -591,7 +677,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
591
677
|
}
|
|
592
678
|
|
|
593
679
|
/**
|
|
680
|
+
* #MONGOOSE FUNCTION
|
|
594
681
|
* Find data by _id and update
|
|
682
|
+
* !!!: throws error if not found (errorCode on not found: )
|
|
683
|
+
*
|
|
595
684
|
* @param id id
|
|
596
685
|
* @param update update
|
|
597
686
|
* @returns data
|
|
@@ -626,14 +715,14 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
626
715
|
if (typeof newData._id === 'object') {
|
|
627
716
|
newData._id = `${newData._id}`;
|
|
628
717
|
}
|
|
629
|
-
/* update._id = newData._id;
|
|
630
|
-
update.__v = newData.__v; */
|
|
631
718
|
|
|
632
719
|
return newData;
|
|
633
720
|
}
|
|
634
721
|
|
|
635
722
|
/**
|
|
636
|
-
*
|
|
723
|
+
* #MONGOOSE FUNCTION
|
|
724
|
+
* Find the data first by any of its parameters
|
|
725
|
+
*
|
|
637
726
|
* @param filter This uses the basic Mongoose updateOne.
|
|
638
727
|
* If you can, use unique parameters for find!
|
|
639
728
|
* @example
|
|
@@ -682,23 +771,12 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
682
771
|
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
683
772
|
* //
|
|
684
773
|
*/
|
|
685
|
-
async updateOne(updateBy: any, update: any, modifier: string): Promise<
|
|
774
|
+
async updateOne(updateBy: any, update: any, modifier: string): Promise<void> {
|
|
686
775
|
update.__lastModified = new Date();
|
|
687
776
|
update.__lastModifiedBy = modifier;
|
|
688
777
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
return res.toObject() as T;
|
|
692
|
-
} else {
|
|
693
|
-
throw new Dynamo_Error({
|
|
694
|
-
status: 204,
|
|
695
|
-
errorCode: 'NTS-DBS-FU1',
|
|
696
|
-
addECToUserMsg: true,
|
|
697
|
-
message: `update ${this.dataParams.dbName} result not found! (NTS DB)`,
|
|
698
|
-
userMessage: this.defaultErrorUserMsg
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
}).catch(error => {
|
|
778
|
+
await this.dataModel.updateOne(updateBy, update)
|
|
779
|
+
.catch(error => {
|
|
702
780
|
throw new Dynamo_Error({
|
|
703
781
|
status: 417,
|
|
704
782
|
errorCode: 'NTS-DBS-UO0',
|
|
@@ -708,19 +786,12 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
708
786
|
error
|
|
709
787
|
});
|
|
710
788
|
});
|
|
711
|
-
|
|
712
|
-
if (typeof newData._id === 'object') {
|
|
713
|
-
newData._id = `${newData._id}`;
|
|
714
|
-
}
|
|
715
|
-
/* update._id = newData._id;
|
|
716
|
-
update.__v = newData.__v; */
|
|
717
|
-
console.log(`Dynamo function result under testing: ${newData}`);
|
|
718
|
-
|
|
719
|
-
return newData;
|
|
720
789
|
}
|
|
721
790
|
|
|
722
791
|
/**
|
|
792
|
+
* #MONGOOSE FUNCTION
|
|
723
793
|
* update one parameter by a specific
|
|
794
|
+
*
|
|
724
795
|
* @param filter This uses the basic Mongoose updateMany.
|
|
725
796
|
* @example
|
|
726
797
|
* // by email:
|
|
@@ -768,12 +839,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
768
839
|
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
769
840
|
* //
|
|
770
841
|
*/
|
|
771
|
-
async updateMany(updateBy: any, update: any, modifier: string): Promise<
|
|
842
|
+
async updateMany(updateBy: any, update: any, modifier: string): Promise<void> {
|
|
772
843
|
update.__lastModified = new Date();
|
|
773
844
|
update.__lastModifiedBy = modifier;
|
|
774
845
|
|
|
775
|
-
|
|
776
|
-
.then(res => res ?? [])
|
|
846
|
+
await this.dataModel.updateMany(updateBy, update)
|
|
777
847
|
.catch(error => {
|
|
778
848
|
throw new Dynamo_Error({
|
|
779
849
|
status: 417,
|
|
@@ -784,18 +854,6 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
784
854
|
error
|
|
785
855
|
});
|
|
786
856
|
});
|
|
787
|
-
|
|
788
|
-
if (0 < dataList.length) {
|
|
789
|
-
dataList.forEach((data: T) => {
|
|
790
|
-
if (data && typeof data._id === 'object') {
|
|
791
|
-
data._id = `${data._id}`;
|
|
792
|
-
}
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
console.log(`Dynamo function result under testing: ${dataList}`);
|
|
797
|
-
|
|
798
|
-
return dataList;
|
|
799
857
|
}
|
|
800
858
|
|
|
801
859
|
// ----------------------------------------------------------------------------------
|