@futdevpro/nts-dynamo 1.5.51 → 1.5.52

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.
Files changed (34) hide show
  1. package/lib/_models/dynamo-nts-endpoint-params.js +3 -2
  2. package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
  3. package/lib/_services/dynamo-nts-app-extended.d.ts +87 -7
  4. package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
  5. package/lib/_services/dynamo-nts-app-extended.js +87 -7
  6. package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
  7. package/lib/_services/dynamo-nts-app.d.ts +131 -22
  8. package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
  9. package/lib/_services/dynamo-nts-app.js +104 -1
  10. package/lib/_services/dynamo-nts-app.js.map +1 -1
  11. package/lib/_services/dynamo-nts-auth.service.d.ts +78 -5
  12. package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
  13. package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
  14. package/lib/_services/dynamo-nts-data.service.d.ts +23 -1
  15. package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
  16. package/lib/_services/dynamo-nts-data.service.js +73 -53
  17. package/lib/_services/dynamo-nts-data.service.js.map +1 -1
  18. package/lib/_services/dynamo-nts-db.service.d.ts +164 -119
  19. package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
  20. package/lib/_services/dynamo-nts-db.service.js +327 -277
  21. package/lib/_services/dynamo-nts-db.service.js.map +1 -1
  22. package/lib/_services/dynamo-nts-routing-module.service.d.ts +39 -0
  23. package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
  24. package/lib/_services/dynamo-nts-routing-module.service.js +39 -0
  25. package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
  26. package/lib/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +15 -12
  28. package/src/_models/dynamo-nts-endpoint-params.ts +2 -2
  29. package/src/_services/dynamo-nts-app-extended.ts +87 -7
  30. package/src/_services/dynamo-nts-app.ts +131 -22
  31. package/src/_services/dynamo-nts-auth.service.ts +79 -5
  32. package/src/_services/dynamo-nts-data.service.ts +74 -54
  33. package/src/_services/dynamo-nts-db.service.ts +355 -281
  34. package/src/_services/dynamo-nts-routing-module.service.ts +39 -0
@@ -37,11 +37,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
37
37
  data.__lastModifiedBy = creator;
38
38
 
39
39
  const dataModel = new this.dataModel(data);
40
- let newData: T;
41
-
42
- await dataModel.save().then(res => {
40
+ let newData: T = await dataModel.save().then(res => {
43
41
  if (res) {
44
- newData = res.toObject() as T;
42
+ return res.toObject() as T;
45
43
  } else {
46
44
  throw new Dynamo_Error({
47
45
  status: 204,
@@ -81,11 +79,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
81
79
  data.__lastModifiedBy = modifier;
82
80
 
83
81
  const dataModel = new this.dataModel(data);
84
- let newData: T;
85
-
86
- await this.dataModel.findByIdAndUpdate(data._id, dataModel).then(res => {
82
+ let newData: T = await this.dataModel.findByIdAndUpdate(data._id, dataModel).then(res => {
87
83
  if (res) {
88
- newData = res.toObject() as T;
84
+ return res.toObject() as T;
89
85
  } else {
90
86
  throw new Dynamo_Error({
91
87
  status: 204,
@@ -106,6 +102,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
106
102
  });
107
103
  });
108
104
 
105
+ if (typeof newData._id === 'object') {
106
+ newData._id = `${newData._id}`;
107
+ }
108
+ data._id = newData._id;
109
109
  data.__v = newData.__v;
110
110
 
111
111
  return data;
@@ -117,13 +117,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
117
117
  * @returns data
118
118
  */
119
119
  async getDataById(id: string): Promise<T> {
120
- let data: T;
121
-
122
- await this.dataModel.findById(id).then(res => {
120
+ let data: T = await this.dataModel.findById(id).then(res => {
123
121
  if (res) {
124
- data = res.toObject() as T;
122
+ return res.toObject() as T;
125
123
  } else {
126
- data = null;
124
+ return null;
127
125
  }
128
126
  }).catch(error => {
129
127
  throw new Dynamo_Error({
@@ -149,29 +147,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
149
147
  * @returns data
150
148
  */
151
149
  async getDataByDependencyId(dependencyId: string): Promise<T> {
152
- if (this.depDataName) {
153
- let data: T;
154
- await this.dataModel.findOne({ [this.depDataName]: dependencyId }).then(res => {
155
- if (res) {
156
- data = res.toObject() as T;
157
- } else {
158
- data = null;
159
- }
160
- }).catch(error => {
161
- throw new Dynamo_Error({
162
- status: 417,
163
- errorCode: 'NTS-DBS-GD1',
164
- addECToUserMsg: true,
165
- message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
166
- userMessage: this.defaultErrorUserMsg,
167
- error
168
- });
169
- });
170
- if (data && typeof data._id === 'object') {
171
- data._id = `${data._id}`;
172
- }
173
- return data;
174
- } else {
150
+ if (!this.depDataName) {
175
151
  throw new Dynamo_Error({
176
152
  status: 501,
177
153
  errorCode: 'NTS-DBS-GD0',
@@ -180,6 +156,29 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
180
156
  userMessage: this.defaultErrorUserMsg
181
157
  });
182
158
  }
159
+
160
+ let data: T = await this.dataModel.findOne({ [this.depDataName]: dependencyId }).then(res => {
161
+ if (res) {
162
+ return res.toObject() as T;
163
+ } else {
164
+ return null;
165
+ }
166
+ }).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
+ });
175
+ });
176
+
177
+ if (data && typeof data._id === 'object') {
178
+ data._id = `${data._id}`;
179
+ }
180
+
181
+ return data;
183
182
  }
184
183
 
185
184
  /**
@@ -188,29 +187,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
188
187
  * @returns dataList
189
188
  */
190
189
  async getDataListByDependencyId(dependencyId: string): Promise<T[]> {
191
- if (this.depDataName) {
192
- let dataList = [];
193
- await this.dataModel.find({ [this.depDataName]: dependencyId }).then(res => {
194
- if (res) {
195
- dataList = res;
196
- }
197
- }).catch(error => {
198
- throw new Dynamo_Error({
199
- status: 417,
200
- errorCode: 'NTS-DBS-GLD1',
201
- addECToUserMsg: true,
202
- message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
203
- userMessage: this.defaultErrorUserMsg,
204
- error
205
- });
206
- });
207
- if (0 < dataList.length && typeof dataList[0]._id === 'object') {
208
- dataList.forEach((data: T) => {
209
- data._id = `˙${data._id}`;
210
- });
211
- }
212
- return dataList;
213
- } else {
190
+ if (!this.depDataName) {
214
191
  throw new Dynamo_Error({
215
192
  status: 501,
216
193
  errorCode: 'NTS-DBS-GLD0',
@@ -219,6 +196,29 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
219
196
  userMessage: this.defaultErrorUserMsg
220
197
  });
221
198
  }
199
+
200
+ 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
+ });
211
+ });
212
+
213
+ if (0 < dataList.length) {
214
+ dataList.forEach((data: T) => {
215
+ if (data && typeof data._id === 'object') {
216
+ data._id = `${data._id}`;
217
+ }
218
+ });
219
+ }
220
+
221
+ return dataList;
222
222
  }
223
223
 
224
224
  /**
@@ -227,24 +227,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
227
227
  * @returns dataList
228
228
  */
229
229
  async getDataListByDependencyIds(ids: string[]): Promise<T[]> {
230
- if (this.depDataName) {
231
- let dataList = [];
232
- await this.dataModel.find({ [this.depDataName]: { $in: ids }}).then(res => {
233
- if (res) {
234
- dataList = res;
235
- }
236
- }).catch(error => {
237
- throw new Dynamo_Error({
238
- status: 417,
239
- errorCode: 'NTS-DBS-GLDS1',
240
- addECToUserMsg: true,
241
- message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (NTS DB)`,
242
- userMessage: this.defaultErrorUserMsg,
243
- error
244
- });
245
- });
246
- return dataList;
247
- } else {
230
+ if (!this.depDataName) {
248
231
  throw new Dynamo_Error({
249
232
  status: 501,
250
233
  errorCode: 'NTS-DBS-GLDS0',
@@ -253,6 +236,29 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
253
236
  userMessage: this.defaultErrorUserMsg
254
237
  });
255
238
  }
239
+
240
+ 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
+ });
251
+ });
252
+
253
+ if (0 < dataList.length) {
254
+ dataList.forEach((data: T) => {
255
+ if (data && typeof data._id === 'object') {
256
+ data._id = `${data._id}`;
257
+ }
258
+ });
259
+ }
260
+
261
+ return dataList;
256
262
  }
257
263
 
258
264
  /**
@@ -265,10 +271,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
265
271
  async searchData(searchBy: object, narrowByDependencyIds?: string[]): Promise<T[]> {
266
272
  const filter = {};
267
273
 
268
- if (narrowByDependencyIds.length > 0) {
269
- if (this.depDataName) {
270
- filter[this.depDataName] = { $in: narrowByDependencyIds };
271
- } else {
274
+ if (0 < narrowByDependencyIds.length) {
275
+ if (!this.depDataName) {
272
276
  throw new Dynamo_Error({
273
277
  status: 501,
274
278
  errorCode: 'NTS-DBS-SD0',
@@ -277,22 +281,33 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
277
281
  userMessage: this.defaultErrorUserMsg
278
282
  });
279
283
  }
284
+
285
+ filter[this.depDataName] = { $in: narrowByDependencyIds };
280
286
  }
281
287
 
282
288
  await this.dataParams.modelParams.forEach((modelParam: DynamoNTS_DataPropertyParams) => {
283
- if ((searchBy[modelParam.key] !== null && searchBy[modelParam.key] !== undefined) || searchBy[modelParam.key + 'Range']) {
289
+ if (
290
+ (searchBy[modelParam.key] !== null && searchBy[modelParam.key] !== undefined) ||
291
+ searchBy[modelParam.key + 'Range']
292
+ ) {
284
293
  if (modelParam.key.includes('Range') || modelParam.type.includes('[]')) {
285
294
  // inverz search filter (for Range and Array functions)
286
295
  if (modelParam.key.includes('Range')) {
287
296
  const searchParamKeyWithoutRange = modelParam.key.split('Range')[0];
288
- if (searchBy[searchParamKeyWithoutRange] !== null && searchBy[searchParamKeyWithoutRange] !== undefined) {
297
+ if (
298
+ searchBy[searchParamKeyWithoutRange] !== null &&
299
+ searchBy[searchParamKeyWithoutRange] !== undefined
300
+ ) {
289
301
  filter[modelParam.key] = {
290
302
  from: { $lte: searchBy[searchParamKeyWithoutRange] },
291
303
  to: { $gte: searchBy[searchParamKeyWithoutRange] }
292
304
  };
293
305
  }
294
306
  } else {
295
- if (searchBy[modelParam.key] !== null && searchBy[modelParam.key] !== undefined) {
307
+ if (
308
+ searchBy[modelParam.key] !== null &&
309
+ searchBy[modelParam.key] !== undefined
310
+ ) {
296
311
  filter[modelParam.key] = { $in: searchBy[modelParam.key] };
297
312
  }
298
313
  }
@@ -317,12 +332,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
317
332
  }
318
333
  });
319
334
 
320
- let dataList = [];
321
- await this.dataModel.find(filter).then(res => {
322
- if (res) {
323
- dataList = res;
324
- }
325
- }).catch(error => {
335
+ let dataList: T[] = await this.dataModel.find(filter)
336
+ .then(res => res ?? [])
337
+ .catch(error => {
326
338
  throw new Dynamo_Error({
327
339
  status: 417,
328
340
  errorCode: 'NTS-DBS-SD1',
@@ -333,59 +345,25 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
333
345
  });
334
346
  });
335
347
 
336
- if (0 < dataList.length && typeof dataList[0]._id === 'object') {
348
+ if (0 < dataList.length) {
337
349
  dataList.forEach((data: T) => {
338
- data._id = `˙${data._id}`;
350
+ if (data && typeof data._id === 'object') {
351
+ data._id = `${data._id}`;
352
+ }
339
353
  });
340
354
  }
341
355
 
342
- return dataList as T[];
356
+ return dataList;
343
357
  }
344
358
 
345
- /**
346
- * find data by any of its parameters, throws error if not found
347
- * @param data
348
- * (always use unique parameters for find!)
349
- * etc.: by email:
350
- * @example { email: email }
351
- * or by id that is in list:
352
- * @example { userIds: { $in: this.userId } }
353
- * or by number or Date that is greater than OR less than:
354
- * @example { points: { $gte: 2, $lte: 14 } }
355
- * @returns data
356
- */
357
- /* async findData(data: T): Promise<T> {
358
- await this.dataModel.findOne(data).then(res => {
359
- if (res) {
360
- data = res.toObject() as T;
361
- } else {
362
- data = null;
363
- }
364
- }).catch(error => {
365
- throw new Dynamo_Error({
366
- status: 417,
367
- message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
368
- error
369
- });
370
- });
371
- if (data && typeof data._id === 'object') {
372
- data._id = `${data._id}`;
373
- }
374
- return data;
375
- } */
376
-
377
359
  /**
378
360
  * returns all data from database, throws error if not found
379
361
  * @returns dataList
380
362
  */
381
363
  async getAll(): Promise<T[]> {
382
- let dataList = [];
383
-
384
- await this.dataModel.find({}).then(res => {
385
- if (res) {
386
- dataList = res;
387
- }
388
- }).catch(error => {
364
+ let dataList: T[] = await this.dataModel.find({})
365
+ .then(res => res ?? [])
366
+ .catch(error => {
389
367
  throw new Dynamo_Error({
390
368
  status: 417,
391
369
  errorCode: 'NTS-DBS-GA0',
@@ -427,18 +405,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
427
405
  * @param dependencyId id
428
406
  */
429
407
  async deleteDataByDependencyId(dependencyId: string): Promise<void> {
430
- if (this.depDataName) {
431
- await this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
432
- throw new Dynamo_Error({
433
- status: 417,
434
- errorCode: 'NTS-DBS-DDD1',
435
- addECToUserMsg: true,
436
- message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
437
- userMessage: this.defaultErrorUserMsg,
438
- error
439
- });
440
- });
441
- } else {
408
+ if (!this.depDataName) {
442
409
  throw new Dynamo_Error({
443
410
  status: 501,
444
411
  errorCode: 'NTS-DBS-DDD0',
@@ -447,39 +414,55 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
447
414
  userMessage: this.defaultErrorUserMsg
448
415
  });
449
416
  }
417
+
418
+ await this.dataModel.deleteMany({ [this.depDataName]: dependencyId })
419
+ .catch(error => {
420
+ throw new Dynamo_Error({
421
+ status: 417,
422
+ errorCode: 'NTS-DBS-DDD1',
423
+ addECToUserMsg: true,
424
+ message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
425
+ userMessage: this.defaultErrorUserMsg,
426
+ error
427
+ });
428
+ });
450
429
  }
451
430
 
452
431
  // ----------------------------------------------------------------------------------
453
432
  // ----------------------------------------------------------------------------------
454
433
  // ----------------------------------------------------------------------------------
455
- // DIRECT MONGOOSE CALLS (with error handlings)
434
+ // DIRECT Basic MONGOOSE FUNCTIONS (with error handlings)
456
435
 
457
436
  /**
458
- * find the data first by any of its parameters, throws error if not found
459
- * @param filter
460
- * (always use unique parameters for find!)
461
- * etc.: by email:
462
- * @example { email: email }
463
- * or by id that is in list:
464
- * @example { userIds: { $in: this.userId } }
465
- * or by number or Date that is GREATER THAN OR LESS THAN:
466
- * @example { points: { $gt: 2, $lt: 14 } }
467
- * further tools (syntax matches with $gt):
468
- * $eq: Matches values that are EQUAL to a specified value.
469
- * $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
470
- * $lte: Matches values that are LESS THAN or EQUAL to a specified value.
471
- * $ne: Matches all values that are NOT EQUAL to a specified value.
472
- * $nin: Matches NONE of the values specified IN an array.
437
+ * Find the data first by any of its parameters, throws error if not found
438
+ * @param filter if you can, use unique parameters for find!
473
439
  *
474
- * @returns data
440
+ * @example
441
+ * // by email:
442
+ * { email: email }
443
+ * //
444
+ * @example
445
+ * // or by id that is in list:
446
+ * { userIds: { $in: this.userId } }
447
+ * //
448
+ * @example
449
+ * // or by number or Date that is Greater Than AND Less Than:
450
+ * { points: { $gt: 2, $lt: 14 } }
451
+ * // further tools (syntax matches with $gt):
452
+ * $eq: // Matches values that are EQual to a specified value.
453
+ * $gte: // Matches values that are Greater Than OR Equal to a specified value.
454
+ * $lte: // Matches values that are Less Than or Equal to a specified value.
455
+ * $ne: // Matches all values that are Not Equal to a specified value.
456
+ * $nin: // Matches None of the values specified IN an array.
457
+ * //
458
+ * @returns {T} data: T
475
459
  */
476
460
  async findOne(filter: any): Promise<T> {
477
- let data: T;
478
- await this.dataModel.findOne(filter).then(res => {
461
+ let data: T = await this.dataModel.findOne(filter).then(res => {
479
462
  if (res) {
480
- data = res.toObject() as T;
463
+ return res.toObject() as T;
481
464
  } else {
482
- data = null;
465
+ return null;
483
466
  }
484
467
  }).catch(error => {
485
468
  throw new Dynamo_Error({
@@ -491,38 +474,42 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
491
474
  error
492
475
  });
493
476
  });
477
+
494
478
  if (data && typeof data._id === 'object') {
495
479
  data._id = `${data._id}`;
496
480
  }
481
+
497
482
  return data;
498
483
  }
499
484
 
500
485
  /**
501
- * find all data by any of its parameters, throws error if not found
502
- * @param filter
503
- * etc.: by email:
504
- * @example { email: email }
505
- * or by id that is in list:
506
- * @example { userIds: { $in: this.userId } }
507
- * or by number or Date that is GREATER THAN OR LESS THAN:
508
- * @example { points: { $gt: 2, $lt: 14 } }
509
- * further tools (syntax matches with $gt):
510
- * $eq: Matches values that are EQUAL to a specified value.
511
- * $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
512
- * $lte: Matches values that are LESS THAN or EQUAL to a specified value.
513
- * $ne: Matches all values that are NOT EQUAL to a specified value.
514
- * $nin: Matches NONE of the values specified IN an array.
486
+ * Find the data first by any of its parameters, throws error if not found
487
+ * @param filter if you can, use unique parameters for find!
515
488
  *
516
- * @returns dataList
489
+ * @example
490
+ * // by email:
491
+ * { email: email }
492
+ * //
493
+ * @example
494
+ * // or by id that is in list:
495
+ * { userIds: { $in: this.userId } }
496
+ * //
497
+ * @example
498
+ * // or by number or Date that is Greater Than AND Less Than:
499
+ * { points: { $gt: 2, $lt: 14 } }
500
+ * // further tools (syntax matches with $gt):
501
+ * $eq: // Matches values that are EQual to a specified value.
502
+ * $gte: // Matches values that are Greater Than OR Equal to a specified value.
503
+ * $lte: // Matches values that are Less Than or Equal to a specified value.
504
+ * $ne: // Matches all values that are Not Equal to a specified value.
505
+ * $nin: // Matches None of the values specified IN an array.
506
+ * //
507
+ * @returns {T[]} dataList: T[]
517
508
  */
518
509
  async find(filter: any): Promise<T[]> {
519
- let dataList = [];
520
-
521
- await this.dataModel.find(filter).then(res => {
522
- if (res) {
523
- dataList = res;
524
- }
525
- }).catch(error => {
510
+ let dataList: T[] = await this.dataModel.find(filter)
511
+ .then(res => res ?? [])
512
+ .catch(error => {
526
513
  throw new Dynamo_Error({
527
514
  status: 417,
528
515
  errorCode: 'NTS-DBS-F0',
@@ -533,9 +520,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
533
520
  });
534
521
  });
535
522
 
536
- if (0 < dataList.length && typeof dataList[0]._id === 'object') {
523
+ if (0 < dataList.length) {
537
524
  dataList.forEach((data: T) => {
538
- data._id = `˙${data._id}`;
525
+ if (data && typeof data._id === 'object') {
526
+ data._id = `${data._id}`;
527
+ }
539
528
  });
540
529
  }
541
530
 
@@ -543,37 +532,43 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
543
532
  }
544
533
 
545
534
  /**
546
- * find all data by any of its parameters, throws error if not found
547
- * @param filter
548
- * etc.: by email:
549
- * @example { email: email }
550
- * or by id that is in list:
551
- * @example { userIds: { $in: this.userId } }
552
- * or by number or Date that is GREATER THAN OR LESS THAN:
553
- * @example { points: { $gt: 2, $lt: 14 } }
554
- * further tools (syntax matches with $gt):
555
- * $eq: Matches values that are EQUAL to a specified value.
556
- * $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
557
- * $lte: Matches values that are LESS THAN or EQUAL to a specified value.
558
- * $ne: Matches all values that are NOT EQUAL to a specified value.
559
- * $nin: Matches NONE of the values specified IN an array.
535
+ * Find the data first by any of its parameters, throws error if not found
536
+ * @param filter if you can, use unique parameters for find!
560
537
  *
538
+ * @example
539
+ * // by email:
540
+ * { email: email }
541
+ * //
542
+ * @example
543
+ * // or by id that is in list:
544
+ * { userIds: { $in: this.userId } }
545
+ * //
546
+ * @example
547
+ * // or by number or Date that is Greater Than AND Less Than:
548
+ * { points: { $gt: 2, $lt: 14 } }
549
+ * // further tools (syntax matches with $gt):
550
+ * $eq: // Matches values that are EQual to a specified value.
551
+ * $gte: // Matches values that are Greater Than OR Equal to a specified value.
552
+ * $lte: // Matches values that are Less Than or Equal to a specified value.
553
+ * $ne: // Matches all values that are Not Equal to a specified value.
554
+ * $nin: // Matches None of the values specified IN an array.
555
+ * //
561
556
  * @param page page
562
557
  * @param pageSize pageSize
563
- * @param sort etc. by dateTime: { dateTime: -1 }
564
- * @returns dataList
558
+ * @param sort
559
+ * @example
560
+ * // by dateTime (this uses the basic sort function):
561
+ * { dateTime: -1 }
562
+ * //
563
+ * @returns {T[]} dataList: T[]
565
564
  */
566
565
  async findWithPaging(filter: any, page: number, pageSize: number, sort?: any): Promise<T[]> {
567
- let dataList = [];
568
- await this.dataModel.find(filter)
566
+ let dataList: T[] = await this.dataModel.find(filter)
569
567
  .sort(sort)
570
568
  .skip(page * pageSize)
571
569
  .limit(pageSize)
572
- .then(res => {
573
- if (res) {
574
- dataList = res;
575
- }
576
- }).catch(error => {
570
+ .then(res => res ?? [])
571
+ .catch(error => {
577
572
  throw new Dynamo_Error({
578
573
  status: 417,
579
574
  errorCode: 'NTS-DBS-WP0',
@@ -584,9 +579,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
584
579
  });
585
580
  });
586
581
 
587
- if (0 < dataList.length && typeof dataList[0]._id === 'object') {
582
+ if (0 < dataList.length) {
588
583
  dataList.forEach((data: T) => {
589
- data._id = `˙${data._id}`;
584
+ if (data && typeof data._id === 'object') {
585
+ data._id = `${data._id}`;
586
+ }
590
587
  });
591
588
  }
592
589
 
@@ -600,13 +597,12 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
600
597
  * @returns data
601
598
  */
602
599
  async findByIdAndUpdate(id: string, update: any, modifier: string): Promise<T> {
603
- let data: T;
604
600
  update.__lastModified = new Date();
605
601
  update.__lastModifiedBy = modifier;
606
602
 
607
- await this.dataModel.findByIdAndUpdate(id, update).then(res => {
603
+ let newData: T = await this.dataModel.findByIdAndUpdate(id, update).then(res => {
608
604
  if (res) {
609
- data = res.toObject() as T;
605
+ return res.toObject() as T;
610
606
  } else {
611
607
  throw new Dynamo_Error({
612
608
  status: 204,
@@ -626,47 +622,84 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
626
622
  error
627
623
  });
628
624
  });
629
- update.__v = data.__v;
630
- return update;
625
+
626
+ if (typeof newData._id === 'object') {
627
+ newData._id = `${newData._id}`;
628
+ }
629
+ /* update._id = newData._id;
630
+ update.__v = newData.__v; */
631
+
632
+ return newData;
631
633
  }
632
634
 
633
635
  /**
634
- * update one parameter by a specific
635
- * @param updateBy
636
- * (always use unique parameters for find!)
637
- * etc.: by email:
638
- * @example { email: email }
639
- * or by id that is in list:
640
- * @example { userIds: { $in: this.userId } }
641
- * or by number or Date that is GREATER THAN OR LESS THAN:
642
- * @example { points: { $gt: 2, $lt: 14 } }
643
- * further tools (syntax matches with $gt):
644
- * $eq: Matches values that are EQUAL to a specified value.
645
- * $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
646
- * $lte: Matches values that are LESS THAN or EQUAL to a specified value.
647
- * $ne: Matches all values that are NOT EQUAL to a specified value.
648
- * $nin: Matches NONE of the values specified IN an array.
636
+ * Find the data first by any of its parameters, throws error if not found
637
+ * @param filter This uses the basic Mongoose updateOne.
638
+ * If you can, use unique parameters for find!
639
+ * @example
640
+ * // by email:
641
+ * { email: email }
642
+ * //
643
+ * @example
644
+ * // or by id that is in list:
645
+ * { userIds: { $in: this.userId } }
646
+ * //
647
+ * @example
648
+ * // or by number or Date that is Greater Than AND Less Than:
649
+ * { points: { $gt: 2, $lt: 14 } }
650
+ * // further tools (syntax matches with $gt):
651
+ * $eq: // Matches values that are EQual to a specified value.
652
+ * $gte: // Matches values that are Greater Than OR Equal to a specified value.
653
+ * $lte: // Matches values that are Less Than or Equal to a specified value.
654
+ * $ne: // Matches all values that are Not Equal to a specified value.
655
+ * $nin: // Matches None of the values specified IN an array.
656
+ * //
649
657
  *
650
- * @param update
651
- * etc.: increase a specific value:
652
- * @example { $inc: { popularity: 15 } }
653
- * or add element to a list:
654
- * @example { $push: { reactions: this.newReaction }
655
- * or all at once
656
- * @example { $inc: { popularity: this.newVote.amount }, emailVerified: true, $push: { reactions: this.newReaction } }
657
- * further tools (syntax matches with $inc):
658
- * $currentDate: Sets the value of a field to current date, either as a Date or a Timestamp.
659
- * $min: Only updates the field if the specified value is less than the existing field value.
660
- * $max: Only updates the field if the specified value is greater than the existing field value.
661
- * $mul: Multiplies the value of the field by the specified amount.
662
- * $rename: Renames a field.
663
- * $unset: Removes the specified field from a document. (set: "" to value)
658
+ * @param update this uses the basic Mongoose updateOne
659
+ * @example
660
+ * // increase a specific value (here by 15):
661
+ * { $inc: { popularity: 15 } }
662
+ * //
663
+ * @example
664
+ * // or add element to a list:
665
+ * { $push: { reactions: this.newReaction }
666
+ * // or add multiple elements to a list
667
+ * { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
668
+ * //
669
+ * @example
670
+ * // or all at once
671
+ * {
672
+ * $inc: { popularity: this.newVote.amount },
673
+ * emailVerified: true,
674
+ * $push: { reactions: this.newReaction }
675
+ * }
676
+ * // further tools (syntax matches with $inc):
677
+ * $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
678
+ * $min: // Only updates the field if the specified value is less than the existing field value.
679
+ * $max: // Only updates the field if the specified value is greater than the existing field value.
680
+ * $mul: // Multiplies the value of the field by the specified amount.
681
+ * $rename: // Renames a field.
682
+ * $unset: // Removes the specified field from a document. (set: "" to value)
683
+ * //
664
684
  */
665
- async updateOne(updateBy: any, update: any, modifier: string): Promise<void> {
685
+ async updateOne(updateBy: any, update: any, modifier: string): Promise<T> {
666
686
  update.__lastModified = new Date();
667
687
  update.__lastModifiedBy = modifier;
668
- await this.dataModel.updateOne(updateBy, update).catch(error => {
669
- throw new Dynamo_Error({
688
+
689
+ let newData: T = await this.dataModel.updateOne(updateBy, update).then(res => {
690
+ if (res) {
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 => {
702
+ throw new Dynamo_Error({
670
703
  status: 417,
671
704
  errorCode: 'NTS-DBS-UO0',
672
705
  addECToUserMsg: true,
@@ -675,44 +708,73 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
675
708
  error
676
709
  });
677
710
  });
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;
678
720
  }
679
721
 
680
722
  /**
681
723
  * update one parameter by a specific
682
- * @param updateBy
683
- * etc.: by email:
684
- * @example { email: email }
685
- * or by id that is in list:
686
- * @example { userIds: { $in: this.userId } }
687
- * or by number or Date that is GREATER THAN OR LESS THAN:
688
- * @example { points: { $gt: 2, $lt: 14 } }
689
- * further tools (syntax matches with $gt):
690
- * $eq: Matches values that are EQUAL to a specified value.
691
- * $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
692
- * $lte: Matches values that are LESS THAN or EQUAL to a specified value.
693
- * $ne: Matches all values that are NOT EQUAL to a specified value.
694
- * $nin: Matches NONE of the values specified IN an array.
724
+ * @param filter This uses the basic Mongoose updateMany.
725
+ * @example
726
+ * // by email:
727
+ * { email: email }
728
+ * //
729
+ * @example
730
+ * // or by id that is in list:
731
+ * { userIds: { $in: this.userId } }
732
+ * //
733
+ * @example
734
+ * // or by number or Date that is Greater Than AND Less Than:
735
+ * { points: { $gt: 2, $lt: 14 } }
736
+ * // further tools (syntax matches with $gt):
737
+ * $eq: // Matches values that are EQual to a specified value.
738
+ * $gte: // Matches values that are Greater Than OR Equal to a specified value.
739
+ * $lte: // Matches values that are Less Than or Equal to a specified value.
740
+ * $ne: // Matches all values that are Not Equal to a specified value.
741
+ * $nin: // Matches None of the values specified IN an array.
742
+ * //
695
743
  *
696
- * @param update
697
- * etc.: increase a specific value:
698
- * @example { $inc: { popularity: 15 } }
699
- * or add element to a list:
700
- * @example { $push: { reactions: this.newReaction }
701
- * or all at once
702
- * @example { $inc: { popularity: this.newVote.amount }, emailVerified: true, $push: { reactions: this.newReaction } }
703
- * further tools (syntax matches with $inc):
704
- * $currentDate: Sets the value of a field to current date, either as a Date or a Timestamp.
705
- * $min: Only updates the field if the specified value is less than the existing field value.
706
- * $max: Only updates the field if the specified value is greater than the existing field value.
707
- * $mul: Multiplies the value of the field by the specified amount.
708
- * $rename: Renames a field.
709
- * $unset: Removes the specified field from a document. (set: "" to value)
744
+ * @param update this uses the basic Mongoose updateOne
745
+ * @example
746
+ * // increase a specific value (here by 15):
747
+ * { $inc: { popularity: 15 } }
748
+ * //
749
+ * @example
750
+ * // or add element to a list:
751
+ * { $push: { reactions: this.newReaction }
752
+ * // or add multiple elements to a list
753
+ * { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
754
+ * //
755
+ * @example
756
+ * // or all at once
757
+ * {
758
+ * $inc: { popularity: this.newVote.amount },
759
+ * emailVerified: true,
760
+ * $push: { reactions: this.newReaction }
761
+ * }
762
+ * // further tools (syntax matches with $inc):
763
+ * $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
764
+ * $min: // Only updates the field if the specified value is less than the existing field value.
765
+ * $max: // Only updates the field if the specified value is greater than the existing field value.
766
+ * $mul: // Multiplies the value of the field by the specified amount.
767
+ * $rename: // Renames a field.
768
+ * $unset: // Removes the specified field from a document. (set: "" to value)
769
+ * //
710
770
  */
711
- async updateMany(updateBy: any, update: any, modifier: string): Promise<void> {
771
+ async updateMany(updateBy: any, update: any, modifier: string): Promise<T[]> {
712
772
  update.__lastModified = new Date();
713
773
  update.__lastModifiedBy = modifier;
714
774
 
715
- await this.dataModel.updateMany(updateBy, update).catch(error => {
775
+ let dataList: T[] = await this.dataModel.updateMany(updateBy, update)
776
+ .then(res => res ?? [])
777
+ .catch(error => {
716
778
  throw new Dynamo_Error({
717
779
  status: 417,
718
780
  errorCode: 'NTS-DBS-UM0',
@@ -722,6 +784,18 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
722
784
  error
723
785
  });
724
786
  });
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;
725
799
  }
726
800
 
727
801
  // ----------------------------------------------------------------------------------
@@ -760,7 +834,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
760
834
 
761
835
  params.forEach((property: DynamoNTS_DataPropertyParams) => {
762
836
  const beType = this.getBEType(property.type);
763
- if (beType !== Object || !property.subObjectParams) {
837
+ if (beType !== Object || !property?.subObjectParams || property?.subObjectParams?.length == 0) {
764
838
  schemaSettingsObj[property.key] = {
765
839
  type: beType
766
840
  };