@futdevpro/nts-dynamo 1.5.77 → 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/LICENSE +2 -2
- package/lib/_constants/dynamo-nts-global-settings.d.ts +2 -2
- package/lib/_constants/dynamo-nts-global-settings.js +17 -17
- package/lib/_constants/index.d.ts +1 -1
- package/lib/_constants/index.js +4 -4
- package/lib/_enums/data-model-type.enum.d.ts +12 -12
- package/lib/_enums/data-model-type.enum.js +16 -16
- package/lib/_enums/data-model-type.enum.js.map +1 -1
- package/lib/_enums/dynamo-nts-data-service-function.enum.d.ts +12 -12
- package/lib/_enums/dynamo-nts-data-service-function.enum.js +18 -18
- package/lib/_enums/dynamo-nts-data-service-function.enum.js.map +1 -1
- package/lib/_enums/dynamo-nts-route-security.enum.d.ts +11 -11
- package/lib/_enums/dynamo-nts-route-security.enum.js +15 -15
- package/lib/_enums/dynamo-nts-route-security.enum.js.map +1 -1
- package/lib/_enums/dynamo-nts-socket-security.enum.d.ts +10 -10
- package/lib/_enums/dynamo-nts-socket-security.enum.js +14 -14
- package/lib/_enums/dynamo-nts-socket-security.enum.js.map +1 -1
- package/lib/_enums/http/http-call-type.enum.d.ts +11 -11
- package/lib/_enums/http/http-call-type.enum.js +15 -15
- package/lib/_enums/http/http-call-type.enum.js.map +1 -1
- package/lib/_enums/http/http-response-type.enum.d.ts +6 -6
- package/lib/_enums/http/http-response-type.enum.js +10 -10
- package/lib/_enums/http/http-response-type.enum.js.map +1 -1
- package/lib/_enums/http/socket-event.enum.d.ts +9 -8
- package/lib/_enums/http/socket-event.enum.d.ts.map +1 -1
- package/lib/_enums/http/socket-event.enum.js +13 -12
- package/lib/_enums/http/socket-event.enum.js.map +1 -1
- package/lib/_enums/index.d.ts +8 -8
- package/lib/_enums/index.js +13 -13
- package/lib/_enums/predefined-data-types.enum.d.ts +10 -10
- package/lib/_enums/predefined-data-types.enum.js +14 -14
- package/lib/_enums/predefined-data-types.enum.js.map +1 -1
- package/lib/_interfaces/certification-settings.interface.d.ts +7 -0
- package/lib/_interfaces/certification-settings.interface.d.ts.map +1 -0
- package/lib/_interfaces/certification-settings.interface.js +3 -0
- package/lib/_interfaces/certification-settings.interface.js.map +1 -0
- package/lib/_interfaces/global-service-settings.interface.d.ts +18 -0
- package/lib/_interfaces/global-service-settings.interface.d.ts.map +1 -0
- package/lib/_interfaces/global-service-settings.interface.js +3 -0
- package/lib/_interfaces/global-service-settings.interface.js.map +1 -0
- package/lib/_interfaces/index.d.ts +1 -0
- package/lib/_interfaces/index.d.ts.map +1 -0
- package/lib/_interfaces/index.js +4 -0
- package/lib/_interfaces/index.js.map +1 -0
- package/lib/_interfaces/port-settings.interface.d.ts +5 -0
- package/lib/_interfaces/port-settings.interface.d.ts.map +1 -0
- package/lib/_interfaces/port-settings.interface.js +3 -0
- package/lib/_interfaces/port-settings.interface.js.map +1 -0
- package/lib/_models/dynamo-nts-api-call-params.d.ts +95 -95
- package/lib/_models/dynamo-nts-api-call-params.js +47 -47
- package/lib/_models/dynamo-nts-app-params.d.ts +49 -49
- package/lib/_models/dynamo-nts-app-params.js +17 -17
- package/lib/_models/dynamo-nts-endpoint-params.d.ts +80 -80
- package/lib/_models/dynamo-nts-endpoint-params.js +139 -139
- package/lib/_models/dynamo-nts-global-settings.d.ts +53 -53
- package/lib/_models/dynamo-nts-global-settings.js +2 -2
- package/lib/_models/dynamo-nts-routing-module-settings.d.ts +19 -19
- package/lib/_models/dynamo-nts-routing-module-settings.js +2 -2
- package/lib/_models/dynamo-nts-socket-event-params.d.ts +32 -30
- package/lib/_models/dynamo-nts-socket-event-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-event-params.js +80 -79
- package/lib/_models/dynamo-nts-socket-event-params.js.map +1 -1
- package/lib/_models/dynamo-nts-socket-presence.d.ts +21 -0
- package/lib/_models/dynamo-nts-socket-presence.d.ts.map +1 -0
- package/lib/_models/dynamo-nts-socket-presence.js +45 -0
- package/lib/_models/dynamo-nts-socket-presence.js.map +1 -0
- package/lib/_models/dynamo-nts-socket-service-params.d.ts +18 -18
- package/lib/_models/dynamo-nts-socket-service-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-service-params.js +26 -26
- package/lib/_models/dynamo-nts-socket-service-params.js.map +1 -1
- package/lib/_models/index.d.ts +7 -8
- package/lib/_models/index.d.ts.map +1 -1
- package/lib/_models/index.js +12 -12
- package/lib/_models/index.js.map +1 -1
- package/lib/_modules/api-service.index.d.ts +5 -5
- package/lib/_modules/api-service.index.js +11 -11
- package/lib/_modules/app-extended.index.d.ts +15 -12
- package/lib/_modules/app-extended.index.d.ts.map +1 -1
- package/lib/_modules/app-extended.index.js +23 -19
- package/lib/_modules/app-extended.index.js.map +1 -1
- package/lib/_modules/app.index.d.ts +13 -10
- package/lib/_modules/app.index.d.ts.map +1 -1
- package/lib/_modules/app.index.js +21 -17
- package/lib/_modules/app.index.js.map +1 -1
- package/lib/_modules/auth.index.d.ts +3 -3
- package/lib/_modules/auth.index.js +8 -8
- package/lib/_modules/constants.index.d.ts +1 -1
- package/lib/_modules/constants.index.js +4 -4
- package/lib/_modules/controller.index.d.ts +4 -4
- package/lib/_modules/controller.index.js +10 -10
- package/lib/_modules/custom-data/custom-data.controller.d.ts +5 -5
- package/lib/_modules/custom-data/custom-data.controller.js +55 -55
- package/lib/_modules/custom-data/custom-data.service.d.ts +5 -5
- package/lib/_modules/custom-data/custom-data.service.js +11 -11
- package/lib/_modules/custom-data/get-custom-data-routing-module.d.ts +3 -3
- package/lib/_modules/custom-data/get-custom-data-routing-module.js +17 -17
- package/lib/_modules/custom-data/index.d.ts +4 -4
- package/lib/_modules/custom-data/index.js +8 -8
- package/lib/_modules/custom-data-module.index.d.ts +1 -1
- package/lib/_modules/custom-data-module.index.js +4 -4
- package/lib/_modules/data-service.index.d.ts +5 -5
- package/lib/_modules/data-service.index.js +10 -10
- package/lib/_modules/email.index.d.ts +3 -3
- package/lib/_modules/email.index.js +8 -8
- package/lib/_modules/enums.index.d.ts +1 -1
- package/lib/_modules/enums.index.js +4 -4
- package/lib/_modules/models.index.d.ts +1 -1
- package/lib/_modules/models.index.js +4 -4
- package/lib/_modules/services.index.d.ts +1 -1
- package/lib/_modules/services.index.js +4 -4
- package/lib/_modules/test/get-test-routing-module.d.ts +3 -3
- package/lib/_modules/test/get-test-routing-module.js +17 -17
- package/lib/_modules/test/index.d.ts +3 -3
- package/lib/_modules/test/index.js +7 -7
- package/lib/_modules/test/test.controller.d.ts +5 -5
- package/lib/_modules/test/test.controller.js +104 -104
- package/lib/_modules/test-module.index.d.ts +1 -1
- package/lib/_modules/test-module.index.js +4 -4
- package/lib/_modules/usage/get-usage-routing-module.d.ts +3 -3
- package/lib/_modules/usage/get-usage-routing-module.js +17 -17
- package/lib/_modules/usage/index.d.ts +4 -4
- package/lib/_modules/usage/index.js +8 -8
- package/lib/_modules/usage/usage-controller.d.ts +6 -6
- package/lib/_modules/usage/usage-controller.js +88 -88
- package/lib/_modules/usage/usage.service.d.ts +16 -16
- package/lib/_modules/usage/usage.service.js +132 -132
- package/lib/_modules/usage-module.index.d.ts +1 -1
- package/lib/_modules/usage-module.index.js +4 -4
- package/lib/_services/dynamo-nts-api.service.d.ts +34 -34
- package/lib/_services/dynamo-nts-api.service.js +188 -188
- package/lib/_services/dynamo-nts-app-extended.d.ts +128 -128
- package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.js +212 -212
- package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
- package/lib/_services/dynamo-nts-app.d.ts +270 -278
- package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app.js +371 -371
- package/lib/_services/dynamo-nts-app.js.map +1 -1
- package/lib/_services/dynamo-nts-app.spec.d.ts +1 -0
- package/lib/_services/dynamo-nts-app.spec.d.ts.map +1 -0
- package/lib/_services/dynamo-nts-app.spec.js +10 -0
- package/lib/_services/dynamo-nts-app.spec.js.map +1 -0
- package/lib/_services/dynamo-nts-auth.service.d.ts +127 -127
- package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.js +53 -53
- package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
- package/lib/_services/dynamo-nts-controller.service.d.ts +105 -105
- package/lib/_services/dynamo-nts-controller.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-controller.service.js +57 -57
- package/lib/_services/dynamo-nts-controller.service.js.map +1 -1
- package/lib/_services/dynamo-nts-data.service.d.ts +230 -230
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +689 -689
- package/lib/_services/dynamo-nts-data.service.js.map +1 -1
- package/lib/_services/dynamo-nts-db-service-collection.service.d.ts +8 -8
- package/lib/_services/dynamo-nts-db-service-collection.service.js +10 -10
- package/lib/_services/dynamo-nts-db.service.d.ts +386 -312
- package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-db.service.js +856 -856
- package/lib/_services/dynamo-nts-db.service.js.map +1 -1
- package/lib/_services/dynamo-nts-email-service-collection.service.d.ts +18 -18
- package/lib/_services/dynamo-nts-email-service-collection.service.js +20 -20
- package/lib/_services/dynamo-nts-email.service.d.ts +56 -56
- package/lib/_services/dynamo-nts-email.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-email.service.js +203 -203
- package/lib/_services/dynamo-nts-email.service.js.map +1 -1
- package/lib/_services/dynamo-nts-global.service.d.ts +71 -84
- package/lib/_services/dynamo-nts-global.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-global.service.js +156 -156
- package/lib/_services/dynamo-nts-global.service.js.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.d.ts +76 -76
- package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.js +191 -191
- package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
- package/lib/_services/dynamo-nts-shared.service.d.ts +31 -31
- package/lib/_services/dynamo-nts-shared.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-shared.service.js +70 -70
- package/lib/_services/dynamo-nts-shared.service.js.map +1 -1
- package/lib/_services/dynamo-nts-shared.service.spec.d.ts +2 -0
- package/lib/_services/dynamo-nts-shared.service.spec.d.ts.map +1 -0
- package/lib/_services/dynamo-nts-shared.service.spec.js +12 -0
- package/lib/_services/dynamo-nts-shared.service.spec.js.map +1 -0
- package/lib/_services/dynamo-nts-singleton.service.d.ts +8 -8
- package/lib/_services/dynamo-nts-singleton.service.js +18 -18
- package/lib/_services/dynamo-nts-singleton.service.js.map +1 -1
- package/lib/_services/dynamo-nts-socket-service-collection.service.d.ts +9 -9
- package/lib/_services/dynamo-nts-socket-service-collection.service.js +13 -13
- package/lib/_services/dynamo-nts-socket.service.d.ts +57 -45
- package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.js +188 -165
- package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
- package/lib/_services/index.d.ts +14 -16
- package/lib/_services/index.d.ts.map +1 -1
- package/lib/_services/index.js +20 -20
- package/lib/_services/index.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.js +14 -14
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package SAVE.json +216 -0
- package/package-NEW with test but not working.json +228 -0
- package/package.json +14 -8
- package/spec/support/jasmine.json +14 -0
- package/src/_enums/http/socket-event.enum.ts +2 -1
- package/src/_interfaces/certification-settings.interface.ts +7 -0
- package/src/_interfaces/global-service-settings.interface.ts +23 -0
- package/src/_interfaces/index.ts +5 -0
- package/src/_interfaces/port-settings.interface.ts +5 -0
- package/src/_models/dynamo-nts-socket-event-params.ts +23 -21
- package/src/_models/{dynamo-nts-socket-dictionary.ts → dynamo-nts-socket-presence.ts} +21 -5
- package/src/_models/dynamo-nts-socket-service-params.ts +1 -0
- package/src/_models/index.ts +2 -2
- package/src/_modules/app-extended.index.ts +7 -2
- package/src/_modules/app.index.ts +5 -0
- package/src/_services/dynamo-nts-app-extended.ts +6 -2
- package/src/_services/dynamo-nts-app.spec.ts +14 -0
- package/src/_services/dynamo-nts-app.ts +8 -14
- package/src/_services/dynamo-nts-auth.service.ts +1 -0
- package/src/_services/dynamo-nts-controller.service.ts +2 -1
- package/src/_services/dynamo-nts-data.service.ts +19 -19
- package/src/_services/dynamo-nts-db.service.ts +195 -115
- package/src/_services/dynamo-nts-email.service.ts +1 -0
- package/src/_services/dynamo-nts-global.service.ts +3 -18
- package/src/_services/dynamo-nts-routing-module.service.ts +1 -0
- package/src/_services/dynamo-nts-shared.service.spec.ts +10 -0
- package/src/_services/dynamo-nts-shared.service.ts +2 -1
- package/src/_services/dynamo-nts-socket.service.ts +80 -41
- package/src/_services/index.ts +2 -2
|
@@ -1,690 +1,690 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DynamoNTS_DataService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
6
|
-
const dynamo_nts_global_service_1 = require("./dynamo-nts-global.service");
|
|
7
|
-
/**
|
|
8
|
-
* Basic Data Service that is connected to the relevant DBServices
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* export class UserMatchStatisticsService extends DynamoNTS_DataService<UserMatchStatistics> {
|
|
12
|
-
* constructor(
|
|
13
|
-
* set?: {
|
|
14
|
-
* data?: UserMatchStatistics,
|
|
15
|
-
* issuer?: string,
|
|
16
|
-
* }
|
|
17
|
-
* ) {
|
|
18
|
-
* super(
|
|
19
|
-
* new UserMatchStatistics(set?.data),
|
|
20
|
-
* userMatchStatisticsModelParams
|
|
21
|
-
* );
|
|
22
|
-
* this.issuer = set?.issuer;
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
*/
|
|
26
|
-
class DynamoNTS_DataService {
|
|
27
|
-
constructor(
|
|
28
|
-
/**
|
|
29
|
-
* Initial data, this will be used by functions on default
|
|
30
|
-
*/
|
|
31
|
-
data,
|
|
32
|
-
/**
|
|
33
|
-
* DB data prams will be used to connect to usable dbService on GlobalService
|
|
34
|
-
*/
|
|
35
|
-
dataParams,
|
|
36
|
-
/**
|
|
37
|
-
* Initial set for issuer to be able to follow the issuer's activity
|
|
38
|
-
*/
|
|
39
|
-
issuer) {
|
|
40
|
-
this.dataList = [];
|
|
41
|
-
this.defaultErrorUserMsg = `We encountered an unhandled Data Error, ` +
|
|
42
|
-
`\nplease contact the responsible development team.`;
|
|
43
|
-
this.defaultValidationErrorUserMsg = `We encountered an unhandled Validation Error, ` +
|
|
44
|
-
`\nplease contact the responsible development team.`;
|
|
45
|
-
this.dataDBService = dynamo_nts_global_service_1.DynamoNTS_GlobalService.getDBService(dataParams);
|
|
46
|
-
this.data = data;
|
|
47
|
-
this.dataParams = dataParams;
|
|
48
|
-
this.lookForDependencyDataSettings();
|
|
49
|
-
this.issuer = issuer;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* returns all data from database to service dataList
|
|
53
|
-
*/
|
|
54
|
-
getAll(dontSetToService) {
|
|
55
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
try {
|
|
57
|
-
const dataListExists = yield this.dataDBService.getAll().catch(error => {
|
|
58
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GA1') {
|
|
59
|
-
fsm_dynamo_1.Dynamo_Log.warn(`getAll ${this.dataParams.dataName} didn't found any.`);
|
|
60
|
-
return [];
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
if (!dontSetToService) {
|
|
67
|
-
this.dataList = dataListExists;
|
|
68
|
-
}
|
|
69
|
-
return dataListExists;
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
73
|
-
status: 417,
|
|
74
|
-
errorCode: 'NTS-DS0-GA0',
|
|
75
|
-
addECToUserMsg: true,
|
|
76
|
-
message: `getAll was unsuccessful (${this.dataParams.dataName})`,
|
|
77
|
-
userMessage: this.defaultErrorUserMsg,
|
|
78
|
-
error: error
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* @description
|
|
85
|
-
* returns data from database by id
|
|
86
|
-
* also if dontSetToService is false or not setted,
|
|
87
|
-
* the data will be saved to the service, even if its not found
|
|
88
|
-
*
|
|
89
|
-
* @remarks
|
|
90
|
-
* If you need to get-save a data, if possible,
|
|
91
|
-
* use db-service update instead.
|
|
92
|
-
*
|
|
93
|
-
* @param {string} id
|
|
94
|
-
* (using id from service.data, if not provided)
|
|
95
|
-
* @param dontSetToService
|
|
96
|
-
*
|
|
97
|
-
* @return {T} data: T
|
|
98
|
-
*/
|
|
99
|
-
getDataById(id, dontSetToService) {
|
|
100
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
try {
|
|
102
|
-
if (!id && !this.data._id) {
|
|
103
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
104
|
-
status: 417,
|
|
105
|
-
errorCode: 'NTS-DS0-GI1',
|
|
106
|
-
addECToUserMsg: true,
|
|
107
|
-
message: `ID is missing! (maybe you wanted to use getDataByDependencyId() instead...) (${this.dataParams.dataName})`,
|
|
108
|
-
userMessage: this.defaultErrorUserMsg
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const dataExists = yield this.dataDBService.getDataById(id !== null && id !== void 0 ? id : this.data._id);
|
|
112
|
-
if (!dontSetToService) {
|
|
113
|
-
this.data = dataExists;
|
|
114
|
-
}
|
|
115
|
-
return dataExists;
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) == 'NTS-DS0-GI1') {
|
|
119
|
-
throw error;
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
123
|
-
status: 417,
|
|
124
|
-
errorCode: 'NTS-DS0-GI0',
|
|
125
|
-
addECToUserMsg: true,
|
|
126
|
-
message: `getDataById was unsuccessful (${this.dataParams.dataName})`,
|
|
127
|
-
userMessage: this.defaultErrorUserMsg,
|
|
128
|
-
error: error
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* returns data from database by dependencyId to the service
|
|
136
|
-
* (using id from service.data, if not provided)
|
|
137
|
-
* @param dependencyId
|
|
138
|
-
*/
|
|
139
|
-
getDataByDependencyId(dependencyId, dontSetToService) {
|
|
140
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
141
|
-
try {
|
|
142
|
-
if (!this.depKey) {
|
|
143
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
144
|
-
status: 417,
|
|
145
|
-
errorCode: 'NTS-DS0-GD1',
|
|
146
|
-
addECToUserMsg: true,
|
|
147
|
-
message: `
|
|
148
|
-
userMessage: this.defaultErrorUserMsg
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
if (!dependencyId && !this.data[this.depKey]) {
|
|
152
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
153
|
-
status: 417,
|
|
154
|
-
errorCode: 'NTS-DS0-GD2',
|
|
155
|
-
addECToUserMsg: true,
|
|
156
|
-
message:
|
|
157
|
-
userMessage: this.defaultErrorUserMsg
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
const dataExists = yield this.dataDBService.getDataByDependencyId(dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]).catch(error => {
|
|
161
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GD2') {
|
|
162
|
-
fsm_dynamo_1.Dynamo_Log.warn(`getDataByDependencyId ${this.dataParams.dataName} (${this.depKey}: ${dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]}) didn't found any.`);
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
if (!dontSetToService) {
|
|
170
|
-
this.data = dataExists;
|
|
171
|
-
}
|
|
172
|
-
return dataExists;
|
|
173
|
-
}
|
|
174
|
-
catch (error) {
|
|
175
|
-
if (['NTS-DS0-GD1', 'NTS-DS0-GD2'].includes(error === null || error === void 0 ? void 0 : error.errorCode)) {
|
|
176
|
-
throw error;
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
180
|
-
status: 417,
|
|
181
|
-
errorCode: 'NTS-DS0-GD0',
|
|
182
|
-
addECToUserMsg: true,
|
|
183
|
-
message: `getDataByDependencyId was unsuccessful (${this.dataParams.dataName})`,
|
|
184
|
-
userMessage: this.defaultErrorUserMsg,
|
|
185
|
-
error: error
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* returns dataList from database by dependencyId to the service
|
|
193
|
-
* @param dependencyId
|
|
194
|
-
*/
|
|
195
|
-
getDataListByDependencyId(dependencyId, dontSetToService) {
|
|
196
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
197
|
-
try {
|
|
198
|
-
if (!this.depKey) {
|
|
199
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
200
|
-
status: 417,
|
|
201
|
-
errorCode: 'NTS-DS0-GLD1',
|
|
202
|
-
addECToUserMsg: true,
|
|
203
|
-
message: `dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
|
|
204
|
-
userMessage: this.defaultErrorUserMsg
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
if (!dependencyId && !this.data[this.depKey]) {
|
|
208
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
209
|
-
status: 417,
|
|
210
|
-
errorCode: 'NTS-DS0-GLD2',
|
|
211
|
-
addECToUserMsg: true,
|
|
212
|
-
message:
|
|
213
|
-
userMessage: this.defaultErrorUserMsg
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
const dataListExists = yield this.dataDBService.getDataListByDependencyId(dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]).catch(error => {
|
|
217
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GLD2') {
|
|
218
|
-
fsm_dynamo_1.Dynamo_Log.warn(`getDataListByDependencyId ${this.dataParams.dataName} (${this.depKey}: ${dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]}) didn't found any.`);
|
|
219
|
-
return [];
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
throw error;
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
if (!dontSetToService) {
|
|
226
|
-
this.dataList = dataListExists;
|
|
227
|
-
}
|
|
228
|
-
return dataListExists;
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
if (['NTS-DS0-GLD1', 'NTS-DS0-GLD2'].includes(error === null || error === void 0 ? void 0 : error.errorCode)) {
|
|
232
|
-
throw error;
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
236
|
-
status: 417,
|
|
237
|
-
errorCode: 'NTS-DS0-GLD0',
|
|
238
|
-
addECToUserMsg: true,
|
|
239
|
-
message: `getDataListByDependencyId was unsuccessful (${this.dataParams.dataName})`,
|
|
240
|
-
userMessage: this.defaultErrorUserMsg,
|
|
241
|
-
error: error
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
*
|
|
249
|
-
* // findOne desc:
|
|
250
|
-
*
|
|
251
|
-
* Find the data first by any of its parameters,
|
|
252
|
-
* also if dontSetToService is false or not setted,
|
|
253
|
-
* the data will be saved to the service, even if non found
|
|
254
|
-
*
|
|
255
|
-
* @param filter if you can, use unique parameters for find!
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* // by email:
|
|
259
|
-
* { email: email }
|
|
260
|
-
* //
|
|
261
|
-
* @example
|
|
262
|
-
* // or by id that is in list:
|
|
263
|
-
* { userIds: { $in: this.userId } }
|
|
264
|
-
* //
|
|
265
|
-
* @example
|
|
266
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
267
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
268
|
-
* // further tools (syntax matches with $gt):
|
|
269
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
270
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
271
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
272
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
273
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
274
|
-
* //
|
|
275
|
-
* @returns {T} data: T
|
|
276
|
-
*/
|
|
277
|
-
findData(
|
|
278
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
279
|
-
try {
|
|
280
|
-
const dataExists = yield this.dataDBService.findOne(
|
|
281
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-FO1') {
|
|
282
|
-
fsm_dynamo_1.Dynamo_Log.warn(`findData ${this.dataParams.dataName} didn't found any.`);
|
|
283
|
-
return null;
|
|
284
|
-
}
|
|
285
|
-
else {
|
|
286
|
-
throw error;
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
if (!dontSetToService) {
|
|
290
|
-
this.data = dataExists;
|
|
291
|
-
}
|
|
292
|
-
return dataExists;
|
|
293
|
-
}
|
|
294
|
-
catch (error) {
|
|
295
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
296
|
-
status: 417,
|
|
297
|
-
errorCode: 'NTS-DS0-FD0',
|
|
298
|
-
addECToUserMsg: true,
|
|
299
|
-
message: `findData was unsuccessful (${this.dataParams.dataName})`,
|
|
300
|
-
userMessage: this.defaultErrorUserMsg,
|
|
301
|
-
error: error
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
*
|
|
308
|
-
* // find desc:
|
|
309
|
-
*
|
|
310
|
-
* Find the data first by any of its parameters,
|
|
311
|
-
* also if dontSetToService is false or not setted,
|
|
312
|
-
* the data will be saved to the service, even if non found
|
|
313
|
-
*
|
|
314
|
-
* @param filter if you can, use unique parameters for find!
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* // by email:
|
|
318
|
-
* { email: email }
|
|
319
|
-
* //
|
|
320
|
-
* @example
|
|
321
|
-
* // or by id that is in list:
|
|
322
|
-
* { userIds: { $in: this.userId } }
|
|
323
|
-
* //
|
|
324
|
-
* @example
|
|
325
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
326
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
327
|
-
* // further tools (syntax matches with $gt):
|
|
328
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
329
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
330
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
331
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
332
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
333
|
-
* //
|
|
334
|
-
* @returns {T[]} dataList: T[]
|
|
335
|
-
*/
|
|
336
|
-
findDatas(
|
|
337
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
338
|
-
try {
|
|
339
|
-
const dataListExists = yield this.dataDBService.find(
|
|
340
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-F1') {
|
|
341
|
-
fsm_dynamo_1.Dynamo_Log.warn(`findDatas ${this.dataParams.dataName} didn't found any.`);
|
|
342
|
-
return [];
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
throw error;
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
if (!dontSetToService) {
|
|
349
|
-
this.dataList = dataListExists;
|
|
350
|
-
}
|
|
351
|
-
return dataListExists;
|
|
352
|
-
}
|
|
353
|
-
catch (error) {
|
|
354
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
355
|
-
status: 417,
|
|
356
|
-
errorCode: 'NTS-DS0-FDS0',
|
|
357
|
-
addECToUserMsg: true,
|
|
358
|
-
message: `findDatas was unsuccessful (${this.dataParams.dataName})`,
|
|
359
|
-
userMessage: this.defaultErrorUserMsg,
|
|
360
|
-
error: error
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
* This function uses the dataDBService.updateOne function.
|
|
367
|
-
* This uses updateBy if setted, or data._id if its setted or this.data[this.dependencyKey]
|
|
368
|
-
* @param set
|
|
369
|
-
*
|
|
370
|
-
* // updateOne desc:
|
|
371
|
-
*
|
|
372
|
-
* Find the data first by any of its parameters, throws error if not found
|
|
373
|
-
* @param filter This uses the basic Mongoose updateOne.
|
|
374
|
-
* If you can, use unique parameters for find!
|
|
375
|
-
* @example
|
|
376
|
-
* // by email:
|
|
377
|
-
* { email: email }
|
|
378
|
-
* //
|
|
379
|
-
* @example
|
|
380
|
-
* // or by id that is in list:
|
|
381
|
-
* { userIds: { $in: this.userId } }
|
|
382
|
-
* //
|
|
383
|
-
* @example
|
|
384
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
385
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
386
|
-
* // further tools (syntax matches with $gt):
|
|
387
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
388
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
389
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
390
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
391
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
392
|
-
* //
|
|
393
|
-
*
|
|
394
|
-
* @param update this uses the basic Mongoose updateOne
|
|
395
|
-
* @example
|
|
396
|
-
* // increase a specific value (here by 15):
|
|
397
|
-
* { $inc: { popularity: 15 } }
|
|
398
|
-
* //
|
|
399
|
-
* @example
|
|
400
|
-
* // or add element to a list:
|
|
401
|
-
* { $push: { reactions: this.newReaction }
|
|
402
|
-
* // or add multiple elements to a list
|
|
403
|
-
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
404
|
-
* //
|
|
405
|
-
* @example
|
|
406
|
-
* // or all at once
|
|
407
|
-
* {
|
|
408
|
-
* $inc: { popularity: this.newVote.amount },
|
|
409
|
-
* emailVerified: true,
|
|
410
|
-
* $push: { reactions: this.newReaction }
|
|
411
|
-
* }
|
|
412
|
-
* // further tools (syntax matches with $inc):
|
|
413
|
-
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
414
|
-
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
415
|
-
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
416
|
-
* $mul: // Multiplies the value of the field by the specified amount.
|
|
417
|
-
* $rename: // Renames a field.
|
|
418
|
-
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
419
|
-
* //
|
|
420
|
-
*/
|
|
421
|
-
updateData(set) {
|
|
422
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
423
|
-
try {
|
|
424
|
-
if (set.
|
|
425
|
-
yield this.dataDBService.updateOne(set.
|
|
426
|
-
}
|
|
427
|
-
else if (this.data._id) {
|
|
428
|
-
yield this.dataDBService.updateOne({ _id: this.data._id }, set.update, this.issuer);
|
|
429
|
-
}
|
|
430
|
-
else if (this.depKey && this.data[this.depKey]) {
|
|
431
|
-
yield this.dataDBService.updateOne({ [this.depKey]: this.data[this.depKey] }, set.update, this.issuer);
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
435
|
-
status: 417,
|
|
436
|
-
errorCode: 'NTS-DS0-UD1',
|
|
437
|
-
addECToUserMsg: true,
|
|
438
|
-
message: `no usable parameter provided for updateData; no updateBy, no id, no dependencyId (${this.dataParams.dataName})`,
|
|
439
|
-
userMessage: this.defaultErrorUserMsg,
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
catch (error) {
|
|
444
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) == 'NTS-DS0-UD1') {
|
|
445
|
-
throw error;
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
449
|
-
status: 417,
|
|
450
|
-
errorCode: 'NTS-DS0-UD0',
|
|
451
|
-
addECToUserMsg: true,
|
|
452
|
-
message: `updateData was unsuccessful (${this.dataParams.dataName})`,
|
|
453
|
-
userMessage: this.defaultErrorUserMsg,
|
|
454
|
-
error: error
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* modifies data if the data have ID and already exists in the DB,
|
|
462
|
-
* creates new if the ID is not present or cant find in DB,
|
|
463
|
-
* and if dependency data setted up, will check before creation,
|
|
464
|
-
*
|
|
465
|
-
* @warning
|
|
466
|
-
* but the proper way to update data, if you use update method instead,
|
|
467
|
-
* this way, you can avoid data override errors
|
|
468
|
-
* (when you simultaneously trying to change the same data's
|
|
469
|
-
* different values from different flows)
|
|
470
|
-
*/
|
|
471
|
-
saveData() {
|
|
472
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
473
|
-
try {
|
|
474
|
-
if (!this.data) {
|
|
475
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
476
|
-
status: 417,
|
|
477
|
-
errorCode: 'NTS-DS0-SD4',
|
|
478
|
-
addECToUserMsg: true,
|
|
479
|
-
message: `saveData was unsuccessful: no data to save!, (${this.dataParams.dataName})`,
|
|
480
|
-
userMessage: this.defaultErrorUserMsg
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
if (!this.data._id && (!this.depKey || !this.data[this.depKey])) {
|
|
484
|
-
// if ID of dependencyID is not present, data not exists, create new data
|
|
485
|
-
this.data = yield this.dataDBService.createData(this.data, this.issuer);
|
|
486
|
-
return;
|
|
487
|
-
}
|
|
488
|
-
let dataExists;
|
|
489
|
-
// check if data already exists with the specific ID
|
|
490
|
-
if (this.data._id) {
|
|
491
|
-
dataExists = yield this.getDataById(null, true);
|
|
492
|
-
if (dataExists) {
|
|
493
|
-
// if data exists do modify
|
|
494
|
-
this.data = yield this.dataDBService.modifyData(this.data, this.issuer);
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
499
|
-
status: 417,
|
|
500
|
-
errorCode: 'NTS-DS0-SD1',
|
|
501
|
-
addECToUserMsg: true,
|
|
502
|
-
message: `saveData was unsuccessful: provided ID not exists (id: ${this.data._id}, ${this.dataParams.dataName})`,
|
|
503
|
-
userMessage: this.defaultErrorUserMsg
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
if (this.depKey) {
|
|
508
|
-
if (!this.data[this.depKey]) {
|
|
509
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
510
|
-
status: 417,
|
|
511
|
-
errorCode: 'NTS-DS0-SD2',
|
|
512
|
-
addECToUserMsg: true,
|
|
513
|
-
message: `saveData was unsuccessful: dependency data id missing from data (key: ${this.depKey}, ${this.dataParams.dataName})`,
|
|
514
|
-
userMessage: this.defaultErrorUserMsg
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
if (this.depKeyIsUnique) {
|
|
518
|
-
dataExists = yield this.getDataByDependencyId(null, true);
|
|
519
|
-
if (dataExists) {
|
|
520
|
-
// if data exists do modify
|
|
521
|
-
this.data = yield this.dataDBService.modifyData(this.data, this.issuer);
|
|
522
|
-
return;
|
|
523
|
-
}
|
|
524
|
-
else {
|
|
525
|
-
// if data not exists check that dependency already exists for this
|
|
526
|
-
const dependencyExists = yield this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
|
|
527
|
-
if (!dependencyExists) {
|
|
528
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
529
|
-
status: 417,
|
|
530
|
-
errorCode: 'NTS-DS0-SD3',
|
|
531
|
-
addECToUserMsg: true,
|
|
532
|
-
message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]}, ${this.dataParams.dataName})`,
|
|
533
|
-
userMessage: this.defaultErrorUserMsg
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
// if data not exists create new data
|
|
540
|
-
this.data = yield this.dataDBService.createData(this.data, this.issuer);
|
|
541
|
-
}
|
|
542
|
-
catch (error) {
|
|
543
|
-
if (['NTS-DS0-SD1', 'NTS-DS0-SD2'].includes(error === null || error === void 0 ? void 0 : error.errorCode)) {
|
|
544
|
-
throw error;
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
548
|
-
status: 417,
|
|
549
|
-
errorCode: 'NTS-DS0-SD0',
|
|
550
|
-
addECToUserMsg: true,
|
|
551
|
-
message: `
|
|
552
|
-
userMessage: this.defaultErrorUserMsg,
|
|
553
|
-
error: error
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* permanently deletes data from database by data._id
|
|
561
|
-
*/
|
|
562
|
-
deleteData() {
|
|
563
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
564
|
-
try {
|
|
565
|
-
if (!this.data._id) {
|
|
566
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
567
|
-
status: 417,
|
|
568
|
-
errorCode: 'NTS-DS0-DD1',
|
|
569
|
-
addECToUserMsg: true,
|
|
570
|
-
message: `ID is missing! (${this.dataParams.dataName})`,
|
|
571
|
-
userMessage: this.defaultErrorUserMsg,
|
|
572
|
-
});
|
|
573
|
-
}
|
|
574
|
-
yield this.dataDBService.deleteDataById(this.data._id);
|
|
575
|
-
}
|
|
576
|
-
catch (error) {
|
|
577
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) == 'NTS-DS0-DD1') {
|
|
578
|
-
throw error;
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
582
|
-
status: 417,
|
|
583
|
-
errorCode: 'NTS-DS0-DD0',
|
|
584
|
-
addECToUserMsg: true,
|
|
585
|
-
message: `deleteData was unsuccessful (${this.dataParams.dataName})`,
|
|
586
|
-
userMessage: this.defaultErrorUserMsg,
|
|
587
|
-
error: error
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
/**
|
|
594
|
-
* validation of data, for modify and create, by the ModelParams
|
|
595
|
-
*/
|
|
596
|
-
validateForSave() {
|
|
597
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
598
|
-
try {
|
|
599
|
-
for (let i = 0; i < this.dataParams.modelParams.length; i++) {
|
|
600
|
-
// basic required validations
|
|
601
|
-
if ((this.dataParams.modelParams[i].required &&
|
|
602
|
-
(this.data[this.dataParams.modelParams[i].key] === null ||
|
|
603
|
-
this.data[this.dataParams.modelParams[i].key] === undefined)) ||
|
|
604
|
-
(this.dataParams.modelParams[i].index &&
|
|
605
|
-
(this.data[this.dataParams.modelParams[i].key] === null ||
|
|
606
|
-
this.data[this.dataParams.modelParams[i].key] === undefined))) {
|
|
607
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
608
|
-
status: 422,
|
|
609
|
-
errorCode: 'NTS-DS0-VD1',
|
|
610
|
-
addECToUserMsg: true,
|
|
611
|
-
message:
|
|
612
|
-
userMessage: this.defaultValidationErrorUserMsg
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
// specific Date validation
|
|
616
|
-
if (this.dataParams.modelParams[i].type === 'Date' &&
|
|
617
|
-
!(new Date(this.data[this.dataParams.modelParams[i].key]) instanceof Date)) {
|
|
618
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
619
|
-
status: 422,
|
|
620
|
-
errorCode: 'NTS-DS0-VD2',
|
|
621
|
-
addECToUserMsg: true,
|
|
622
|
-
message:
|
|
623
|
-
userMessage: this.defaultValidationErrorUserMsg
|
|
624
|
-
});
|
|
625
|
-
}
|
|
626
|
-
// call additional validators
|
|
627
|
-
if (this.dataParams.modelParams[i].additionalValidators) {
|
|
628
|
-
for (let j = 0; j < this.dataParams.modelParams[i].additionalValidators.length; j++) {
|
|
629
|
-
this.dataParams.modelParams[i].additionalValidators[j](this.data[this.dataParams.modelParams[i].key]);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
catch (error) {
|
|
635
|
-
if (['NTS-DS0-VD1', 'NTS-DS0-VD2'].includes(error === null || error === void 0 ? void 0 : error.errorCode)) {
|
|
636
|
-
throw error;
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
640
|
-
status: 422,
|
|
641
|
-
errorCode: 'NTS-DS0-VD0',
|
|
642
|
-
addECToUserMsg: true,
|
|
643
|
-
message: `validateForSave was unsuccessful (${this.dataParams.dataName})`,
|
|
644
|
-
userMessage: this.defaultErrorUserMsg,
|
|
645
|
-
error: error
|
|
646
|
-
});
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* setting up dependency dataHook by DynamoBEDataModelParams
|
|
653
|
-
*/
|
|
654
|
-
lookForDependencyDataSettings() {
|
|
655
|
-
const dependencyParam = this.dataParams.modelParams.find((modelParams) => modelParams.isDependencyHook);
|
|
656
|
-
if (dependencyParam) {
|
|
657
|
-
this.depKey = dependencyParam.key;
|
|
658
|
-
if (dependencyParam.dependencyDataName) {
|
|
659
|
-
this.depDBServiceKey = dependencyParam.dependencyDataName;
|
|
660
|
-
}
|
|
661
|
-
if (dependencyParam.unique) {
|
|
662
|
-
this.depKeyIsUnique = true;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
*
|
|
668
|
-
* @returns
|
|
669
|
-
*/
|
|
670
|
-
getDependencyDataDBService() {
|
|
671
|
-
if (!this.depDBServiceKey) {
|
|
672
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
673
|
-
status: 501,
|
|
674
|
-
errorCode: 'NTS-DS0-GDDB0',
|
|
675
|
-
addECToUserMsg: true,
|
|
676
|
-
message: `getDependencyDataDBService was unsuccessful, service key not setted up! (${this.dataParams.dataName}))`,
|
|
677
|
-
userMessage: this.defaultErrorUserMsg
|
|
678
|
-
});
|
|
679
|
-
}
|
|
680
|
-
if (this.depDataDBService) {
|
|
681
|
-
return this.depDataDBService;
|
|
682
|
-
}
|
|
683
|
-
else {
|
|
684
|
-
this.depDataDBService = dynamo_nts_global_service_1.DynamoNTS_GlobalService.getDBServiceByKey(this.depDBServiceKey);
|
|
685
|
-
return this.depDataDBService;
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
exports.DynamoNTS_DataService = DynamoNTS_DataService;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamoNTS_DataService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
6
|
+
const dynamo_nts_global_service_1 = require("./dynamo-nts-global.service");
|
|
7
|
+
/**
|
|
8
|
+
* Basic Data Service that is connected to the relevant DBServices
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* export class UserMatchStatisticsService extends DynamoNTS_DataService<UserMatchStatistics> {
|
|
12
|
+
* constructor(
|
|
13
|
+
* set?: {
|
|
14
|
+
* data?: UserMatchStatistics,
|
|
15
|
+
* issuer?: string,
|
|
16
|
+
* }
|
|
17
|
+
* ) {
|
|
18
|
+
* super(
|
|
19
|
+
* new UserMatchStatistics(set?.data),
|
|
20
|
+
* userMatchStatisticsModelParams
|
|
21
|
+
* );
|
|
22
|
+
* this.issuer = set?.issuer;
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
class DynamoNTS_DataService {
|
|
27
|
+
constructor(
|
|
28
|
+
/**
|
|
29
|
+
* Initial data, this will be used by functions on default
|
|
30
|
+
*/
|
|
31
|
+
data,
|
|
32
|
+
/**
|
|
33
|
+
* DB data prams will be used to connect to usable dbService on GlobalService
|
|
34
|
+
*/
|
|
35
|
+
dataParams,
|
|
36
|
+
/**
|
|
37
|
+
* Initial set for issuer to be able to follow the issuer's activity
|
|
38
|
+
*/
|
|
39
|
+
issuer) {
|
|
40
|
+
this.dataList = [];
|
|
41
|
+
this.defaultErrorUserMsg = `We encountered an unhandled Data Error, ` +
|
|
42
|
+
`\nplease contact the responsible development team.`;
|
|
43
|
+
this.defaultValidationErrorUserMsg = `We encountered an unhandled Validation Error, ` +
|
|
44
|
+
`\nplease contact the responsible development team.`;
|
|
45
|
+
this.dataDBService = dynamo_nts_global_service_1.DynamoNTS_GlobalService.getDBService(dataParams);
|
|
46
|
+
this.data = data;
|
|
47
|
+
this.dataParams = dataParams;
|
|
48
|
+
this.lookForDependencyDataSettings();
|
|
49
|
+
this.issuer = issuer;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* returns all data from database to service dataList
|
|
53
|
+
*/
|
|
54
|
+
getAll(dontSetToService) {
|
|
55
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
try {
|
|
57
|
+
const dataListExists = yield this.dataDBService.getAll().catch(error => {
|
|
58
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GA1') {
|
|
59
|
+
fsm_dynamo_1.Dynamo_Log.warn(`getAll ${this.dataParams.dataName} didn't found any.`);
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
if (!dontSetToService) {
|
|
67
|
+
this.dataList = dataListExists;
|
|
68
|
+
}
|
|
69
|
+
return dataListExists;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
73
|
+
status: 417,
|
|
74
|
+
errorCode: 'NTS-DS0-GA0',
|
|
75
|
+
addECToUserMsg: true,
|
|
76
|
+
message: `getAll was unsuccessful (${this.dataParams.dataName})`,
|
|
77
|
+
userMessage: this.defaultErrorUserMsg,
|
|
78
|
+
error: error
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* @description
|
|
85
|
+
* returns data from database by id
|
|
86
|
+
* also if dontSetToService is false or not setted,
|
|
87
|
+
* the data will be saved to the service, even if its not found
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* If you need to get-save a data, if possible,
|
|
91
|
+
* use db-service update instead.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} id
|
|
94
|
+
* (using id from service.data, if not provided)
|
|
95
|
+
* @param dontSetToService
|
|
96
|
+
*
|
|
97
|
+
* @return {T} data: T
|
|
98
|
+
*/
|
|
99
|
+
getDataById(id, dontSetToService) {
|
|
100
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
try {
|
|
102
|
+
if (!id && !this.data._id) {
|
|
103
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
104
|
+
status: 417,
|
|
105
|
+
errorCode: 'NTS-DS0-GI1',
|
|
106
|
+
addECToUserMsg: true,
|
|
107
|
+
message: `getDataById failed, ID is missing! (maybe you wanted to use getDataByDependencyId() instead...) (${this.dataParams.dataName})`,
|
|
108
|
+
userMessage: this.defaultErrorUserMsg
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const dataExists = yield this.dataDBService.getDataById(id !== null && id !== void 0 ? id : this.data._id);
|
|
112
|
+
if (!dontSetToService) {
|
|
113
|
+
this.data = dataExists;
|
|
114
|
+
}
|
|
115
|
+
return dataExists;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) == 'NTS-DS0-GI1') {
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
123
|
+
status: 417,
|
|
124
|
+
errorCode: 'NTS-DS0-GI0',
|
|
125
|
+
addECToUserMsg: true,
|
|
126
|
+
message: `getDataById was unsuccessful (${this.dataParams.dataName})`,
|
|
127
|
+
userMessage: this.defaultErrorUserMsg,
|
|
128
|
+
error: error
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* returns data from database by dependencyId to the service
|
|
136
|
+
* (using id from service.data, if not provided)
|
|
137
|
+
* @param dependencyId
|
|
138
|
+
*/
|
|
139
|
+
getDataByDependencyId(dependencyId, dontSetToService) {
|
|
140
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
try {
|
|
142
|
+
if (!this.depKey) {
|
|
143
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
144
|
+
status: 417,
|
|
145
|
+
errorCode: 'NTS-DS0-GD1',
|
|
146
|
+
addECToUserMsg: true,
|
|
147
|
+
message: `getDataByDependencyId failed, dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
|
|
148
|
+
userMessage: this.defaultErrorUserMsg
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
if (!dependencyId && !this.data[this.depKey]) {
|
|
152
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
153
|
+
status: 417,
|
|
154
|
+
errorCode: 'NTS-DS0-GD2',
|
|
155
|
+
addECToUserMsg: true,
|
|
156
|
+
message: `getDataByDependencyId failed, ${this.depKey} is missing! (${this.dataParams.dataName})`,
|
|
157
|
+
userMessage: this.defaultErrorUserMsg
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const dataExists = yield this.dataDBService.getDataByDependencyId(dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]).catch(error => {
|
|
161
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GD2') {
|
|
162
|
+
fsm_dynamo_1.Dynamo_Log.warn(`getDataByDependencyId failed; ${this.dataParams.dataName} (${this.depKey}: ${dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]}) didn't found any.`);
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
if (!dontSetToService) {
|
|
170
|
+
this.data = dataExists;
|
|
171
|
+
}
|
|
172
|
+
return dataExists;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (['NTS-DS0-GD1', 'NTS-DS0-GD2'].includes(error === null || error === void 0 ? void 0 : error.errorCode)) {
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
180
|
+
status: 417,
|
|
181
|
+
errorCode: 'NTS-DS0-GD0',
|
|
182
|
+
addECToUserMsg: true,
|
|
183
|
+
message: `getDataByDependencyId was unsuccessful (${this.dataParams.dataName})`,
|
|
184
|
+
userMessage: this.defaultErrorUserMsg,
|
|
185
|
+
error: error
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* returns dataList from database by dependencyId to the service
|
|
193
|
+
* @param dependencyId
|
|
194
|
+
*/
|
|
195
|
+
getDataListByDependencyId(dependencyId, dontSetToService) {
|
|
196
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
try {
|
|
198
|
+
if (!this.depKey) {
|
|
199
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
200
|
+
status: 417,
|
|
201
|
+
errorCode: 'NTS-DS0-GLD1',
|
|
202
|
+
addECToUserMsg: true,
|
|
203
|
+
message: `dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
|
|
204
|
+
userMessage: this.defaultErrorUserMsg
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (!dependencyId && !this.data[this.depKey]) {
|
|
208
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
209
|
+
status: 417,
|
|
210
|
+
errorCode: 'NTS-DS0-GLD2',
|
|
211
|
+
addECToUserMsg: true,
|
|
212
|
+
message: `getDataListByDependencyId failed, ${this.depKey} is missing (${this.dataParams.dataName})`,
|
|
213
|
+
userMessage: this.defaultErrorUserMsg
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const dataListExists = yield this.dataDBService.getDataListByDependencyId(dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]).catch(error => {
|
|
217
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GLD2') {
|
|
218
|
+
fsm_dynamo_1.Dynamo_Log.warn(`getDataListByDependencyId ${this.dataParams.dataName} (${this.depKey}: ${dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]}) didn't found any.`);
|
|
219
|
+
return [];
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
if (!dontSetToService) {
|
|
226
|
+
this.dataList = dataListExists;
|
|
227
|
+
}
|
|
228
|
+
return dataListExists;
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
if (['NTS-DS0-GLD1', 'NTS-DS0-GLD2'].includes(error === null || error === void 0 ? void 0 : error.errorCode)) {
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
236
|
+
status: 417,
|
|
237
|
+
errorCode: 'NTS-DS0-GLD0',
|
|
238
|
+
addECToUserMsg: true,
|
|
239
|
+
message: `getDataListByDependencyId was unsuccessful (${this.dataParams.dataName})`,
|
|
240
|
+
userMessage: this.defaultErrorUserMsg,
|
|
241
|
+
error: error
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
*
|
|
249
|
+
* // findOne desc:
|
|
250
|
+
*
|
|
251
|
+
* Find the data first by any of its parameters,
|
|
252
|
+
* also if dontSetToService is false or not setted,
|
|
253
|
+
* the data will be saved to the service, even if non found
|
|
254
|
+
*
|
|
255
|
+
* @param filter if you can, use unique parameters for find!
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* // by email:
|
|
259
|
+
* { email: email }
|
|
260
|
+
* //
|
|
261
|
+
* @example
|
|
262
|
+
* // or by id that is in list:
|
|
263
|
+
* { userIds: { $in: this.userId } }
|
|
264
|
+
* //
|
|
265
|
+
* @example
|
|
266
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
267
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
268
|
+
* // further tools (syntax matches with $gt):
|
|
269
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
270
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
271
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
272
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
273
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
274
|
+
* //
|
|
275
|
+
* @returns {T} data: T
|
|
276
|
+
*/
|
|
277
|
+
findData(filterBy, dontSetToService) {
|
|
278
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
try {
|
|
280
|
+
const dataExists = yield this.dataDBService.findOne(filterBy).catch(error => {
|
|
281
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-FO1') {
|
|
282
|
+
fsm_dynamo_1.Dynamo_Log.warn(`findData ${this.dataParams.dataName} didn't found any.`);
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
if (!dontSetToService) {
|
|
290
|
+
this.data = dataExists;
|
|
291
|
+
}
|
|
292
|
+
return dataExists;
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
296
|
+
status: 417,
|
|
297
|
+
errorCode: 'NTS-DS0-FD0',
|
|
298
|
+
addECToUserMsg: true,
|
|
299
|
+
message: `findData was unsuccessful (${this.dataParams.dataName})`,
|
|
300
|
+
userMessage: this.defaultErrorUserMsg,
|
|
301
|
+
error: error
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
*
|
|
308
|
+
* // find desc:
|
|
309
|
+
*
|
|
310
|
+
* Find the data first by any of its parameters,
|
|
311
|
+
* also if dontSetToService is false or not setted,
|
|
312
|
+
* the data will be saved to the service, even if non found
|
|
313
|
+
*
|
|
314
|
+
* @param filter if you can, use unique parameters for find!
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* // by email:
|
|
318
|
+
* { email: email }
|
|
319
|
+
* //
|
|
320
|
+
* @example
|
|
321
|
+
* // or by id that is in list:
|
|
322
|
+
* { userIds: { $in: this.userId } }
|
|
323
|
+
* //
|
|
324
|
+
* @example
|
|
325
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
326
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
327
|
+
* // further tools (syntax matches with $gt):
|
|
328
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
329
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
330
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
331
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
332
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
333
|
+
* //
|
|
334
|
+
* @returns {T[]} dataList: T[]
|
|
335
|
+
*/
|
|
336
|
+
findDatas(filterBy, dontSetToService) {
|
|
337
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
338
|
+
try {
|
|
339
|
+
const dataListExists = yield this.dataDBService.find(filterBy).catch(error => {
|
|
340
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-F1') {
|
|
341
|
+
fsm_dynamo_1.Dynamo_Log.warn(`findDatas ${this.dataParams.dataName} didn't found any.`);
|
|
342
|
+
return [];
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
throw error;
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
if (!dontSetToService) {
|
|
349
|
+
this.dataList = dataListExists;
|
|
350
|
+
}
|
|
351
|
+
return dataListExists;
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
355
|
+
status: 417,
|
|
356
|
+
errorCode: 'NTS-DS0-FDS0',
|
|
357
|
+
addECToUserMsg: true,
|
|
358
|
+
message: `findDatas was unsuccessful (${this.dataParams.dataName})`,
|
|
359
|
+
userMessage: this.defaultErrorUserMsg,
|
|
360
|
+
error: error
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* This function uses the dataDBService.updateOne function.
|
|
367
|
+
* This uses updateBy if setted, or data._id if its setted or this.data[this.dependencyKey]
|
|
368
|
+
* @param set
|
|
369
|
+
*
|
|
370
|
+
* // updateOne desc:
|
|
371
|
+
*
|
|
372
|
+
* Find the data first by any of its parameters, throws error if not found
|
|
373
|
+
* @param filter This uses the basic Mongoose updateOne.
|
|
374
|
+
* If you can, use unique parameters for find!
|
|
375
|
+
* @example
|
|
376
|
+
* // by email:
|
|
377
|
+
* { email: email }
|
|
378
|
+
* //
|
|
379
|
+
* @example
|
|
380
|
+
* // or by id that is in list:
|
|
381
|
+
* { userIds: { $in: this.userId } }
|
|
382
|
+
* //
|
|
383
|
+
* @example
|
|
384
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
385
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
386
|
+
* // further tools (syntax matches with $gt):
|
|
387
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
388
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
389
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
390
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
391
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
392
|
+
* //
|
|
393
|
+
*
|
|
394
|
+
* @param update this uses the basic Mongoose updateOne
|
|
395
|
+
* @example
|
|
396
|
+
* // increase a specific value (here by 15):
|
|
397
|
+
* { $inc: { popularity: 15 } }
|
|
398
|
+
* //
|
|
399
|
+
* @example
|
|
400
|
+
* // or add element to a list:
|
|
401
|
+
* { $push: { reactions: this.newReaction }
|
|
402
|
+
* // or add multiple elements to a list
|
|
403
|
+
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
404
|
+
* //
|
|
405
|
+
* @example
|
|
406
|
+
* // or all at once
|
|
407
|
+
* {
|
|
408
|
+
* $inc: { popularity: this.newVote.amount },
|
|
409
|
+
* emailVerified: true,
|
|
410
|
+
* $push: { reactions: this.newReaction }
|
|
411
|
+
* }
|
|
412
|
+
* // further tools (syntax matches with $inc):
|
|
413
|
+
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
414
|
+
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
415
|
+
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
416
|
+
* $mul: // Multiplies the value of the field by the specified amount.
|
|
417
|
+
* $rename: // Renames a field.
|
|
418
|
+
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
419
|
+
* //
|
|
420
|
+
*/
|
|
421
|
+
updateData(set) {
|
|
422
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
423
|
+
try {
|
|
424
|
+
if (set.filterBy) {
|
|
425
|
+
yield this.dataDBService.updateOne(set.filterBy, set.update, this.issuer);
|
|
426
|
+
}
|
|
427
|
+
else if (this.data._id) {
|
|
428
|
+
yield this.dataDBService.updateOne({ _id: this.data._id }, set.update, this.issuer);
|
|
429
|
+
}
|
|
430
|
+
else if (this.depKey && this.data[this.depKey]) {
|
|
431
|
+
yield this.dataDBService.updateOne({ [this.depKey]: this.data[this.depKey] }, set.update, this.issuer);
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
435
|
+
status: 417,
|
|
436
|
+
errorCode: 'NTS-DS0-UD1',
|
|
437
|
+
addECToUserMsg: true,
|
|
438
|
+
message: `no usable parameter provided for updateData; no updateBy, no id, no dependencyId (${this.dataParams.dataName})`,
|
|
439
|
+
userMessage: this.defaultErrorUserMsg,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
catch (error) {
|
|
444
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) == 'NTS-DS0-UD1') {
|
|
445
|
+
throw error;
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
449
|
+
status: 417,
|
|
450
|
+
errorCode: 'NTS-DS0-UD0',
|
|
451
|
+
addECToUserMsg: true,
|
|
452
|
+
message: `updateData was unsuccessful (${this.dataParams.dataName})`,
|
|
453
|
+
userMessage: this.defaultErrorUserMsg,
|
|
454
|
+
error: error
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* modifies data if the data have ID and already exists in the DB,
|
|
462
|
+
* creates new if the ID is not present or cant find in DB,
|
|
463
|
+
* and if dependency data setted up, will check before creation,
|
|
464
|
+
*
|
|
465
|
+
* @warning
|
|
466
|
+
* but the proper way to update data, if you use update method instead,
|
|
467
|
+
* this way, you can avoid data override errors
|
|
468
|
+
* (when you simultaneously trying to change the same data's
|
|
469
|
+
* different values from different flows)
|
|
470
|
+
*/
|
|
471
|
+
saveData() {
|
|
472
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
473
|
+
try {
|
|
474
|
+
if (!this.data) {
|
|
475
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
476
|
+
status: 417,
|
|
477
|
+
errorCode: 'NTS-DS0-SD4',
|
|
478
|
+
addECToUserMsg: true,
|
|
479
|
+
message: `saveData was unsuccessful: no data to save!, (${this.dataParams.dataName})`,
|
|
480
|
+
userMessage: this.defaultErrorUserMsg
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
if (!this.data._id && (!this.depKey || !this.data[this.depKey])) {
|
|
484
|
+
// if ID of dependencyID is not present, data not exists, create new data
|
|
485
|
+
this.data = yield this.dataDBService.createData(this.data, this.issuer);
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
let dataExists;
|
|
489
|
+
// check if data already exists with the specific ID
|
|
490
|
+
if (this.data._id) {
|
|
491
|
+
dataExists = yield this.getDataById(null, true);
|
|
492
|
+
if (dataExists) {
|
|
493
|
+
// if data exists do modify
|
|
494
|
+
this.data = yield this.dataDBService.modifyData(this.data, this.issuer);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
499
|
+
status: 417,
|
|
500
|
+
errorCode: 'NTS-DS0-SD1',
|
|
501
|
+
addECToUserMsg: true,
|
|
502
|
+
message: `saveData was unsuccessful: provided ID not exists (id: ${this.data._id}, ${this.dataParams.dataName})`,
|
|
503
|
+
userMessage: this.defaultErrorUserMsg
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (this.depKey) {
|
|
508
|
+
if (!this.data[this.depKey]) {
|
|
509
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
510
|
+
status: 417,
|
|
511
|
+
errorCode: 'NTS-DS0-SD2',
|
|
512
|
+
addECToUserMsg: true,
|
|
513
|
+
message: `saveData was unsuccessful: dependency data id missing from data (key: ${this.depKey}, ${this.dataParams.dataName})`,
|
|
514
|
+
userMessage: this.defaultErrorUserMsg
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
if (this.depKeyIsUnique) {
|
|
518
|
+
dataExists = yield this.getDataByDependencyId(null, true);
|
|
519
|
+
if (dataExists) {
|
|
520
|
+
// if data exists do modify
|
|
521
|
+
this.data = yield this.dataDBService.modifyData(this.data, this.issuer);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
// if data not exists check that dependency already exists for this
|
|
526
|
+
const dependencyExists = yield this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
|
|
527
|
+
if (!dependencyExists) {
|
|
528
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
529
|
+
status: 417,
|
|
530
|
+
errorCode: 'NTS-DS0-SD3',
|
|
531
|
+
addECToUserMsg: true,
|
|
532
|
+
message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]}, ${this.dataParams.dataName})`,
|
|
533
|
+
userMessage: this.defaultErrorUserMsg
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
// if data not exists create new data
|
|
540
|
+
this.data = yield this.dataDBService.createData(this.data, this.issuer);
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
if (['NTS-DS0-SD1', 'NTS-DS0-SD2'].includes(error === null || error === void 0 ? void 0 : error.errorCode)) {
|
|
544
|
+
throw error;
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
548
|
+
status: 417,
|
|
549
|
+
errorCode: 'NTS-DS0-SD0',
|
|
550
|
+
addECToUserMsg: true,
|
|
551
|
+
message: `saveData was unsuccessful (${this.dataParams.dataName})`,
|
|
552
|
+
userMessage: this.defaultErrorUserMsg,
|
|
553
|
+
error: error
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
/**
|
|
560
|
+
* permanently deletes data from database by data._id
|
|
561
|
+
*/
|
|
562
|
+
deleteData() {
|
|
563
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
564
|
+
try {
|
|
565
|
+
if (!this.data._id) {
|
|
566
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
567
|
+
status: 417,
|
|
568
|
+
errorCode: 'NTS-DS0-DD1',
|
|
569
|
+
addECToUserMsg: true,
|
|
570
|
+
message: `deleteData failed, ID is missing! (${this.dataParams.dataName})`,
|
|
571
|
+
userMessage: this.defaultErrorUserMsg,
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
yield this.dataDBService.deleteDataById(this.data._id);
|
|
575
|
+
}
|
|
576
|
+
catch (error) {
|
|
577
|
+
if ((error === null || error === void 0 ? void 0 : error.errorCode) == 'NTS-DS0-DD1') {
|
|
578
|
+
throw error;
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
582
|
+
status: 417,
|
|
583
|
+
errorCode: 'NTS-DS0-DD0',
|
|
584
|
+
addECToUserMsg: true,
|
|
585
|
+
message: `deleteData was unsuccessful (${this.dataParams.dataName})`,
|
|
586
|
+
userMessage: this.defaultErrorUserMsg,
|
|
587
|
+
error: error
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* validation of data, for modify and create, by the ModelParams
|
|
595
|
+
*/
|
|
596
|
+
validateForSave() {
|
|
597
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
598
|
+
try {
|
|
599
|
+
for (let i = 0; i < this.dataParams.modelParams.length; i++) {
|
|
600
|
+
// basic required validations
|
|
601
|
+
if ((this.dataParams.modelParams[i].required &&
|
|
602
|
+
(this.data[this.dataParams.modelParams[i].key] === null ||
|
|
603
|
+
this.data[this.dataParams.modelParams[i].key] === undefined)) ||
|
|
604
|
+
(this.dataParams.modelParams[i].index &&
|
|
605
|
+
(this.data[this.dataParams.modelParams[i].key] === null ||
|
|
606
|
+
this.data[this.dataParams.modelParams[i].key] === undefined))) {
|
|
607
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
608
|
+
status: 422,
|
|
609
|
+
errorCode: 'NTS-DS0-VD1',
|
|
610
|
+
addECToUserMsg: true,
|
|
611
|
+
message: `validateForSave failed, ${this.dataParams.modelParams[i].key} is missing! (${this.dataParams.modelParams[i].required ? 'required' : 'index'}) (${this.dataParams.dataName})`,
|
|
612
|
+
userMessage: this.defaultValidationErrorUserMsg
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
// specific Date validation
|
|
616
|
+
if (this.dataParams.modelParams[i].type === 'Date' &&
|
|
617
|
+
!(new Date(this.data[this.dataParams.modelParams[i].key]) instanceof Date)) {
|
|
618
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
619
|
+
status: 422,
|
|
620
|
+
errorCode: 'NTS-DS0-VD2',
|
|
621
|
+
addECToUserMsg: true,
|
|
622
|
+
message: `validateForSave failed, ${this.dataParams.modelParams[i].key} is not a date! (${this.dataParams.dataName})`,
|
|
623
|
+
userMessage: this.defaultValidationErrorUserMsg
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
// call additional validators
|
|
627
|
+
if (this.dataParams.modelParams[i].additionalValidators) {
|
|
628
|
+
for (let j = 0; j < this.dataParams.modelParams[i].additionalValidators.length; j++) {
|
|
629
|
+
this.dataParams.modelParams[i].additionalValidators[j](this.data[this.dataParams.modelParams[i].key]);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
catch (error) {
|
|
635
|
+
if (['NTS-DS0-VD1', 'NTS-DS0-VD2'].includes(error === null || error === void 0 ? void 0 : error.errorCode)) {
|
|
636
|
+
throw error;
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
640
|
+
status: 422,
|
|
641
|
+
errorCode: 'NTS-DS0-VD0',
|
|
642
|
+
addECToUserMsg: true,
|
|
643
|
+
message: `validateForSave was unsuccessful (${this.dataParams.dataName})`,
|
|
644
|
+
userMessage: this.defaultErrorUserMsg,
|
|
645
|
+
error: error
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* setting up dependency dataHook by DynamoBEDataModelParams
|
|
653
|
+
*/
|
|
654
|
+
lookForDependencyDataSettings() {
|
|
655
|
+
const dependencyParam = this.dataParams.modelParams.find((modelParams) => modelParams.isDependencyHook);
|
|
656
|
+
if (dependencyParam) {
|
|
657
|
+
this.depKey = dependencyParam.key;
|
|
658
|
+
if (dependencyParam.dependencyDataName) {
|
|
659
|
+
this.depDBServiceKey = dependencyParam.dependencyDataName;
|
|
660
|
+
}
|
|
661
|
+
if (dependencyParam.unique) {
|
|
662
|
+
this.depKeyIsUnique = true;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
*
|
|
668
|
+
* @returns
|
|
669
|
+
*/
|
|
670
|
+
getDependencyDataDBService() {
|
|
671
|
+
if (!this.depDBServiceKey) {
|
|
672
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
673
|
+
status: 501,
|
|
674
|
+
errorCode: 'NTS-DS0-GDDB0',
|
|
675
|
+
addECToUserMsg: true,
|
|
676
|
+
message: `getDependencyDataDBService was unsuccessful, service key not setted up! (${this.dataParams.dataName}))`,
|
|
677
|
+
userMessage: this.defaultErrorUserMsg
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
if (this.depDataDBService) {
|
|
681
|
+
return this.depDataDBService;
|
|
682
|
+
}
|
|
683
|
+
else {
|
|
684
|
+
this.depDataDBService = dynamo_nts_global_service_1.DynamoNTS_GlobalService.getDBServiceByKey(this.depDBServiceKey);
|
|
685
|
+
return this.depDataDBService;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
exports.DynamoNTS_DataService = DynamoNTS_DataService;
|
|
690
690
|
//# sourceMappingURL=dynamo-nts-data.service.js.map
|