@futdevpro/nts-dynamo 1.5.51 → 1.5.53

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