@futdevpro/nts-dynamo 1.6.18 → 1.6.19

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.
@@ -35,10 +35,19 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
35
35
  public dataParams: Dynamo_DataParams
36
36
  ){
37
37
  try {
38
- /* this.serviceName = this.constructor?.name; */
38
+ this.serviceName = this.constructor?.name;
39
39
  this.lookForDependencyDataSettings();
40
40
  } catch (error) {
41
- Dynamo_Log.error(`\nDynamoNTS_DBService ERROR, The dbService construction failed for ${dataParams.dataName}. ${this.serviceName}`, new Error());
41
+ Dynamo_Log.error(
42
+ `\nDynamoNTS_DBService ERROR, The dbService construction failed for ${dataParams.dataName}. ${this.serviceName}`,
43
+ new Error()
44
+ );
45
+ /* error = new Dynamo_Error({
46
+ message: `\nDynamoNTS_DBService ERROR, The construction failed for ${dataParams.dataName}. ${this.serviceName}`,
47
+ error
48
+ });
49
+
50
+ throw error; */
42
51
  }
43
52
  }
44
53
 
@@ -59,12 +68,13 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
59
68
  return res?.toObject() as T;
60
69
  } else {
61
70
  throw new Dynamo_Error({
71
+ ...this.getDefaultErrorSettings(
72
+ 'createData',
73
+ new Error(`createData failed, save ${this.dataParams.dbName} result not found! (NTS DB)`)
74
+ ),
75
+
62
76
  status: 204,
63
77
  errorCode: 'NTS-DBS-CD1',
64
- addECToUserMsg: true,
65
- message: `createData failed, save ${this.dataParams.dbName} result not found! (NTS DB)`,
66
- userMessage: this.defaultErrorUserMsg,
67
- issuerService: this.serviceName,
68
78
  issuer,
69
79
  });
70
80
  }
@@ -73,14 +83,12 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
73
83
  throw error;
74
84
  } else {
75
85
  throw new Dynamo_Error({
86
+ ...this.getDefaultErrorSettings('createData', error),
87
+
76
88
  status: 422,
77
89
  errorCode: 'NTS-DBS-CD0',
78
- addECToUserMsg: true,
79
90
  message: `createData failed, Create new ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
80
- userMessage: this.defaultErrorUserMsg,
81
- issuerService: this.serviceName,
82
91
  issuer,
83
- error
84
92
  });
85
93
  }
86
94
  });
@@ -109,25 +117,23 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
109
117
  return res?.toObject() as T;
110
118
  } else {
111
119
  throw new Dynamo_Error({
120
+ ...this.getDefaultErrorSettings(
121
+ 'modifyData',
122
+ new Error(`modifyData failed, modify ${this.dataParams.dbName} result not found! (NTS DB)`)
123
+ ),
124
+
112
125
  status: 204,
113
126
  errorCode: 'NTS-DBS-FU1',
114
- addECToUserMsg: true,
115
- message: `modifyData failed, modify ${this.dataParams.dbName} result not found! (NTS DB)`,
116
- userMessage: this.defaultErrorUserMsg,
117
- issuerService: this.serviceName,
118
127
  issuer,
119
128
  });
120
129
  }
121
130
  }).catch(error => {
122
131
  throw new Dynamo_Error({
123
- status: 417,
132
+ ...this.getDefaultErrorSettings('modifyData', error),
133
+
124
134
  errorCode: 'NTS-DBS-FU0',
125
- addECToUserMsg: true,
126
135
  message: `modifyData ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
127
- userMessage: this.defaultErrorUserMsg,
128
- issuerService: this.serviceName,
129
136
  issuer,
130
- error
131
137
  });
132
138
  });
133
139
 
@@ -151,13 +157,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
151
157
  return res?.toObject() as T ?? null;
152
158
  }).catch(error => {
153
159
  throw new Dynamo_Error({
154
- status: 417,
160
+ ...this.getDefaultErrorSettings('getDataById', error),
161
+
155
162
  errorCode: 'NTS-DBS-GI0',
156
- addECToUserMsg: true,
157
163
  message: `get ${this.dataParams.dbName} by ID was unsuccessful (NTS DB)`,
158
- userMessage: this.defaultErrorUserMsg,
159
- issuerService: this.serviceName,
160
- error
161
164
  });
162
165
  });
163
166
 
@@ -178,12 +181,13 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
178
181
  async getDataByDependencyId(dependencyId: string): Promise<T> {
179
182
  if (!this.depDataName) {
180
183
  throw new Dynamo_Error({
184
+ ...this.getDefaultErrorSettings(
185
+ 'getDataByDependencyId',
186
+ new Error(`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`)
187
+ ),
188
+
181
189
  status: 501,
182
190
  errorCode: 'NTS-DBS-GD0',
183
- addECToUserMsg: true,
184
- message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
185
- userMessage: this.defaultErrorUserMsg,
186
- issuerService: this.serviceName,
187
191
  });
188
192
  }
189
193
 
@@ -191,13 +195,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
191
195
  return res?.toObject() as T ?? null;
192
196
  }).catch(error => {
193
197
  throw new Dynamo_Error({
194
- status: 417,
198
+ ...this.getDefaultErrorSettings('getDataByDependencyId', error),
199
+
195
200
  errorCode: 'NTS-DBS-GD1',
196
- addECToUserMsg: true,
197
201
  message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
198
- userMessage: this.defaultErrorUserMsg,
199
- issuerService: this.serviceName,
200
- error
201
202
  });
202
203
  });
203
204
 
@@ -218,12 +219,13 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
218
219
  async getDataListByDependencyId(dependencyId: string): Promise<T[]> {
219
220
  if (!this.depDataName) {
220
221
  throw new Dynamo_Error({
222
+ ...this.getDefaultErrorSettings(
223
+ 'getDataListByDependencyId',
224
+ new Error(`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`)
225
+ ),
226
+
221
227
  status: 501,
222
228
  errorCode: 'NTS-DBS-GLD0',
223
- addECToUserMsg: true,
224
- message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
225
- userMessage: this.defaultErrorUserMsg,
226
- issuerService: this.serviceName,
227
229
  });
228
230
  }
229
231
 
@@ -231,13 +233,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
231
233
  return res as T[] ?? [];
232
234
  }).catch(error => {
233
235
  throw new Dynamo_Error({
234
- status: 417,
236
+ ...this.getDefaultErrorSettings('getDataListByDependencyId', error),
237
+
235
238
  errorCode: 'NTS-DBS-GLD1',
236
- addECToUserMsg: true,
237
239
  message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
238
- userMessage: this.defaultErrorUserMsg,
239
- issuerService: this.serviceName,
240
- error
241
240
  });
242
241
  });
243
242
 
@@ -262,12 +261,13 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
262
261
  async getDataListByDependencyIds(ids: string[]): Promise<T[]> {
263
262
  if (!this.depDataName) {
264
263
  throw new Dynamo_Error({
264
+ ...this.getDefaultErrorSettings(
265
+ 'getDataListByDependencyIds',
266
+ new Error(`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`)
267
+ ),
268
+
265
269
  status: 501,
266
270
  errorCode: 'NTS-DBS-GLDS0',
267
- addECToUserMsg: true,
268
- message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
269
- userMessage: this.defaultErrorUserMsg,
270
- issuerService: this.serviceName,
271
271
  });
272
272
  }
273
273
 
@@ -275,13 +275,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
275
275
  return res as T[] ?? [];
276
276
  }).catch(error => {
277
277
  throw new Dynamo_Error({
278
- status: 417,
278
+ ...this.getDefaultErrorSettings('getDataListByDependencyIds', error),
279
+
279
280
  errorCode: 'NTS-DBS-GLDS1',
280
- addECToUserMsg: true,
281
281
  message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (NTS DB)`,
282
- userMessage: this.defaultErrorUserMsg,
283
- issuerService: this.serviceName,
284
- error
285
282
  });
286
283
  });
287
284
 
@@ -308,13 +305,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
308
305
  return res as T[] ?? [];
309
306
  }).catch(error => {
310
307
  throw new Dynamo_Error({
311
- status: 417,
308
+ ...this.getDefaultErrorSettings('getAll', error),
309
+
312
310
  errorCode: 'NTS-DBS-GA0',
313
- addECToUserMsg: true,
314
311
  message: `get all ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
315
- userMessage: this.defaultErrorUserMsg,
316
- issuerService: this.serviceName,
317
- error
318
312
  });
319
313
  });
320
314
 
@@ -334,13 +328,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
334
328
  async deleteDataById(id: string): Promise<void> {
335
329
  await this.dataModel.findByIdAndDelete(id).catch(error => {
336
330
  throw new Dynamo_Error({
337
- status: 417,
331
+ ...this.getDefaultErrorSettings('deleteDataById', error),
332
+
338
333
  errorCode: 'NTS-DBS-DD0',
339
- addECToUserMsg: true,
340
334
  message: `delete ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
341
- userMessage: this.defaultErrorUserMsg,
342
- issuerService: this.serviceName,
343
- error
344
335
  });
345
336
  });
346
337
  }
@@ -352,24 +343,22 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
352
343
  async deleteDataByDependencyId(dependencyId: string): Promise<void> {
353
344
  if (!this.depDataName) {
354
345
  throw new Dynamo_Error({
346
+ ...this.getDefaultErrorSettings(
347
+ 'deleteDataByDependencyId',
348
+ new Error(`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`)
349
+ ),
350
+
355
351
  status: 501,
356
352
  errorCode: 'NTS-DBS-DDD0',
357
- addECToUserMsg: true,
358
- message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
359
- userMessage: this.defaultErrorUserMsg,
360
- issuerService: this.serviceName,
361
353
  });
362
354
  }
363
355
 
364
356
  await this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
365
357
  throw new Dynamo_Error({
366
- status: 417,
358
+ ...this.getDefaultErrorSettings('deleteDataByDependencyId', error),
359
+
367
360
  errorCode: 'NTS-DBS-DDD1',
368
- addECToUserMsg: true,
369
361
  message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
370
- userMessage: this.defaultErrorUserMsg,
371
- issuerService: this.serviceName,
372
- error
373
362
  });
374
363
  });
375
364
  }
@@ -388,12 +377,13 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
388
377
  if (0 < narrowByDependencyIds.length) {
389
378
  if (!this.depDataName) {
390
379
  throw new Dynamo_Error({
380
+ ...this.getDefaultErrorSettings(
381
+ 'searchData',
382
+ new Error(`dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`)
383
+ ),
384
+
391
385
  status: 501,
392
386
  errorCode: 'NTS-DBS-SD0',
393
- addECToUserMsg: true,
394
- message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
395
- userMessage: this.defaultErrorUserMsg,
396
- issuerService: this.serviceName,
397
387
  });
398
388
  }
399
389
 
@@ -451,13 +441,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
451
441
  .then(res => res ?? [])
452
442
  .catch(error => {
453
443
  throw new Dynamo_Error({
454
- status: 417,
444
+ ...this.getDefaultErrorSettings('searchData', error),
445
+
455
446
  errorCode: 'NTS-DBS-SD1',
456
- addECToUserMsg: true,
457
447
  message: `search ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
458
- userMessage: this.defaultErrorUserMsg,
459
- issuerService: this.serviceName,
460
- error
461
448
  });
462
449
  });
463
450
 
@@ -508,13 +495,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
508
495
  return res as T ?? null;
509
496
  }).catch(error => {
510
497
  throw new Dynamo_Error({
511
- status: 417,
498
+ ...this.getDefaultErrorSettings('findOne', error),
499
+
512
500
  errorCode: 'NTS-DBS-FO0',
513
- addECToUserMsg: true,
514
501
  message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB) fliter: ${filterBy}`,
515
- userMessage: this.defaultErrorUserMsg,
516
- issuerService: this.serviceName,
517
- error
518
502
  });
519
503
  });
520
504
 
@@ -558,13 +542,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
558
542
  return res as T[] ?? [];
559
543
  }).catch(error => {
560
544
  throw new Dynamo_Error({
561
- status: 417,
545
+ ...this.getDefaultErrorSettings('find', error),
546
+
562
547
  errorCode: 'NTS-DBS-F0',
563
- addECToUserMsg: true,
564
548
  message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
565
- userMessage: this.defaultErrorUserMsg,
566
- issuerService: this.serviceName,
567
- error
568
549
  });
569
550
  });
570
551
 
@@ -620,13 +601,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
620
601
  .then(res => res ?? [])
621
602
  .catch(error => {
622
603
  throw new Dynamo_Error({
623
- status: 417,
604
+ ...this.getDefaultErrorSettings('findWithPaging', error),
605
+
624
606
  errorCode: 'NTS-DBS-WP0',
625
- addECToUserMsg: true,
626
607
  message: `findWithPaging ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
627
- userMessage: this.defaultErrorUserMsg,
628
- issuerService: this.serviceName,
629
- error
630
608
  });
631
609
  });
632
610
 
@@ -658,14 +636,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
658
636
  return res?.toObject() as T ?? null;
659
637
  }).catch(error => {
660
638
  throw new Dynamo_Error({
661
- status: 417,
639
+ ...this.getDefaultErrorSettings('findByIdAndUpdate', error),
640
+
662
641
  errorCode: 'NTS-DBS-FIU0',
663
- addECToUserMsg: true,
664
642
  message: `findByIdAndUpdate ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
665
- userMessage: this.defaultErrorUserMsg,
666
- issuerService: this.serviceName,
667
643
  issuer,
668
- error
669
644
  });
670
645
  });
671
646
 
@@ -734,14 +709,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
734
709
 
735
710
  await this.dataModel.updateOne(filterBy, update).catch(error => {
736
711
  throw new Dynamo_Error({
737
- status: 417,
712
+ ...this.getDefaultErrorSettings('updateOne', error),
713
+
738
714
  errorCode: 'NTS-DBS-UO0',
739
- addECToUserMsg: true,
740
715
  message: `updateOne ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
741
- userMessage: this.defaultErrorUserMsg,
742
- issuerService: this.serviceName,
743
716
  issuer,
744
- error
745
717
  });
746
718
  });
747
719
  }
@@ -803,14 +775,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
803
775
 
804
776
  await this.dataModel.updateMany(filterBy, update).catch(error => {
805
777
  throw new Dynamo_Error({
806
- status: 417,
778
+ ...this.getDefaultErrorSettings('updateMany', error),
779
+
807
780
  errorCode: 'NTS-DBS-UM0',
808
- addECToUserMsg: true,
809
781
  message: `updateMany ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
810
- userMessage: this.defaultErrorUserMsg,
811
- issuerService: this.serviceName,
812
782
  issuer,
813
- error
814
783
  });
815
784
  });
816
785
  }
@@ -880,16 +849,22 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
880
849
 
881
850
  private getBEType(type: string): String | Number | Boolean | Object | Function | Array<any> | Date {
882
851
  switch (type) {
852
+
883
853
  case 'string':
884
854
  return String;
855
+
885
856
  case 'number':
886
857
  return Number;
858
+
887
859
  case 'boolean':
888
860
  return Boolean;
861
+
889
862
  case 'Date':
890
863
  return Date;
864
+
891
865
  case 'object':
892
866
  return Object;
867
+
893
868
  default:
894
869
  if (type.includes('[]')) {
895
870
  return Array;
@@ -927,4 +902,15 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
927
902
  this.depDataName = dependencyParam.key;
928
903
  }
929
904
  }
905
+
906
+ private getDefaultErrorSettings(fnName: string, error: Dynamo_Error | Error) {
907
+ return {
908
+ status: 417,
909
+ message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS-DB)`,
910
+ addECToUserMsg: true,
911
+ userMessage: this.defaultErrorUserMsg,
912
+ issuerService: this.serviceName,
913
+ error
914
+ };
915
+ }
930
916
  }
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- import { Dynamo_Metadata, Dynamo_DataParams, Dynamo_Log } from '@futdevpro/fsm-dynamo';
3
+ import { Dynamo_Metadata, Dynamo_DataParams, Dynamo_Log, Dynamo_Error } from '@futdevpro/fsm-dynamo';
4
4
  import { DynamoNTS_AppParams } from '../../_models/control-models/app-params.control-model';
5
5
 
6
6
  import { DynamoNTS_GlobalServiceSettings } from '../../_models/interfaces/global-service-settings.interface';
@@ -38,7 +38,7 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
38
38
  /**
39
39
  * You need to setup global Services through this function
40
40
  */
41
- static setServices(set: DynamoNTS_GlobalServiceSettings): void {
41
+ static async setServices(set: DynamoNTS_GlobalServiceSettings): Promise<void> {
42
42
  this.getInstance();
43
43
 
44
44
  try {
@@ -47,14 +47,24 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
47
47
  try {
48
48
  this.instance.dbServiceCollection[dbModel.dataName] = new DynamoNTS_DBService(dbModel);
49
49
  } catch (error) {
50
- Dynamo_Log.error(`\nFailed to create DynamoBEDBService (${dbModel.dataName}).\n`, dbModel, `\n`, error);
50
+ error = new Dynamo_Error({
51
+ message: `Failed to create DynamoNTS_DBService (${dbModel.dataName}).\n` + dbModel,
52
+ issuerService: 'DynamoNTS_GlobalService',
53
+ error: error
54
+ });
55
+ throw error;
51
56
  }
52
57
  });
53
58
 
54
59
  this.instance.authService = set.authService;
55
60
  this.instance.emailServiceCollection = set.emailServiceCollection;
56
61
  } catch (error) {
57
- Dynamo_Log.error('\nsetServices failed on DynamoNTS_GlobalService.\n', error);
62
+ Dynamo_Log.error(`Failed to create DynamoNTS_GlobalService.`, error);
63
+ /* error = new Dynamo_Error({
64
+ message: `Failed to create DynamoNTS_GlobalService.`,
65
+ error: error
66
+ });
67
+ throw error; */
58
68
  }
59
69
  }
60
70
 
@@ -1,9 +1,19 @@
1
1
 
2
+ import { delay } from '@futdevpro/fsm-dynamo';
2
3
  import { DynamoNTS_AppBase_Mock, DynamoNTS_AppFull_Mock } from '../../_constants/mocks/app-server.mock';
3
4
 
4
- describe('DynamoNTS_App', () => {
5
- describe('should create a base instance', () => {
6
- const app = new DynamoNTS_AppBase_Mock();
5
+ describe('DynamoNTS_App;', () => {
6
+ describe('a base instance;', () => {
7
+ let app: DynamoNTS_AppBase_Mock;
8
+
9
+ beforeEach(async () => {
10
+ app = new DynamoNTS_AppBase_Mock();
11
+ await app.ready();
12
+ });
13
+
14
+ afterEach(async () => {
15
+ await app.stop();
16
+ });
7
17
 
8
18
  it('should be created', () => {
9
19
  expect(app).toBeDefined();
@@ -14,8 +24,17 @@ describe('DynamoNTS_App', () => {
14
24
  });
15
25
  });
16
26
 
17
- describe('should create the full instance', () => {
18
- const app = new DynamoNTS_AppFull_Mock();
27
+ describe('a full instance;', () => {
28
+ let app: DynamoNTS_AppFull_Mock;
29
+
30
+ beforeEach(async () => {
31
+ app = new DynamoNTS_AppFull_Mock();
32
+ await app.ready();
33
+ });
34
+
35
+ afterEach(async () => {
36
+ await app.stop();
37
+ });
19
38
 
20
39
  it('should be created', () => {
21
40
  expect(app).toBeDefined();
@@ -24,6 +43,7 @@ describe('DynamoNTS_App', () => {
24
43
  it('should be started', () => {
25
44
  expect(app.started).toBeTrue();
26
45
  });
46
+
27
47
  });
28
48
  });
29
49