@futdevpro/nts-dynamo 1.5.81 → 1.5.83
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 +5 -5
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +6 -6
- package/lib/_services/dynamo-nts-data.service.js.map +1 -1
- package/lib/_services/dynamo-nts-db.service.d.ts +93 -19
- package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-db.service.js +102 -102
- package/lib/_services/dynamo-nts-db.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
- package/src/_services/dynamo-nts-data.service.ts +10 -10
- package/src/_services/dynamo-nts-db.service.ts +187 -110
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@futdevpro/nts-dynamo",
|
|
3
|
-
"version": "01.05.
|
|
3
|
+
"version": "01.05.83",
|
|
4
4
|
"description": "Dynamic NodeTS (NodeJS-Typescript), MongoDB Backend System Framework by Future Development Program Ltd.",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"scripts": {
|
|
7
6
|
"test": "jasmine",
|
|
8
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import { Dynamo_Metadata, Dynamo_DataParams, Dynamo_DataPropertyParams, Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
3
3
|
|
|
4
|
-
import { DynamoNTS_DBService } from './dynamo-nts-db.service';
|
|
4
|
+
import { DynamoNTS_DBFilter, DynamoNTS_DBService, DynamoNTS_DBUpdate } from './dynamo-nts-db.service';
|
|
5
5
|
import { DynamoNTS_GlobalService } from './dynamo-nts-global.service';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -285,9 +285,9 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
285
285
|
* //
|
|
286
286
|
* @returns {T} data: T
|
|
287
287
|
*/
|
|
288
|
-
async findData(
|
|
288
|
+
async findData(filterBy: DynamoNTS_DBFilter<T>, dontSetToService?: boolean): Promise<T> {
|
|
289
289
|
try {
|
|
290
|
-
const dataExists: T = await this.dataDBService.findOne(
|
|
290
|
+
const dataExists: T = await this.dataDBService.findOne(filterBy).catch(error => {
|
|
291
291
|
if (error?.errorCode === 'NTS-DBS-FO1') {
|
|
292
292
|
Dynamo_Log.warn(`findData ${this.dataParams.dataName} didn't found any.`);
|
|
293
293
|
return null;
|
|
@@ -342,9 +342,9 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
342
342
|
* //
|
|
343
343
|
* @returns {T[]} dataList: T[]
|
|
344
344
|
*/
|
|
345
|
-
async findDatas(
|
|
345
|
+
async findDatas(filterBy: DynamoNTS_DBFilter<T>, dontSetToService?: boolean): Promise<T[]> {
|
|
346
346
|
try {
|
|
347
|
-
const dataListExists: T[] = await this.dataDBService.find(
|
|
347
|
+
const dataListExists: T[] = await this.dataDBService.find(filterBy).catch(error => {
|
|
348
348
|
if (error?.errorCode === 'NTS-DBS-F1') {
|
|
349
349
|
Dynamo_Log.warn(`findDatas ${this.dataParams.dataName} didn't found any.`);
|
|
350
350
|
return [];
|
|
@@ -425,14 +425,14 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
425
425
|
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
426
426
|
* //
|
|
427
427
|
*/
|
|
428
|
-
async updateData(set: {
|
|
428
|
+
async updateData(set: { filterBy?: DynamoNTS_DBFilter<T>, update: DynamoNTS_DBUpdate<T> }): Promise<void> {
|
|
429
429
|
try {
|
|
430
|
-
if (set.
|
|
431
|
-
await this.dataDBService.updateOne(set.
|
|
430
|
+
if (set.filterBy) {
|
|
431
|
+
await this.dataDBService.updateOne(set.filterBy, set.update, this.issuer);
|
|
432
432
|
} else if (this.data._id) {
|
|
433
|
-
await this.dataDBService.updateOne({ _id: this.data._id }
|
|
433
|
+
await this.dataDBService.updateOne({ _id: this.data._id } as DynamoNTS_DBFilter<T>, set.update, this.issuer);
|
|
434
434
|
} else if (this.depKey && this.data[this.depKey]) {
|
|
435
|
-
await this.dataDBService.updateOne({ [this.depKey]: this.data[this.depKey] }
|
|
435
|
+
await this.dataDBService.updateOne({ [this.depKey]: this.data[this.depKey] } as DynamoNTS_DBFilter<T>, set.update, this.issuer);
|
|
436
436
|
} else {
|
|
437
437
|
throw new Dynamo_Error({
|
|
438
438
|
status: 417,
|
|
@@ -6,10 +6,87 @@ import {
|
|
|
6
6
|
Dynamo_Metadata, Dynamo_DataParams, Dynamo_DataPropertyParams, Dynamo_Error
|
|
7
7
|
} from '@futdevpro/fsm-dynamo';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @example
|
|
11
|
+
* // by email:
|
|
12
|
+
* { email: email }
|
|
13
|
+
* //
|
|
14
|
+
* @example
|
|
15
|
+
* // or by id that is in list:
|
|
16
|
+
* { userIds: { $in: this.userId } }
|
|
17
|
+
* //
|
|
18
|
+
* @example
|
|
19
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
20
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
21
|
+
* // further tools (syntax matches with $gt):
|
|
22
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
23
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
24
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
25
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
26
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
27
|
+
* //
|
|
28
|
+
* @returns {T} data: T
|
|
29
|
+
*/
|
|
30
|
+
export type DynamoNTS_DBFilter<T> = {
|
|
31
|
+
[K in keyof T]?: T[K] | {
|
|
32
|
+
$in?: any, // Matches values that are includes the value; This works only when T[K] is an array!
|
|
33
|
+
$eq?: T[K], // Matches values that are EQual to a specified value.
|
|
34
|
+
$gt?: number | Date, // Matches values that are Greater Than a specified value.
|
|
35
|
+
$gte?: number | Date, // Matches values that are Greater Than OR Equal to a specified value.
|
|
36
|
+
$lt?: number | Date, // Matches values that are Less Than a specified value.
|
|
37
|
+
$lte?: number | Date, // Matches values that are Less Than or Equal to a specified value.
|
|
38
|
+
$ne?: T[K], // Matches all values that are Not Equal to a specified value.
|
|
39
|
+
$nin?: T[K], // Matches None of the values specified IN an array.
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param update this uses the basic Mongoose updateOne
|
|
45
|
+
* @example
|
|
46
|
+
* // increase a specific value (here by 15):
|
|
47
|
+
* { $inc: { popularity: 15 } }
|
|
48
|
+
* //
|
|
49
|
+
* @example
|
|
50
|
+
* // or add element to a list:
|
|
51
|
+
* { $push: { reactions: this.newReaction }
|
|
52
|
+
* // or add multiple elements to a list
|
|
53
|
+
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
54
|
+
* //
|
|
55
|
+
* @example
|
|
56
|
+
* // or all at once
|
|
57
|
+
* {
|
|
58
|
+
* $inc: { popularity: this.newVote.amount },
|
|
59
|
+
* emailVerified: true,
|
|
60
|
+
* $push: { reactions: this.newReaction }
|
|
61
|
+
* }
|
|
62
|
+
* // further tools (syntax matches with $inc):
|
|
63
|
+
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
64
|
+
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
65
|
+
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
66
|
+
* $mul: // Multiplies the value of the field by the specified amount.
|
|
67
|
+
* $rename: // Renames a field.
|
|
68
|
+
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
69
|
+
* //
|
|
70
|
+
*/
|
|
71
|
+
export type DynamoNTS_DBUpdate<T> = {
|
|
72
|
+
[K in keyof T]?: T[K] | {
|
|
73
|
+
$inc?: number, // Increments the value of the field by the specified amount.
|
|
74
|
+
$push?: any | { // Adds an item to an array.
|
|
75
|
+
$each?: T[K], // Adds multiple items to an array.
|
|
76
|
+
}, // or add multiple elements to a list
|
|
77
|
+
// { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
78
|
+
$min?: number, // Only updates the field if the specified value is less than the existing field value.
|
|
79
|
+
$max?: number, // Only updates the field if the specified value is greater than the existing field value.
|
|
80
|
+
$mul?: number, // Multiplies the value of the field by the specified amount.
|
|
81
|
+
$rename?: string, // Renames a field.
|
|
82
|
+
$unset?: string, // Removes the specified field from a document. (set: "" to value)
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
9
86
|
/**
|
|
10
87
|
*
|
|
11
88
|
*/
|
|
12
|
-
export class DynamoNTS_DBService<T extends Dynamo_Metadata
|
|
89
|
+
export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
13
90
|
dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
|
|
14
91
|
|
|
15
92
|
private depDataName: string;
|
|
@@ -269,15 +346,89 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
269
346
|
return dataList;
|
|
270
347
|
}
|
|
271
348
|
|
|
349
|
+
/**
|
|
350
|
+
* returns all data from database,
|
|
351
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GA1)
|
|
352
|
+
*
|
|
353
|
+
* @returns dataList
|
|
354
|
+
*/
|
|
355
|
+
async getAll(): Promise<T[]> {
|
|
356
|
+
let dataList: T[] = await this.dataModel.find({})
|
|
357
|
+
.then(res => {
|
|
358
|
+
return res as T[] ?? [];
|
|
359
|
+
}).catch(error => {
|
|
360
|
+
throw new Dynamo_Error({
|
|
361
|
+
status: 417,
|
|
362
|
+
errorCode: 'NTS-DBS-GA0',
|
|
363
|
+
addECToUserMsg: true,
|
|
364
|
+
message: `get all ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
365
|
+
userMessage: this.defaultErrorUserMsg,
|
|
366
|
+
error
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
371
|
+
dataList.forEach((data: T) => {
|
|
372
|
+
data._id = `˙${data._id}`;
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return dataList as T[];
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* deleted data by id
|
|
381
|
+
* @param id id
|
|
382
|
+
*/
|
|
383
|
+
async deleteDataById(id: string): Promise<void> {
|
|
384
|
+
await this.dataModel.findByIdAndDelete(id).catch(error => {
|
|
385
|
+
throw new Dynamo_Error({
|
|
386
|
+
status: 417,
|
|
387
|
+
errorCode: 'NTS-DBS-DD0',
|
|
388
|
+
addECToUserMsg: true,
|
|
389
|
+
message: `delete ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
390
|
+
userMessage: this.defaultErrorUserMsg,
|
|
391
|
+
error
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* deleted data by id
|
|
398
|
+
* @param dependencyId id
|
|
399
|
+
*/
|
|
400
|
+
async deleteDataByDependencyId(dependencyId: string): Promise<void> {
|
|
401
|
+
if (!this.depDataName) {
|
|
402
|
+
throw new Dynamo_Error({
|
|
403
|
+
status: 501,
|
|
404
|
+
errorCode: 'NTS-DBS-DDD0',
|
|
405
|
+
addECToUserMsg: true,
|
|
406
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
407
|
+
userMessage: this.defaultErrorUserMsg
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
await this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
|
|
412
|
+
throw new Dynamo_Error({
|
|
413
|
+
status: 417,
|
|
414
|
+
errorCode: 'NTS-DBS-DDD1',
|
|
415
|
+
addECToUserMsg: true,
|
|
416
|
+
message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
417
|
+
userMessage: this.defaultErrorUserMsg,
|
|
418
|
+
error
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
272
423
|
/**
|
|
273
424
|
* returns search result for searchBy object params
|
|
274
425
|
* can use lists or xRange values for searchBy obj properties
|
|
275
426
|
*
|
|
276
|
-
* @param
|
|
427
|
+
* @param filterBy filter
|
|
277
428
|
* @param narrowByDependencyIds id
|
|
278
429
|
* @returns dataList
|
|
279
430
|
*/
|
|
280
|
-
async searchData(
|
|
431
|
+
async searchData(filterBy: DynamoNTS_DBFilter<T>, narrowByDependencyIds?: string[]): Promise<T[]> {
|
|
281
432
|
const filter = {};
|
|
282
433
|
|
|
283
434
|
if (0 < narrowByDependencyIds.length) {
|
|
@@ -296,45 +447,45 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
296
447
|
|
|
297
448
|
await this.dataParams.modelParams.forEach((modelParam: Dynamo_DataPropertyParams) => {
|
|
298
449
|
if (
|
|
299
|
-
(
|
|
300
|
-
|
|
450
|
+
(filterBy[modelParam.key] !== null && filterBy[modelParam.key] !== undefined) ||
|
|
451
|
+
filterBy[modelParam.key + 'Range']
|
|
301
452
|
) {
|
|
302
453
|
if (modelParam.key.includes('Range') || modelParam.type.includes('[]')) {
|
|
303
454
|
// inverz search filter (for Range and Array functions)
|
|
304
455
|
if (modelParam.key.includes('Range')) {
|
|
305
456
|
const searchParamKeyWithoutRange = modelParam.key.split('Range')[0];
|
|
306
457
|
if (
|
|
307
|
-
|
|
308
|
-
|
|
458
|
+
filterBy[searchParamKeyWithoutRange] !== null &&
|
|
459
|
+
filterBy[searchParamKeyWithoutRange] !== undefined
|
|
309
460
|
) {
|
|
310
461
|
filter[modelParam.key] = {
|
|
311
|
-
from: { $lte:
|
|
312
|
-
to: { $gte:
|
|
462
|
+
from: { $lte: filterBy[searchParamKeyWithoutRange] },
|
|
463
|
+
to: { $gte: filterBy[searchParamKeyWithoutRange] }
|
|
313
464
|
};
|
|
314
465
|
}
|
|
315
466
|
} else {
|
|
316
467
|
if (
|
|
317
|
-
|
|
318
|
-
|
|
468
|
+
filterBy[modelParam.key] !== null &&
|
|
469
|
+
filterBy[modelParam.key] !== undefined
|
|
319
470
|
) {
|
|
320
|
-
filter[modelParam.key] = { $in:
|
|
471
|
+
filter[modelParam.key] = { $in: filterBy[modelParam.key] };
|
|
321
472
|
}
|
|
322
473
|
}
|
|
323
474
|
} else {
|
|
324
475
|
// basic search filter
|
|
325
|
-
if (
|
|
326
|
-
if (
|
|
476
|
+
if (filterBy[modelParam.key + 'Range']) {
|
|
477
|
+
if (filterBy[modelParam.key + 'Range'].from || filterBy[modelParam.key + 'Range'].to) {
|
|
327
478
|
filter[modelParam.key] = {};
|
|
328
|
-
if (
|
|
329
|
-
filter[modelParam.key].$gte =
|
|
479
|
+
if (filterBy[modelParam.key + 'Range'].from) {
|
|
480
|
+
filter[modelParam.key].$gte = filterBy[modelParam.key + 'Range'].from;
|
|
330
481
|
}
|
|
331
|
-
if (
|
|
332
|
-
filter[modelParam.key].$lte =
|
|
482
|
+
if (filterBy[modelParam.key + 'Range'].to) {
|
|
483
|
+
filter[modelParam.key].$lte = filterBy[modelParam.key + 'Range'].to;
|
|
333
484
|
}
|
|
334
485
|
}
|
|
335
|
-
} else if (
|
|
336
|
-
if (
|
|
337
|
-
filter[modelParam.key] = { $in:
|
|
486
|
+
} else if (filterBy[modelParam.key] !== null && filterBy[modelParam.key] !== undefined) {
|
|
487
|
+
if (filterBy[modelParam.key].lenght > 0) {
|
|
488
|
+
filter[modelParam.key] = { $in: filterBy[modelParam.key] };
|
|
338
489
|
}
|
|
339
490
|
}
|
|
340
491
|
}
|
|
@@ -365,80 +516,6 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
365
516
|
return dataList;
|
|
366
517
|
}
|
|
367
518
|
|
|
368
|
-
/**
|
|
369
|
-
* returns all data from database,
|
|
370
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GA1)
|
|
371
|
-
*
|
|
372
|
-
* @returns dataList
|
|
373
|
-
*/
|
|
374
|
-
async getAll(): Promise<T[]> {
|
|
375
|
-
let dataList: T[] = await this.dataModel.find({})
|
|
376
|
-
.then(res => {
|
|
377
|
-
return res as T[] ?? [];
|
|
378
|
-
}).catch(error => {
|
|
379
|
-
throw new Dynamo_Error({
|
|
380
|
-
status: 417,
|
|
381
|
-
errorCode: 'NTS-DBS-GA0',
|
|
382
|
-
addECToUserMsg: true,
|
|
383
|
-
message: `get all ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
384
|
-
userMessage: this.defaultErrorUserMsg,
|
|
385
|
-
error
|
|
386
|
-
});
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
390
|
-
dataList.forEach((data: T) => {
|
|
391
|
-
data._id = `˙${data._id}`;
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return dataList as T[];
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* deleted data by id
|
|
400
|
-
* @param id id
|
|
401
|
-
*/
|
|
402
|
-
async deleteDataById(id: string): Promise<void> {
|
|
403
|
-
await this.dataModel.findByIdAndDelete(id).catch(error => {
|
|
404
|
-
throw new Dynamo_Error({
|
|
405
|
-
status: 417,
|
|
406
|
-
errorCode: 'NTS-DBS-DD0',
|
|
407
|
-
addECToUserMsg: true,
|
|
408
|
-
message: `delete ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
409
|
-
userMessage: this.defaultErrorUserMsg,
|
|
410
|
-
error
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* deleted data by id
|
|
417
|
-
* @param dependencyId id
|
|
418
|
-
*/
|
|
419
|
-
async deleteDataByDependencyId(dependencyId: string): Promise<void> {
|
|
420
|
-
if (!this.depDataName) {
|
|
421
|
-
throw new Dynamo_Error({
|
|
422
|
-
status: 501,
|
|
423
|
-
errorCode: 'NTS-DBS-DDD0',
|
|
424
|
-
addECToUserMsg: true,
|
|
425
|
-
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
426
|
-
userMessage: this.defaultErrorUserMsg
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
await this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
|
|
431
|
-
throw new Dynamo_Error({
|
|
432
|
-
status: 417,
|
|
433
|
-
errorCode: 'NTS-DBS-DDD1',
|
|
434
|
-
addECToUserMsg: true,
|
|
435
|
-
message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
436
|
-
userMessage: this.defaultErrorUserMsg,
|
|
437
|
-
error
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
|
|
442
519
|
// ----------------------------------------------------------------------------------
|
|
443
520
|
// ----------------------------------------------------------------------------------
|
|
444
521
|
// ----------------------------------------------------------------------------------
|
|
@@ -448,7 +525,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
448
525
|
* Find the data first by any of its parameters,
|
|
449
526
|
* !!!: throws error if not found (errorCode on not found: NTS-DBS-FO1)
|
|
450
527
|
*
|
|
451
|
-
* @param
|
|
528
|
+
* @param filterBy if you can, use unique parameters for find!
|
|
452
529
|
*
|
|
453
530
|
* @example
|
|
454
531
|
* // by email:
|
|
@@ -470,15 +547,15 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
470
547
|
* //
|
|
471
548
|
* @returns {T} data: T
|
|
472
549
|
*/
|
|
473
|
-
async findOne(
|
|
474
|
-
let data: T = await this.dataModel.findOne(
|
|
550
|
+
async findOne(filterBy: DynamoNTS_DBFilter<T>): Promise<T> {
|
|
551
|
+
let data: T = await this.dataModel.findOne(filterBy).then(res => {
|
|
475
552
|
return res as T ?? null;
|
|
476
553
|
}).catch(error => {
|
|
477
554
|
throw new Dynamo_Error({
|
|
478
555
|
status: 417,
|
|
479
556
|
errorCode: 'NTS-DBS-FO0',
|
|
480
557
|
addECToUserMsg: true,
|
|
481
|
-
message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB) fliter: ${
|
|
558
|
+
message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB) fliter: ${filterBy}`,
|
|
482
559
|
userMessage: this.defaultErrorUserMsg,
|
|
483
560
|
error
|
|
484
561
|
});
|
|
@@ -496,7 +573,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
496
573
|
* Find the data first by any of its parameters,
|
|
497
574
|
* !!!: throws error if not found (errorCode on not found: NTS-DBS-F1)
|
|
498
575
|
*
|
|
499
|
-
* @param
|
|
576
|
+
* @param filterBy if you can, use unique parameters for find!
|
|
500
577
|
*
|
|
501
578
|
* @example
|
|
502
579
|
* // by email:
|
|
@@ -518,8 +595,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
518
595
|
* //
|
|
519
596
|
* @returns {T[]} dataList: T[]
|
|
520
597
|
*/
|
|
521
|
-
async find(
|
|
522
|
-
let dataList: T[] = await this.dataModel.find(
|
|
598
|
+
async find(filterBy: DynamoNTS_DBFilter<T>): Promise<T[]> {
|
|
599
|
+
let dataList: T[] = await this.dataModel.find(filterBy)
|
|
523
600
|
.then(res => {
|
|
524
601
|
return res as T[] ?? [];
|
|
525
602
|
}).catch(error => {
|
|
@@ -548,7 +625,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
548
625
|
* #MONGOOSE FUNCTION
|
|
549
626
|
* Find the data first by any of its parameters
|
|
550
627
|
*
|
|
551
|
-
* @param
|
|
628
|
+
* @param filterBy if you can, use unique parameters for find!
|
|
552
629
|
*
|
|
553
630
|
* @example
|
|
554
631
|
* // by email:
|
|
@@ -577,8 +654,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
577
654
|
* //
|
|
578
655
|
* @returns {T[]} dataList: T[]
|
|
579
656
|
*/
|
|
580
|
-
async findWithPaging(
|
|
581
|
-
let dataList: T[] = await this.dataModel.find(
|
|
657
|
+
async findWithPaging(filterBy: DynamoNTS_DBFilter<T>, page: number, pageSize: number, sort?: any): Promise<T[]> {
|
|
658
|
+
let dataList: T[] = await this.dataModel.find(filterBy)
|
|
582
659
|
.sort(sort)
|
|
583
660
|
.skip(page * pageSize)
|
|
584
661
|
.limit(pageSize)
|
|
@@ -614,7 +691,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
614
691
|
* @param update update
|
|
615
692
|
* @returns data
|
|
616
693
|
*/
|
|
617
|
-
async findByIdAndUpdate(id: string, update:
|
|
694
|
+
async findByIdAndUpdate(id: string, update: DynamoNTS_DBUpdate<T>, modifier: string): Promise<T> {
|
|
618
695
|
update.__lastModified = new Date();
|
|
619
696
|
update.__lastModifiedBy = modifier;
|
|
620
697
|
|
|
@@ -690,11 +767,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
690
767
|
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
691
768
|
* //
|
|
692
769
|
*/
|
|
693
|
-
async updateOne(
|
|
770
|
+
async updateOne(filterBy: DynamoNTS_DBFilter<T>, update: DynamoNTS_DBUpdate<T>, issuer: string): Promise<void> {
|
|
694
771
|
update.__lastModified = new Date();
|
|
695
772
|
update.__lastModifiedBy = issuer;
|
|
696
773
|
|
|
697
|
-
await this.dataModel.updateOne(
|
|
774
|
+
await this.dataModel.updateOne(filterBy, update).catch(error => {
|
|
698
775
|
throw new Dynamo_Error({
|
|
699
776
|
status: 417,
|
|
700
777
|
errorCode: 'NTS-DBS-UO0',
|
|
@@ -757,11 +834,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata, F extends T = any, U
|
|
|
757
834
|
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
758
835
|
* //
|
|
759
836
|
*/
|
|
760
|
-
async updateMany(
|
|
837
|
+
async updateMany(filterBy: DynamoNTS_DBFilter<T>, update: DynamoNTS_DBUpdate<T>, issuer: string): Promise<void> {
|
|
761
838
|
update.__lastModified = new Date();
|
|
762
839
|
update.__lastModifiedBy = issuer;
|
|
763
840
|
|
|
764
|
-
await this.dataModel.updateMany(
|
|
841
|
+
await this.dataModel.updateMany(filterBy, update).catch(error => {
|
|
765
842
|
throw new Dynamo_Error({
|
|
766
843
|
status: 417,
|
|
767
844
|
errorCode: 'NTS-DBS-UM0',
|