@futdevpro/nts-dynamo 1.9.44 → 1.9.50
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/build/_collections/global-settings.const.d.ts.map +1 -1
- package/build/_collections/global-settings.const.js +1 -0
- package/build/_collections/global-settings.const.js.map +1 -1
- package/build/_models/interfaces/global-service-settings.interface.d.ts +3 -3
- package/build/_models/interfaces/global-service-settings.interface.d.ts.map +1 -1
- package/build/_models/interfaces/global-settings.interface.d.ts +4 -0
- package/build/_models/interfaces/global-settings.interface.d.ts.map +1 -1
- package/build/_modules/mock/data-model.mock.d.ts +2 -2
- package/build/_modules/mock/data-model.mock.d.ts.map +1 -1
- package/build/_modules/mock/data-model.mock.js +21 -21
- package/build/_modules/mock/data-model.mock.js.map +1 -1
- package/build/_modules/mock/socket-server.mock.d.ts +1 -1
- package/build/_modules/mock/socket-server.mock.d.ts.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.d.ts +1 -1
- package/build/_modules/socket/_services/socket-server.service.d.ts.map +1 -1
- package/build/_modules/socket/_services/socket-server.service.spec.js +1 -1
- package/build/_modules/socket/_services/socket-server.service.spec.js.map +1 -1
- package/build/_services/base/archive-data.service.d.ts +2 -2
- package/build/_services/base/archive-data.service.d.ts.map +1 -1
- package/build/_services/base/archive-data.service.js +1 -1
- package/build/_services/base/archive-data.service.js.map +1 -1
- package/build/_services/base/data.service.d.ts +7 -7
- package/build/_services/base/data.service.d.ts.map +1 -1
- package/build/_services/base/data.service.js +63 -14
- package/build/_services/base/data.service.js.map +1 -1
- package/build/_services/base/db.service.d.ts +10 -11
- package/build/_services/base/db.service.d.ts.map +1 -1
- package/build/_services/base/db.service.js +29 -16
- package/build/_services/base/db.service.js.map +1 -1
- package/build/_services/core/api.service.d.ts.map +1 -1
- package/build/_services/core/api.service.js +3 -3
- package/build/_services/core/api.service.js.map +1 -1
- package/build/_services/core/global.service.d.ts +2 -2
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +1 -1
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/route/controller.service.d.ts.map +1 -1
- package/build/_services/route/controller.service.js.map +1 -1
- package/build/index.d.ts +3 -5
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -5
- package/build/index.js.map +1 -1
- package/package.json +3 -3
- package/src/_collections/global-settings.const.ts +2 -1
- package/src/_models/interfaces/global-service-settings.interface.ts +3 -3
- package/src/_models/interfaces/global-settings.interface.ts +5 -0
- package/src/_modules/mock/data-model.mock.ts +23 -23
- package/src/_modules/mock/socket-server.mock.ts +5 -5
- package/src/_modules/socket/_services/socket-server.service.spec.ts +1 -1
- package/src/_modules/socket/_services/socket-server.service.ts +1 -1
- package/src/_services/base/archive-data.service.ts +8 -6
- package/src/_services/base/data.service.ts +185 -109
- package/src/_services/base/db.service.ts +99 -66
- package/src/_services/core/api.service.ts +5 -5
- package/src/_services/core/global.service.ts +16 -14
- package/src/_services/route/controller.service.ts +2 -3
- package/src/index.ts +3 -5
- package/build/_models/types/db-filter.type.d.ts +0 -97
- package/build/_models/types/db-filter.type.d.ts.map +0 -1
- package/build/_models/types/db-filter.type.js +0 -3
- package/build/_models/types/db-filter.type.js.map +0 -1
- package/src/_models/types/db-filter.type.ts +0 -108
|
@@ -6,9 +6,9 @@ import { Request, Response } from 'express';
|
|
|
6
6
|
|
|
7
7
|
import { DyFM_DataModel_Params } from '@futdevpro/fsm-dynamo';
|
|
8
8
|
|
|
9
|
-
import { DyNTS_Service_Collection } from '../../_services/core/service-collection.service';
|
|
10
|
-
import { DyNTS_EmailService } from '../../_services/core/email.service';
|
|
11
9
|
import { DyNTS_AuthService } from '../../_services/core/auth.service';
|
|
10
|
+
import { DyNTS_EmailService } from '../../_services/core/email.service';
|
|
11
|
+
import { DyNTS_Service_Collection } from '../../_services/core/service-collection.service';
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
export interface DyNTS_GlobalService_Settings {
|
|
@@ -25,7 +25,7 @@ export interface DyNTS_GlobalService_Settings {
|
|
|
25
25
|
/**
|
|
26
26
|
* you can setup data tables by passing a DyFM_DataModel_Params list at this point
|
|
27
27
|
*/
|
|
28
|
-
dbModels?: DyFM_DataModel_Params[],
|
|
28
|
+
dbModels?: DyFM_DataModel_Params<any>[],
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* you can setup other services by passing a DyNTS_SingletonService list at this point
|
|
@@ -22,18 +22,18 @@ export class Dependency_Mock extends DyFM_Metadata {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const dependency_mock_DataParams = new DyFM_DataModel_Params({
|
|
25
|
+
export const dependency_mock_DataParams = new DyFM_DataModel_Params<Dependency_Mock>({
|
|
26
26
|
dataName: 'dependencyMock',
|
|
27
|
-
properties:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
27
|
+
properties: {
|
|
28
|
+
string: { type: 'string' },
|
|
29
|
+
number: { type: 'number' },
|
|
30
|
+
date: { type: 'Date' },
|
|
31
|
+
boolean: { type: 'boolean' },
|
|
32
|
+
array: { type: 'string[]' },
|
|
33
|
+
object: { type: 'any' },
|
|
34
|
+
objectArray: { type: 'any[]' },
|
|
35
|
+
objectArrayArray: { type: 'any[][]' },
|
|
36
|
+
},
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
////////////////////////////////////////////////////////////////////
|
|
@@ -63,21 +63,21 @@ export class Dependent_Mock extends DyFM_Metadata {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export const dependent_mock_DataParams = new DyFM_DataModel_Params({
|
|
66
|
+
export const dependent_mock_DataParams = new DyFM_DataModel_Params<Dependent_Mock>({
|
|
67
67
|
dataName: 'dependentMock',
|
|
68
|
-
properties:
|
|
69
|
-
|
|
68
|
+
properties: {
|
|
69
|
+
dependencyId: { type: 'string',
|
|
70
70
|
unique: true, required: true,
|
|
71
71
|
isDependencyHook: true,
|
|
72
72
|
dependencyDataName: dependency_mock_DataParams.dataName,
|
|
73
73
|
},
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
string: { type: 'string' },
|
|
75
|
+
number: { type: 'number' },
|
|
76
|
+
date: { type: 'Date' },
|
|
77
|
+
boolean: { type: 'boolean' },
|
|
78
|
+
array: { type: 'string[]' },
|
|
79
|
+
object: { type: 'any' },
|
|
80
|
+
objectArray: { type: 'any[]' },
|
|
81
|
+
objectArrayArray: { type: 'any[][]' },
|
|
82
|
+
},
|
|
83
83
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Socket } from 'socket.io';
|
|
2
1
|
import { DyFM_SocketEvent } from '@futdevpro/fsm-dynamo/socket';
|
|
2
|
+
import { Socket } from 'socket.io';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
DyNTS_SocketPresence
|
|
4
|
+
import {
|
|
5
|
+
DyNTS_SocketPresence
|
|
6
6
|
} from '../socket/_models/socket-presence.control-model';
|
|
7
|
-
import {
|
|
8
|
-
DyNTS_SocketServerService_Params
|
|
7
|
+
import {
|
|
8
|
+
DyNTS_SocketServerService_Params
|
|
9
9
|
} from '../socket/_models/socket-server-service-params.control-model';
|
|
10
10
|
import { DyNTS_SocketServerService } from '../socket/_services/socket-server.service';
|
|
11
11
|
|
|
@@ -4,7 +4,7 @@ import { DyNTS_SocketServer_Mock } from '../../mock/socket-server.mock';
|
|
|
4
4
|
|
|
5
5
|
describe('DyNTS_SocketServerService', () => {
|
|
6
6
|
it('should create an instance', () => {
|
|
7
|
-
expect(
|
|
7
|
+
expect(DyNTS_SocketServer_Mock.getInstance()).toBeTruthy();
|
|
8
8
|
});
|
|
9
9
|
});
|
|
10
10
|
|
|
@@ -64,7 +64,7 @@ export abstract class DyNTS_SocketServerService<
|
|
|
64
64
|
`We encountered an unhandled Socket Server Error, ` +
|
|
65
65
|
`\nplease contact the responsible development team.`;
|
|
66
66
|
|
|
67
|
-
constructor(){
|
|
67
|
+
protected constructor(){
|
|
68
68
|
super();
|
|
69
69
|
|
|
70
70
|
this.asyncConstructor().catch((error: any) => {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
DyFM_DataModel_Params,
|
|
4
|
+
DyFM_DBFilterSimple,
|
|
5
|
+
DyFM_Error,
|
|
6
|
+
DyFM_Metadata
|
|
4
7
|
} from '@futdevpro/fsm-dynamo';
|
|
5
8
|
|
|
6
|
-
import { DyNTS_DataService } from './data.service';
|
|
7
9
|
import { DyNTS_getArchivedDBName } from '../../_collections/archive.util';
|
|
8
10
|
import { DyNTS_GlobalService } from '../core/global.service';
|
|
11
|
+
import { DyNTS_DataService } from './data.service';
|
|
9
12
|
import { DyNTS_DBService } from './db.service';
|
|
10
|
-
import { DyNTS_DBFilterSimple } from '../../_models/types/db-filter.type';
|
|
11
13
|
|
|
12
14
|
// TODO: 3 type of archiving service system:
|
|
13
15
|
// 1.: within list (data have a list that have elements to archive)
|
|
@@ -26,7 +28,7 @@ export class DyNTS_ArchiveDataService<T extends DyFM_Metadata> extends DyNTS_Dat
|
|
|
26
28
|
/**
|
|
27
29
|
* DB data prams will be used to connect to usable dbService on GlobalService
|
|
28
30
|
*/
|
|
29
|
-
dataParams: DyFM_DataModel_Params
|
|
31
|
+
dataParams: DyFM_DataModel_Params<T>,
|
|
30
32
|
/**
|
|
31
33
|
* Initial set for issuer to be able to follow the issuer's activity
|
|
32
34
|
*/
|
|
@@ -95,7 +97,7 @@ export class DyNTS_ArchiveDataService<T extends DyFM_Metadata> extends DyNTS_Dat
|
|
|
95
97
|
return await this.findData(
|
|
96
98
|
{
|
|
97
99
|
_originalId: originalId,
|
|
98
|
-
} as
|
|
100
|
+
} as DyFM_DBFilterSimple<T>,
|
|
99
101
|
dontSetToService
|
|
100
102
|
);
|
|
101
103
|
} catch (error) {
|
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
import {
|
|
3
3
|
DyFM_AnyError,
|
|
4
4
|
DyFM_Array,
|
|
5
|
-
|
|
5
|
+
DyFM_Data_Params,
|
|
6
|
+
DyFM_DataModel_Params, DyFM_DataProperty_Params,
|
|
7
|
+
DyFM_DBFilter,
|
|
8
|
+
DyFM_Error,
|
|
6
9
|
DyFM_Error_Settings, DyFM_ErrorLevel,
|
|
7
10
|
DyFM_Log,
|
|
8
|
-
DyFM_Metadata
|
|
11
|
+
DyFM_Metadata,
|
|
12
|
+
DyFM_SearchQuery
|
|
9
13
|
} from '@futdevpro/fsm-dynamo';
|
|
10
14
|
|
|
11
15
|
import { DyNTS_getArchivedDBName } from '../../_collections/archive.util';
|
|
12
16
|
import { DyNTS_global_settings } from '../../_collections/global-settings.const';
|
|
13
|
-
import { DyNTS_DBFilter } from '../../_models/types/db-filter.type';
|
|
14
17
|
import { DyNTS_DBUpdate } from '../../_models/types/db-update.type';
|
|
15
18
|
import { DyNTS_GlobalService } from '../core/global.service';
|
|
16
19
|
import { DyNTS_ArchiveDataService } from './archive-data.service';
|
|
@@ -54,7 +57,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
54
57
|
depKeyIsRequired?: boolean;
|
|
55
58
|
private depDataDBService: DyNTS_DBService<any>;
|
|
56
59
|
|
|
57
|
-
dataParams: DyFM_DataModel_Params
|
|
60
|
+
dataParams: DyFM_DataModel_Params<T>;
|
|
58
61
|
|
|
59
62
|
readonly defaultErrorUserMsg: string =
|
|
60
63
|
`We encountered an unhandled Data Service Error, ` +
|
|
@@ -71,7 +74,8 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
71
74
|
/**
|
|
72
75
|
* DB data prams will be used to connect to usable dbService on GlobalService
|
|
73
76
|
*/
|
|
74
|
-
dataParams: DyFM_DataModel_Params,
|
|
77
|
+
/* dataParams: DyFM_DataModel_Params, */
|
|
78
|
+
dataParams: DyFM_Data_Params<T>,
|
|
75
79
|
/**
|
|
76
80
|
* Initial set for issuer to be able to follow the issuer's activity
|
|
77
81
|
*/
|
|
@@ -254,37 +258,41 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
254
258
|
});
|
|
255
259
|
}
|
|
256
260
|
|
|
257
|
-
if (!dependencyId
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
261
|
+
if (!dependencyId) {
|
|
262
|
+
dependencyId = this.data?.[this.depKey];
|
|
263
|
+
|
|
264
|
+
if (!dependencyId) {
|
|
265
|
+
throw new DyFM_Error({
|
|
266
|
+
...this._getDefaultErrorSettings(
|
|
267
|
+
'getDataByDependencyId',
|
|
268
|
+
new Error(
|
|
269
|
+
`getDataByDependencyId failed, "${this.depKey}" is missing! ` +
|
|
270
|
+
`(${this.dataParams.dataName})`
|
|
271
|
+
)
|
|
272
|
+
),
|
|
273
|
+
|
|
274
|
+
errorCode: 'NTS-DS0-GD2',
|
|
275
|
+
additionalContent: {
|
|
276
|
+
data: this.data,
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
}
|
|
272
280
|
}
|
|
273
281
|
|
|
274
|
-
const dataExists: T = await this.dataDBService.getDataByDependencyId(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
);
|
|
282
|
+
const dataExists: T = await this.dataDBService.getDataByDependencyId(dependencyId).catch(
|
|
283
|
+
(error): null => {
|
|
284
|
+
if (error?.errorCode === 'NTS-DBS-GD2') {
|
|
285
|
+
DyFM_Log.warn(
|
|
286
|
+
`getDataByDependencyId failed; "${this.dataParams.dataName}" ` +
|
|
287
|
+
`(${this.depKey}: ${dependencyId ?? this.data[this.depKey]}) didn't found any.`
|
|
288
|
+
);
|
|
282
289
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
290
|
+
return null;
|
|
291
|
+
} else {
|
|
292
|
+
throw error;
|
|
293
|
+
}
|
|
286
294
|
}
|
|
287
|
-
|
|
295
|
+
);
|
|
288
296
|
|
|
289
297
|
if (!dontSetToService) {
|
|
290
298
|
this.data = dataExists;
|
|
@@ -462,7 +470,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
462
470
|
* //
|
|
463
471
|
* @returns {T} data: T
|
|
464
472
|
*/
|
|
465
|
-
async findData(filterBy:
|
|
473
|
+
async findData(filterBy: DyFM_DBFilter<T>, dontSetToService?: boolean): Promise<T> {
|
|
466
474
|
try {
|
|
467
475
|
const dataExists: T = await this.dataDBService.findOne(filterBy).catch((error): null => {
|
|
468
476
|
if (error?.errorCode === 'NTS-DBS-FO1') {
|
|
@@ -518,7 +526,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
518
526
|
* //
|
|
519
527
|
* @returns {T[]} dataList: T[]
|
|
520
528
|
*/
|
|
521
|
-
async findDataList(filterBy:
|
|
529
|
+
async findDataList(filterBy: DyFM_DBFilter<T>, dontSetToService?: boolean): Promise<T[]> {
|
|
522
530
|
try {
|
|
523
531
|
const dataListExists: T[] = await this.dataDBService.find(filterBy).catch((error): T[] => {
|
|
524
532
|
if (error?.errorCode === 'NTS-DBS-F1') {
|
|
@@ -601,7 +609,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
601
609
|
* //
|
|
602
610
|
*/
|
|
603
611
|
async updateData(
|
|
604
|
-
set: { filterBy?:
|
|
612
|
+
set: { filterBy?: DyFM_DBFilter<T>, update: DyNTS_DBUpdate<T> },
|
|
605
613
|
dontUpdateModified?: boolean
|
|
606
614
|
): Promise<void> {
|
|
607
615
|
try {
|
|
@@ -615,7 +623,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
615
623
|
|
|
616
624
|
} else if (this.data._id) {
|
|
617
625
|
await this.dataDBService.updateOne(
|
|
618
|
-
{ _id: this.data._id } as
|
|
626
|
+
{ _id: this.data._id } as DyFM_DBFilter<T>,
|
|
619
627
|
set.update,
|
|
620
628
|
this.issuer,
|
|
621
629
|
dontUpdateModified
|
|
@@ -623,7 +631,7 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
623
631
|
|
|
624
632
|
} else if (this.depKey && this.data[this.depKey]) {
|
|
625
633
|
await this.dataDBService.updateOne(
|
|
626
|
-
{ [this.depKey]: this.data[this.depKey] } as
|
|
634
|
+
{ [this.depKey]: this.data[this.depKey] } as DyFM_DBFilter<T>,
|
|
627
635
|
set.update,
|
|
628
636
|
this.issuer,
|
|
629
637
|
dontUpdateModified
|
|
@@ -679,15 +687,15 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
679
687
|
}
|
|
680
688
|
|
|
681
689
|
/**
|
|
682
|
-
* modifies data if the data have ID and already exists in the DB,
|
|
683
|
-
* creates new if the ID is not present or cant find in DB,
|
|
684
|
-
* and if dependency data setted up, will check before creation,
|
|
685
|
-
*
|
|
686
|
-
* @warning
|
|
687
|
-
* but the proper way to update data, if you use update method instead,
|
|
688
|
-
* this way, you can avoid data override errors
|
|
689
|
-
* (when you simultaneously trying to change the same data's
|
|
690
|
-
* different values from different flows)
|
|
690
|
+
* modifies data if the data have ID and already exists in the DB,
|
|
691
|
+
* creates new if the ID is not present or cant find in DB,
|
|
692
|
+
* and if dependency data setted up, will check before creation,
|
|
693
|
+
*
|
|
694
|
+
* @warning
|
|
695
|
+
* but the proper way to update data, if you use update method instead,
|
|
696
|
+
* this way, you can avoid data override errors
|
|
697
|
+
* (when you simultaneously trying to change the same data's
|
|
698
|
+
* different values from different flows)
|
|
691
699
|
*/
|
|
692
700
|
async saveData(data?: T, dontSetToService?: boolean, dontUpdateModified?: boolean): Promise<T> {
|
|
693
701
|
try {
|
|
@@ -797,6 +805,23 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
797
805
|
// if data not exists create new data
|
|
798
806
|
data = await this.dataDBService.createData(data, this.issuer);
|
|
799
807
|
|
|
808
|
+
if (!data._id) {
|
|
809
|
+
throw new DyFM_Error({
|
|
810
|
+
...this._getDefaultErrorSettings(
|
|
811
|
+
'saveData',
|
|
812
|
+
new Error(
|
|
813
|
+
`saveData was unsuccessful: data creation failed ` +
|
|
814
|
+
`(${this.dataParams.dataName})`
|
|
815
|
+
)
|
|
816
|
+
),
|
|
817
|
+
|
|
818
|
+
errorCode: 'NTS-DS0-SD4',
|
|
819
|
+
additionalContent: {
|
|
820
|
+
data: data,
|
|
821
|
+
},
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
|
|
800
825
|
if (!dontSetToService) {
|
|
801
826
|
this.data = data;
|
|
802
827
|
}
|
|
@@ -804,7 +829,12 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
804
829
|
return data;
|
|
805
830
|
|
|
806
831
|
} catch (error) {
|
|
807
|
-
if ([
|
|
832
|
+
if ([
|
|
833
|
+
'NTS-DS0-SD1',
|
|
834
|
+
'NTS-DS0-SD2',
|
|
835
|
+
'NTS-DS0-SD3',
|
|
836
|
+
'NTS-DS0-SD4',
|
|
837
|
+
].includes(error?.errorCode)) {
|
|
808
838
|
throw error;
|
|
809
839
|
|
|
810
840
|
} else {
|
|
@@ -818,8 +848,8 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
818
848
|
}
|
|
819
849
|
|
|
820
850
|
/**
|
|
821
|
-
* markes data as deleted, if can be archived, will be archived as well
|
|
822
|
-
* if absolute is true, permanently deletes data from database by data._id
|
|
851
|
+
* markes data as deleted, if can be archived, will be archived as well
|
|
852
|
+
* if absolute is true, permanently deletes data from database by data._id
|
|
823
853
|
*/
|
|
824
854
|
async deleteData(id?: string, absolute?: boolean): Promise<void> {
|
|
825
855
|
try {
|
|
@@ -971,72 +1001,74 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
971
1001
|
}
|
|
972
1002
|
|
|
973
1003
|
/**
|
|
974
|
-
* validation of data, for modify and create, by the ModelParams
|
|
1004
|
+
* validation of data, for modify and create, by the ModelParams
|
|
975
1005
|
*/
|
|
976
1006
|
async validateForSave(data?: T): Promise<void> {
|
|
977
1007
|
try {
|
|
978
1008
|
data = this.ensureData(data);
|
|
979
1009
|
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
(
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
// specific Date validation
|
|
1010
|
-
if (element.type === 'Date' &&
|
|
1011
|
-
!(new Date(data[element.key]) instanceof Date)
|
|
1012
|
-
) {
|
|
1013
|
-
throw new DyFM_Error({
|
|
1014
|
-
...this._getDefaultErrorSettings(
|
|
1015
|
-
'validateForSave',
|
|
1016
|
-
new Error(
|
|
1017
|
-
`validateForSave failed, "${element.key}" is not a date! ` +
|
|
1018
|
-
`(${this.dataParams.dataName})`
|
|
1019
|
-
)
|
|
1020
|
-
),
|
|
1010
|
+
Object.values(this.dataParams.properties).forEach(
|
|
1011
|
+
(element: DyFM_DataProperty_Params<any>) => {
|
|
1012
|
+
// basic required validations
|
|
1013
|
+
if (
|
|
1014
|
+
(
|
|
1015
|
+
element.required ||
|
|
1016
|
+
element.index
|
|
1017
|
+
) && (
|
|
1018
|
+
data[element.key] === null ||
|
|
1019
|
+
data[element.key] === undefined
|
|
1020
|
+
)
|
|
1021
|
+
) {
|
|
1022
|
+
throw new DyFM_Error({
|
|
1023
|
+
...this._getDefaultErrorSettings(
|
|
1024
|
+
'validateForSave',
|
|
1025
|
+
new Error(
|
|
1026
|
+
`validateForSave failed, "${element.key}" is missing! ` +
|
|
1027
|
+
`(${this.dataParams.dataName})`
|
|
1028
|
+
)
|
|
1029
|
+
),
|
|
1030
|
+
|
|
1031
|
+
status: 522,
|
|
1032
|
+
errorCode: 'NTS-DS0-VD1',
|
|
1033
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1034
|
+
additionalContent: {
|
|
1035
|
+
data: data,
|
|
1036
|
+
},
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1021
1039
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1040
|
+
// specific Date validation
|
|
1041
|
+
if (element.type === 'Date' &&
|
|
1042
|
+
!(new Date(data[element.key]) instanceof Date)
|
|
1043
|
+
) {
|
|
1044
|
+
throw new DyFM_Error({
|
|
1045
|
+
...this._getDefaultErrorSettings(
|
|
1046
|
+
'validateForSave',
|
|
1047
|
+
new Error(
|
|
1048
|
+
`validateForSave failed, "${element.key}" is not a date! ` +
|
|
1049
|
+
`(${this.dataParams.dataName})`
|
|
1050
|
+
)
|
|
1051
|
+
),
|
|
1052
|
+
|
|
1053
|
+
status: 522,
|
|
1054
|
+
errorCode: 'NTS-DS0-VD2',
|
|
1055
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
1056
|
+
additionalContent: {
|
|
1057
|
+
data: data,
|
|
1058
|
+
},
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1030
1061
|
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1062
|
+
// call additional validators
|
|
1063
|
+
if (element.additionalValidators) {
|
|
1064
|
+
for (let j = 0; j < element.additionalValidators.length; j++) {
|
|
1065
|
+
element.additionalValidators[j](
|
|
1066
|
+
data[element.key]
|
|
1067
|
+
);
|
|
1068
|
+
}
|
|
1037
1069
|
}
|
|
1038
1070
|
}
|
|
1039
|
-
|
|
1071
|
+
);
|
|
1040
1072
|
} catch (error) {
|
|
1041
1073
|
if ([ 'NTS-DS0-VD1', 'NTS-DS0-VD2' ].includes(error?.errorCode)) {
|
|
1042
1074
|
throw error;
|
|
@@ -1051,13 +1083,57 @@ export class DyNTS_DataService<T extends DyFM_Metadata> {
|
|
|
1051
1083
|
}
|
|
1052
1084
|
}
|
|
1053
1085
|
|
|
1086
|
+
async searchData(query?: DyFM_SearchQuery<T>): Promise<T[]> {
|
|
1087
|
+
try {
|
|
1088
|
+
if (!query || Object.keys(query).length === 0) {
|
|
1089
|
+
return await this.getAll();
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
if (!query.filterBy) {
|
|
1093
|
+
query.filterBy = {};
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
if (!query.page && !query.pageSize && !query.sortBy) {
|
|
1097
|
+
return await this.dataDBService.find(query.filterBy);
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
if (!query.page) {
|
|
1101
|
+
query.page = 1;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
if (!query.pageSize) {
|
|
1105
|
+
DyFM_Log.warn('searchData pageSize is not setted, setting to 10.');
|
|
1106
|
+
query.pageSize = DyNTS_global_settings.defaultPageSize;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
if (!query.sortBy) {
|
|
1110
|
+
query.sortBy = { __lastModified: -1 };
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
return await this.dataDBService.findWithPaging(
|
|
1114
|
+
query.filterBy,
|
|
1115
|
+
query.page,
|
|
1116
|
+
query.pageSize,
|
|
1117
|
+
query.sortBy
|
|
1118
|
+
);
|
|
1119
|
+
} catch (error) {
|
|
1120
|
+
throw new DyFM_Error({
|
|
1121
|
+
...this._getDefaultErrorSettings('searchData', error),
|
|
1122
|
+
|
|
1123
|
+
errorCode: 'NTS-DS0-SD0',
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
|
|
1054
1129
|
/**
|
|
1055
1130
|
* setting up dependency dataHook by DynamoBEDataModelParams
|
|
1056
1131
|
*/
|
|
1057
1132
|
private lookForDependencyDataSettings(): void {
|
|
1058
|
-
const dependencyParam: DyFM_DataProperty_Params =
|
|
1059
|
-
(
|
|
1060
|
-
|
|
1133
|
+
const dependencyParam: DyFM_DataProperty_Params<any> =
|
|
1134
|
+
Object.values(this.dataParams.properties).find(
|
|
1135
|
+
(modelParams: DyFM_DataProperty_Params<any>): boolean => modelParams.isDependencyHook
|
|
1136
|
+
);
|
|
1061
1137
|
|
|
1062
1138
|
if (dependencyParam) {
|
|
1063
1139
|
this.depKey = dependencyParam.key;
|