@futdevpro/nts-dynamo 1.6.58 → 1.6.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_constants/mocks/app-extended-server.mock.js +8 -13
- package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
- package/lib/_constants/mocks/app-server.mock.js +4 -9
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/auth-service.mock.js +3 -10
- package/lib/_constants/mocks/auth-service.mock.js.map +1 -1
- package/lib/_constants/mocks/data-model.mock.js +17 -0
- package/lib/_constants/mocks/data-model.mock.js.map +1 -1
- package/lib/_constants/mocks/email-service-collection.mock.js +1 -4
- package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -1
- package/lib/_constants/mocks/endpoint.mock.js +12 -13
- package/lib/_constants/mocks/endpoint.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-client.mock.js +2 -3
- package/lib/_constants/mocks/socket-client.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.js +2 -5
- package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
- package/lib/_enums/http/socket-event-type.enum.d.ts +1 -0
- package/lib/_enums/http/socket-event-type.enum.d.ts.map +1 -1
- package/lib/_enums/http/socket-event-type.enum.js +1 -0
- package/lib/_enums/http/socket-event-type.enum.js.map +1 -1
- package/lib/_models/control-models/api-call-params.control-model.js +32 -0
- package/lib/_models/control-models/api-call-params.control-model.js.map +1 -1
- package/lib/_models/control-models/app-params.control-model.js +31 -4
- package/lib/_models/control-models/app-params.control-model.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.js +3 -5
- package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model.js +4 -6
- package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +91 -88
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-client-service-params.control-model.js +8 -5
- package/lib/_models/control-models/socket-client-service-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.js +35 -34
- package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js +14 -11
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-server-service-params.control-model.js +3 -0
- package/lib/_models/control-models/socket-server-service-params.control-model.js.map +1 -1
- package/lib/_models/control-models/system-control.control-model.js +3 -5
- package/lib/_models/control-models/system-control.control-model.js.map +1 -1
- package/lib/_modules/custom-data/custom-data.controller.js +6 -7
- package/lib/_modules/custom-data/custom-data.controller.js.map +1 -1
- package/lib/_modules/test/test.controller.js +12 -13
- package/lib/_modules/test/test.controller.js.map +1 -1
- package/lib/_modules/usage/usage.controller.js +15 -14
- package/lib/_modules/usage/usage.controller.js.map +1 -1
- package/lib/_modules/usage/usage.data-service.js +88 -96
- package/lib/_modules/usage/usage.data-service.js.map +1 -1
- package/lib/_services/base/data.service.d.ts +2 -0
- package/lib/_services/base/data.service.d.ts.map +1 -1
- package/lib/_services/base/data.service.js +376 -253
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/base/db.service.d.ts +1 -0
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +321 -247
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/base/singleton.service.js +2 -0
- package/lib/_services/base/singleton.service.js.map +1 -1
- package/lib/_services/core/api.service.js +185 -188
- package/lib/_services/core/api.service.js.map +1 -1
- package/lib/_services/core/auth.service.js +3 -3
- package/lib/_services/core/auth.service.js.map +1 -1
- package/lib/_services/core/email.service.js +103 -88
- package/lib/_services/core/email.service.js.map +1 -1
- package/lib/_services/core/global.service.d.ts +1 -1
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +41 -41
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/route/controller.service.js +28 -0
- package/lib/_services/route/controller.service.js.map +1 -1
- package/lib/_services/route/routing-module.service.js +11 -8
- package/lib/_services/route/routing-module.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.js +241 -247
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app-extended.server.spec.js +18 -19
- package/lib/_services/server/app-extended.server.spec.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +2 -1
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +413 -410
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/server/app.server.spec.js +12 -13
- package/lib/_services/server/app.server.spec.js.map +1 -1
- package/lib/_services/shared.static-service.js +15 -17
- package/lib/_services/shared.static-service.js.map +1 -1
- package/lib/_services/socket/socket-client.service.js +134 -145
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.js +294 -263
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +19 -21
- package/src/_enums/http/socket-event-type.enum.ts +2 -0
- package/src/_models/control-models/socket-presence.control-model.ts +8 -2
- package/src/_services/base/data.service.ts +79 -0
- package/src/_services/base/db.service.ts +47 -28
- package/src/_services/core/global.service.ts +4 -2
- package/src/_services/server/app-extended.server.ts +2 -2
- package/src/_services/server/app.server.ts +18 -4
- package/tsconfig.json +2 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DynamoNTS_DataService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
4
|
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
6
5
|
const global_service_1 = require("../core/global.service");
|
|
7
6
|
/**
|
|
@@ -24,6 +23,20 @@ const global_service_1 = require("../core/global.service");
|
|
|
24
23
|
* }
|
|
25
24
|
*/
|
|
26
25
|
class DynamoNTS_DataService {
|
|
26
|
+
serviceName;
|
|
27
|
+
dataDBService;
|
|
28
|
+
data;
|
|
29
|
+
dataList = [];
|
|
30
|
+
issuer;
|
|
31
|
+
depKey;
|
|
32
|
+
depDBServiceKey;
|
|
33
|
+
depKeyIsUnique;
|
|
34
|
+
depDataDBService;
|
|
35
|
+
dataParams;
|
|
36
|
+
defaultErrorUserMsg = `We encountered an unhandled Data Service Error, ` +
|
|
37
|
+
`\nplease contact the responsible development team.`;
|
|
38
|
+
defaultValidationErrorUserMsg = `We encountered an unhandled Validation Error, ` +
|
|
39
|
+
`\nplease contact the responsible development team.`;
|
|
27
40
|
constructor(
|
|
28
41
|
/**
|
|
29
42
|
* Initial data, this will be used by functions on default
|
|
@@ -37,14 +50,8 @@ class DynamoNTS_DataService {
|
|
|
37
50
|
* Initial set for issuer to be able to follow the issuer's activity
|
|
38
51
|
*/
|
|
39
52
|
issuer) {
|
|
40
|
-
var _a;
|
|
41
|
-
this.dataList = [];
|
|
42
|
-
this.defaultErrorUserMsg = `We encountered an unhandled Data Service Error, ` +
|
|
43
|
-
`\nplease contact the responsible development team.`;
|
|
44
|
-
this.defaultValidationErrorUserMsg = `We encountered an unhandled Validation Error, ` +
|
|
45
|
-
`\nplease contact the responsible development team.`;
|
|
46
53
|
try {
|
|
47
|
-
this.serviceName =
|
|
54
|
+
this.serviceName = this.constructor?.name;
|
|
48
55
|
this.dataDBService = global_service_1.DynamoNTS_GlobalService.getDBService(dataParams);
|
|
49
56
|
this.data = data;
|
|
50
57
|
this.dataParams = dataParams;
|
|
@@ -52,33 +59,34 @@ class DynamoNTS_DataService {
|
|
|
52
59
|
this.issuer = issuer;
|
|
53
60
|
}
|
|
54
61
|
catch (error) {
|
|
55
|
-
fsm_dynamo_1.Dynamo_Log.error(`\nDynamoNTS_DataService ERROR, The dataService construction failed for ${dataParams
|
|
62
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nDynamoNTS_DataService ERROR, The dataService construction failed for ${dataParams?.dataName}. ${this.serviceName}`, new Error());
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
/**
|
|
59
66
|
* returns all data from database to service dataList
|
|
60
67
|
*/
|
|
61
|
-
getAll(dontSetToService) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return [];
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
if (!dontSetToService) {
|
|
74
|
-
this.dataList = dataListExists;
|
|
68
|
+
async getAll(dontSetToService) {
|
|
69
|
+
try {
|
|
70
|
+
const dataListExists = await this.dataDBService.getAll().catch(error => {
|
|
71
|
+
if (error?.errorCode === 'NTS-DBS-GA1') {
|
|
72
|
+
fsm_dynamo_1.Dynamo_Log.warn(`getAll ${this.dataParams.dataName} didn't found any.`);
|
|
73
|
+
return [];
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
else {
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
if (!dontSetToService) {
|
|
80
|
+
this.dataList = dataListExists;
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
+
return dataListExists;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
86
|
+
...this._getDefaultErrorSettings('getAll', error),
|
|
87
|
+
errorCode: 'NTS-DS0-GA0',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
82
90
|
}
|
|
83
91
|
/**
|
|
84
92
|
* @description
|
|
@@ -96,102 +104,179 @@ class DynamoNTS_DataService {
|
|
|
96
104
|
*
|
|
97
105
|
* @return {T} data: T
|
|
98
106
|
*/
|
|
99
|
-
getDataById(id, dontSetToService) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (!dontSetToService) {
|
|
107
|
-
this.data = dataExists;
|
|
108
|
-
}
|
|
109
|
-
return dataExists;
|
|
107
|
+
async getDataById(id, dontSetToService) {
|
|
108
|
+
try {
|
|
109
|
+
if (!id && !this.data._id) {
|
|
110
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
111
|
+
...this._getDefaultErrorSettings('getDataById', new Error(`getDataById failed, ID is missing! (maybe you wanted to use getDataByDependencyId() instead...) (${this.dataParams.dataName})`)),
|
|
112
|
+
errorCode: 'NTS-DS0-GI1',
|
|
113
|
+
});
|
|
110
114
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('getDataById', error)), { errorCode: 'NTS-DS0-GI0' }));
|
|
117
|
-
}
|
|
115
|
+
const dataExists = await this.dataDBService.getDataById(id ?? this.data._id);
|
|
116
|
+
if (!dontSetToService) {
|
|
117
|
+
this.data = dataExists;
|
|
118
118
|
}
|
|
119
|
-
|
|
119
|
+
return dataExists;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (error?.errorCode == 'NTS-DS0-GI1') {
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
127
|
+
...this._getDefaultErrorSettings('getDataById', error),
|
|
128
|
+
errorCode: 'NTS-DS0-GI0',
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async getDataByIds(ids, dontSetToService) {
|
|
134
|
+
try {
|
|
135
|
+
if (!ids) {
|
|
136
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
137
|
+
...this._getDefaultErrorSettings('getDataByIds', new Error(`getDataByIds failed, ids is missing! (${this.dataParams.dataName})`)),
|
|
138
|
+
errorCode: 'NTS-DS0-GIS1',
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (ids.length === 0) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
const datas = await this.dataDBService.find({ _id: { $in: ids, }, });
|
|
145
|
+
if (!dontSetToService) {
|
|
146
|
+
this.dataList = datas;
|
|
147
|
+
}
|
|
148
|
+
return datas;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
152
|
+
...this._getDefaultErrorSettings('getDataByIds', error),
|
|
153
|
+
errorCode: 'NTS-DS0-GIS0',
|
|
154
|
+
});
|
|
155
|
+
}
|
|
120
156
|
}
|
|
121
157
|
/**
|
|
122
158
|
* returns data from database by dependencyId to the service
|
|
123
159
|
* (using id from service.data, if not provided)
|
|
124
160
|
* @param dependencyId
|
|
125
161
|
*/
|
|
126
|
-
getDataByDependencyId(dependencyId, dontSetToService) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (!dependencyId && !this.data[this.depKey]) {
|
|
133
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('getDataByDependencyId', new Error(`getDataByDependencyId failed, ${this.depKey} is missing! (${this.dataParams.dataName})`))), { errorCode: 'NTS-DS0-GD2' }));
|
|
134
|
-
}
|
|
135
|
-
const dataExists = yield this.dataDBService.getDataByDependencyId(dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]).catch(error => {
|
|
136
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GD2') {
|
|
137
|
-
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.`);
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
throw error;
|
|
142
|
-
}
|
|
162
|
+
async getDataByDependencyId(dependencyId, dontSetToService) {
|
|
163
|
+
try {
|
|
164
|
+
if (!this.depKey) {
|
|
165
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
166
|
+
...this._getDefaultErrorSettings('getDataByDependencyId', new Error(`getDataByDependencyId failed, dependencyKey is missing from service! (${this.dataParams.dataName})`)),
|
|
167
|
+
errorCode: 'NTS-DS0-GD1',
|
|
143
168
|
});
|
|
144
|
-
if (!dontSetToService) {
|
|
145
|
-
this.data = dataExists;
|
|
146
|
-
}
|
|
147
|
-
return dataExists;
|
|
148
169
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
170
|
+
if (!dependencyId && !this.data[this.depKey]) {
|
|
171
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
172
|
+
...this._getDefaultErrorSettings('getDataByDependencyId', new Error(`getDataByDependencyId failed, ${this.depKey} is missing! (${this.dataParams.dataName})`)),
|
|
173
|
+
errorCode: 'NTS-DS0-GD2',
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
const dataExists = await this.dataDBService.getDataByDependencyId(dependencyId ?? this.data[this.depKey]).catch(error => {
|
|
177
|
+
if (error?.errorCode === 'NTS-DBS-GD2') {
|
|
178
|
+
fsm_dynamo_1.Dynamo_Log.warn(`getDataByDependencyId failed; ${this.dataParams.dataName} (${this.depKey}: ${dependencyId ?? this.data[this.depKey]}) didn't found any.`);
|
|
179
|
+
return null;
|
|
152
180
|
}
|
|
153
181
|
else {
|
|
154
|
-
throw
|
|
182
|
+
throw error;
|
|
155
183
|
}
|
|
184
|
+
});
|
|
185
|
+
if (!dontSetToService) {
|
|
186
|
+
this.data = dataExists;
|
|
187
|
+
}
|
|
188
|
+
return dataExists;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
if (['NTS-DS0-GD1', 'NTS-DS0-GD2'].includes(error?.errorCode)) {
|
|
192
|
+
throw error;
|
|
156
193
|
}
|
|
157
|
-
|
|
194
|
+
else {
|
|
195
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
196
|
+
...this._getDefaultErrorSettings('getDataByDependencyId', error),
|
|
197
|
+
errorCode: 'NTS-DS0-GD0',
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async getDatasByDependencyIds(dependencyIds, dontSetToService) {
|
|
203
|
+
try {
|
|
204
|
+
if (!this.depKey) {
|
|
205
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
206
|
+
...this._getDefaultErrorSettings('getDatasByDependencyIds', new Error(`getDatasByDependencyIds failed, dependencyKey is missing from service! (${this.dataParams.dataName})`)),
|
|
207
|
+
errorCode: 'NTS-DS0-GDS1',
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (!dependencyIds) {
|
|
211
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
212
|
+
...this._getDefaultErrorSettings('getDatasByDependencyIds', new Error(`getDatasByDependencyIds failed, dependencyIds is missing! (${this.dataParams.dataName})`)),
|
|
213
|
+
errorCode: 'NTS-DS0-GDS2',
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (dependencyIds.length === 0) {
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
const datas = await this.dataDBService.getDatasByDependencyIds(dependencyIds);
|
|
220
|
+
if (!dontSetToService) {
|
|
221
|
+
this.dataList = datas;
|
|
222
|
+
}
|
|
223
|
+
return datas;
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
if (['NTS-DS0-GDS1', 'NTS-DS0-GDS2'].includes(error?.errorCode)) {
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
231
|
+
...this._getDefaultErrorSettings('getDatasByDependencyIds', error),
|
|
232
|
+
errorCode: 'NTS-DS0-GDS0',
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
158
236
|
}
|
|
159
237
|
/**
|
|
160
238
|
* returns dataList from database by dependencyId to the service
|
|
161
239
|
* @param dependencyId
|
|
162
240
|
*/
|
|
163
|
-
getDataListByDependencyId(dependencyId, dontSetToService) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (!dependencyId && !this.data[this.depKey]) {
|
|
170
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('getDataListByDependencyId', new Error(`getDataListByDependencyId failed, ${this.depKey} is missing! (${this.dataParams.dataName})`))), { errorCode: 'NTS-DS0-GLD2' }));
|
|
171
|
-
}
|
|
172
|
-
const dataListExists = yield this.dataDBService.getDataListByDependencyId(dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]).catch(error => {
|
|
173
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GLD2') {
|
|
174
|
-
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.`);
|
|
175
|
-
return [];
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
throw error;
|
|
179
|
-
}
|
|
241
|
+
async getDataListByDependencyId(dependencyId, dontSetToService) {
|
|
242
|
+
try {
|
|
243
|
+
if (!this.depKey) {
|
|
244
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
245
|
+
...this._getDefaultErrorSettings('getDataListByDependencyId', new Error(`getDataListByDependencyId failed, dependencyKey is missing from service! (${this.dataParams.dataName})`)),
|
|
246
|
+
errorCode: 'NTS-DS0-GLD1',
|
|
180
247
|
});
|
|
181
|
-
if (!dontSetToService) {
|
|
182
|
-
this.dataList = dataListExists;
|
|
183
|
-
}
|
|
184
|
-
return dataListExists;
|
|
185
248
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
249
|
+
if (!dependencyId && !this.data[this.depKey]) {
|
|
250
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
251
|
+
...this._getDefaultErrorSettings('getDataListByDependencyId', new Error(`getDataListByDependencyId failed, ${this.depKey} is missing! (${this.dataParams.dataName})`)),
|
|
252
|
+
errorCode: 'NTS-DS0-GLD2',
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
const dataListExists = await this.dataDBService.getDataListByDependencyId(dependencyId ?? this.data[this.depKey]).catch(error => {
|
|
256
|
+
if (error?.errorCode === 'NTS-DBS-GLD2') {
|
|
257
|
+
fsm_dynamo_1.Dynamo_Log.warn(`getDataListByDependencyId ${this.dataParams.dataName} (${this.depKey}: ${dependencyId ?? this.data[this.depKey]}) didn't found any.`);
|
|
258
|
+
return [];
|
|
189
259
|
}
|
|
190
260
|
else {
|
|
191
|
-
throw
|
|
261
|
+
throw error;
|
|
192
262
|
}
|
|
263
|
+
});
|
|
264
|
+
if (!dontSetToService) {
|
|
265
|
+
this.dataList = dataListExists;
|
|
266
|
+
}
|
|
267
|
+
return dataListExists;
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
if (['NTS-DS0-GLD1', 'NTS-DS0-GLD2'].includes(error?.errorCode)) {
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
275
|
+
...this._getDefaultErrorSettings('getDataListByDependencyId', error),
|
|
276
|
+
errorCode: 'NTS-DS0-GLD0',
|
|
277
|
+
});
|
|
193
278
|
}
|
|
194
|
-
}
|
|
279
|
+
}
|
|
195
280
|
}
|
|
196
281
|
/**
|
|
197
282
|
*
|
|
@@ -223,27 +308,28 @@ class DynamoNTS_DataService {
|
|
|
223
308
|
* //
|
|
224
309
|
* @returns {T} data: T
|
|
225
310
|
*/
|
|
226
|
-
findData(filterBy, dontSetToService) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
throw error;
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
if (!dontSetToService) {
|
|
239
|
-
this.data = dataExists;
|
|
311
|
+
async findData(filterBy, dontSetToService) {
|
|
312
|
+
try {
|
|
313
|
+
const dataExists = await this.dataDBService.findOne(filterBy).catch(error => {
|
|
314
|
+
if (error?.errorCode === 'NTS-DBS-FO1') {
|
|
315
|
+
fsm_dynamo_1.Dynamo_Log.warn(`findData ${this.dataParams.dataName} didn't found any.`);
|
|
316
|
+
return null;
|
|
240
317
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
318
|
+
else {
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
if (!dontSetToService) {
|
|
323
|
+
this.data = dataExists;
|
|
245
324
|
}
|
|
246
|
-
|
|
325
|
+
return dataExists;
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
329
|
+
...this._getDefaultErrorSettings('findData', error),
|
|
330
|
+
errorCode: 'NTS-DS0-FD0',
|
|
331
|
+
});
|
|
332
|
+
}
|
|
247
333
|
}
|
|
248
334
|
/**
|
|
249
335
|
*
|
|
@@ -275,27 +361,28 @@ class DynamoNTS_DataService {
|
|
|
275
361
|
* //
|
|
276
362
|
* @returns {T[]} dataList: T[]
|
|
277
363
|
*/
|
|
278
|
-
findDatas(filterBy, dontSetToService) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return [];
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
throw error;
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
if (!dontSetToService) {
|
|
291
|
-
this.dataList = dataListExists;
|
|
364
|
+
async findDatas(filterBy, dontSetToService) {
|
|
365
|
+
try {
|
|
366
|
+
const dataListExists = await this.dataDBService.find(filterBy).catch(error => {
|
|
367
|
+
if (error?.errorCode === 'NTS-DBS-F1') {
|
|
368
|
+
fsm_dynamo_1.Dynamo_Log.warn(`findDatas ${this.dataParams.dataName} didn't found any.`);
|
|
369
|
+
return [];
|
|
292
370
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
371
|
+
else {
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
if (!dontSetToService) {
|
|
376
|
+
this.dataList = dataListExists;
|
|
297
377
|
}
|
|
298
|
-
|
|
378
|
+
return dataListExists;
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
382
|
+
...this._getDefaultErrorSettings('findDatas', error),
|
|
383
|
+
errorCode: 'NTS-DS0-FDS0',
|
|
384
|
+
});
|
|
385
|
+
}
|
|
299
386
|
}
|
|
300
387
|
/**
|
|
301
388
|
* This function uses the dataDBService.updateOne function.
|
|
@@ -353,31 +440,35 @@ class DynamoNTS_DataService {
|
|
|
353
440
|
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
354
441
|
* //
|
|
355
442
|
*/
|
|
356
|
-
updateData(set) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
yield this.dataDBService.updateOne(set.filterBy, set.update, this.issuer);
|
|
361
|
-
}
|
|
362
|
-
else if (this.data._id) {
|
|
363
|
-
yield this.dataDBService.updateOne({ _id: this.data._id }, set.update, this.issuer);
|
|
364
|
-
}
|
|
365
|
-
else if (this.depKey && this.data[this.depKey]) {
|
|
366
|
-
yield this.dataDBService.updateOne({ [this.depKey]: this.data[this.depKey] }, set.update, this.issuer);
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('updateData', new Error(`no usable parameter provided for updateData; no updateBy, no id, no dependencyId (${this.dataParams.dataName})`))), { errorCode: 'NTS-DS0-UD1' }));
|
|
370
|
-
}
|
|
443
|
+
async updateData(set) {
|
|
444
|
+
try {
|
|
445
|
+
if (set.filterBy) {
|
|
446
|
+
await this.dataDBService.updateOne(set.filterBy, set.update, this.issuer);
|
|
371
447
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
throw error;
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('updateData', error)), { errorCode: 'NTS-DS0-UD0' }));
|
|
378
|
-
}
|
|
448
|
+
else if (this.data._id) {
|
|
449
|
+
await this.dataDBService.updateOne({ _id: this.data._id }, set.update, this.issuer);
|
|
379
450
|
}
|
|
380
|
-
|
|
451
|
+
else if (this.depKey && this.data[this.depKey]) {
|
|
452
|
+
await this.dataDBService.updateOne({ [this.depKey]: this.data[this.depKey] }, set.update, this.issuer);
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
456
|
+
...this._getDefaultErrorSettings('updateData', new Error(`no usable parameter provided for updateData; no updateBy, no id, no dependencyId (${this.dataParams.dataName})`)),
|
|
457
|
+
errorCode: 'NTS-DS0-UD1',
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
catch (error) {
|
|
462
|
+
if (error?.errorCode == 'NTS-DS0-UD1') {
|
|
463
|
+
throw error;
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
467
|
+
...this._getDefaultErrorSettings('updateData', error),
|
|
468
|
+
errorCode: 'NTS-DS0-UD0',
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
381
472
|
}
|
|
382
473
|
/**
|
|
383
474
|
* modifies data if the data have ID and already exists in the DB,
|
|
@@ -390,122 +481,151 @@ class DynamoNTS_DataService {
|
|
|
390
481
|
* (when you simultaneously trying to change the same data's
|
|
391
482
|
* different values from different flows)
|
|
392
483
|
*/
|
|
393
|
-
saveData() {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
484
|
+
async saveData() {
|
|
485
|
+
try {
|
|
486
|
+
if (!this.data) {
|
|
487
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
488
|
+
...this._getDefaultErrorSettings('saveData', new Error(`no data to save! (${this.dataParams.dataName})`)),
|
|
489
|
+
errorCode: 'NTS-DS0-SD4',
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
if (!this.data._id && (!this.depKey || !this.data[this.depKey])) {
|
|
493
|
+
// if ID of dependencyID is not present, data not exists, create new data
|
|
494
|
+
this.data = await this.dataDBService.createData(this.data, this.issuer);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
let dataExists;
|
|
498
|
+
// check if data already exists with the specific ID
|
|
499
|
+
if (this.data._id) {
|
|
500
|
+
dataExists = await this.getDataById(null, true);
|
|
501
|
+
if (dataExists) {
|
|
502
|
+
// if data exists do modify
|
|
503
|
+
this.data = await this.dataDBService.modifyData(this.data, this.issuer);
|
|
402
504
|
return;
|
|
403
505
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
506
|
+
else {
|
|
507
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
508
|
+
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: provided ID not exists (id: ${this.data._id}, ${this.dataParams.dataName})`)),
|
|
509
|
+
errorCode: 'NTS-DS0-SD1',
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (this.depKey) {
|
|
514
|
+
if (!this.data[this.depKey]) {
|
|
515
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
516
|
+
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data id missing from data (key: ${this.depKey}, ${this.dataParams.dataName})`)),
|
|
517
|
+
errorCode: 'NTS-DS0-SD2',
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
if (this.depKeyIsUnique) {
|
|
521
|
+
dataExists = await this.getDataByDependencyId(null, true);
|
|
408
522
|
if (dataExists) {
|
|
409
523
|
// if data exists do modify
|
|
410
|
-
this.data =
|
|
524
|
+
this.data = await this.dataDBService.modifyData(this.data, this.issuer);
|
|
411
525
|
return;
|
|
412
526
|
}
|
|
413
527
|
else {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (this.depKeyIsUnique) {
|
|
422
|
-
dataExists = yield this.getDataByDependencyId(null, true);
|
|
423
|
-
if (dataExists) {
|
|
424
|
-
// if data exists do modify
|
|
425
|
-
this.data = yield this.dataDBService.modifyData(this.data, this.issuer);
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
// if data not exists check that dependency already exists for this
|
|
430
|
-
const dependencyExists = yield this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
|
|
431
|
-
if (!dependencyExists) {
|
|
432
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]}, ${this.dataParams.dataName})`))), { errorCode: 'NTS-DS0-SD3' }));
|
|
433
|
-
}
|
|
528
|
+
// if data not exists check that dependency already exists for this
|
|
529
|
+
const dependencyExists = await this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
|
|
530
|
+
if (!dependencyExists) {
|
|
531
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
532
|
+
...this._getDefaultErrorSettings('saveData', new Error(`saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]}, ${this.dataParams.dataName})`)),
|
|
533
|
+
errorCode: 'NTS-DS0-SD3',
|
|
534
|
+
});
|
|
434
535
|
}
|
|
435
536
|
}
|
|
436
537
|
}
|
|
437
|
-
// if data not exists create new data
|
|
438
|
-
this.data = yield this.dataDBService.createData(this.data, this.issuer);
|
|
439
538
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
539
|
+
// if data not exists create new data
|
|
540
|
+
this.data = await this.dataDBService.createData(this.data, this.issuer);
|
|
541
|
+
}
|
|
542
|
+
catch (error) {
|
|
543
|
+
if (['NTS-DS0-SD1', 'NTS-DS0-SD2'].includes(error?.errorCode)) {
|
|
544
|
+
throw error;
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
548
|
+
...this._getDefaultErrorSettings('saveData', error),
|
|
549
|
+
errorCode: 'NTS-DS0-SD0',
|
|
550
|
+
});
|
|
447
551
|
}
|
|
448
|
-
}
|
|
552
|
+
}
|
|
449
553
|
}
|
|
450
554
|
/**
|
|
451
555
|
* permanently deletes data from database by data._id
|
|
452
556
|
*/
|
|
453
|
-
deleteData() {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
557
|
+
async deleteData() {
|
|
558
|
+
try {
|
|
559
|
+
if (!this.data._id) {
|
|
560
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
561
|
+
...this._getDefaultErrorSettings('deleteData', new Error(`deleteData failed, ID is missing! (${this.dataParams.dataName})`)),
|
|
562
|
+
errorCode: 'NTS-DS0-DD1',
|
|
563
|
+
});
|
|
460
564
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('deleteData', error)), { errorCode: 'NTS-DS0-DD0' }));
|
|
467
|
-
}
|
|
565
|
+
await this.dataDBService.deleteDataById(this.data._id);
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
if (error?.errorCode == 'NTS-DS0-DD1') {
|
|
569
|
+
throw error;
|
|
468
570
|
}
|
|
469
|
-
|
|
571
|
+
else {
|
|
572
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
573
|
+
...this._getDefaultErrorSettings('deleteData', error),
|
|
574
|
+
errorCode: 'NTS-DS0-DD0',
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
}
|
|
470
578
|
}
|
|
471
579
|
/**
|
|
472
580
|
* validation of data, for modify and create, by the ModelParams
|
|
473
581
|
*/
|
|
474
|
-
validateForSave() {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
582
|
+
async validateForSave() {
|
|
583
|
+
try {
|
|
584
|
+
for (let i = 0; i < this.dataParams.modelParams.length; i++) {
|
|
585
|
+
// basic required validations
|
|
586
|
+
if ((this.dataParams.modelParams[i].required &&
|
|
587
|
+
(this.data[this.dataParams.modelParams[i].key] === null ||
|
|
588
|
+
this.data[this.dataParams.modelParams[i].key] === undefined)) ||
|
|
589
|
+
(this.dataParams.modelParams[i].index &&
|
|
480
590
|
(this.data[this.dataParams.modelParams[i].key] === null ||
|
|
481
|
-
this.data[this.dataParams.modelParams[i].key] === undefined))
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
591
|
+
this.data[this.dataParams.modelParams[i].key] === undefined))) {
|
|
592
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
593
|
+
...this._getDefaultErrorSettings('validateForSave', new Error(`validateForSave failed, ${this.dataParams.modelParams[i].key} is missing! (${this.dataParams.dataName})`)),
|
|
594
|
+
status: 422,
|
|
595
|
+
errorCode: 'NTS-DS0-VD1',
|
|
596
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
// specific Date validation
|
|
600
|
+
if (this.dataParams.modelParams[i].type === 'Date' &&
|
|
601
|
+
!(new Date(this.data[this.dataParams.modelParams[i].key]) instanceof Date)) {
|
|
602
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
603
|
+
...this._getDefaultErrorSettings('validateForSave', new Error(`validateForSave failed, ${this.dataParams.modelParams[i].key} is not a date! (${this.dataParams.dataName})`)),
|
|
604
|
+
status: 422,
|
|
605
|
+
errorCode: 'NTS-DS0-VD2',
|
|
606
|
+
userMessage: this.defaultValidationErrorUserMsg,
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
// call additional validators
|
|
610
|
+
if (this.dataParams.modelParams[i].additionalValidators) {
|
|
611
|
+
for (let j = 0; j < this.dataParams.modelParams[i].additionalValidators.length; j++) {
|
|
612
|
+
this.dataParams.modelParams[i].additionalValidators[j](this.data[this.dataParams.modelParams[i].key]);
|
|
497
613
|
}
|
|
498
614
|
}
|
|
499
615
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
else {
|
|
505
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('validateForSave', error)), { status: 422, errorCode: 'NTS-DS0-VD0' }));
|
|
506
|
-
}
|
|
616
|
+
}
|
|
617
|
+
catch (error) {
|
|
618
|
+
if (['NTS-DS0-VD1', 'NTS-DS0-VD2'].includes(error?.errorCode)) {
|
|
619
|
+
throw error;
|
|
507
620
|
}
|
|
508
|
-
|
|
621
|
+
else {
|
|
622
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
623
|
+
...this._getDefaultErrorSettings('validateForSave', error),
|
|
624
|
+
status: 422,
|
|
625
|
+
errorCode: 'NTS-DS0-VD0',
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
}
|
|
509
629
|
}
|
|
510
630
|
/**
|
|
511
631
|
* setting up dependency dataHook by DynamoBEDataModelParams
|
|
@@ -528,7 +648,11 @@ class DynamoNTS_DataService {
|
|
|
528
648
|
*/
|
|
529
649
|
getDependencyDataDBService() {
|
|
530
650
|
if (!this.depDBServiceKey) {
|
|
531
|
-
throw new fsm_dynamo_1.Dynamo_Error(
|
|
651
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
652
|
+
...this._getDefaultErrorSettings('getDependencyDataDBService', new Error(`getDependencyDataDBService was unsuccessful, service key not setted up! (${this.dataParams.dataName}))`)),
|
|
653
|
+
status: 501,
|
|
654
|
+
errorCode: 'NTS-DS0-GDDB0',
|
|
655
|
+
});
|
|
532
656
|
}
|
|
533
657
|
if (this.depDataDBService) {
|
|
534
658
|
return this.depDataDBService;
|
|
@@ -539,10 +663,9 @@ class DynamoNTS_DataService {
|
|
|
539
663
|
}
|
|
540
664
|
}
|
|
541
665
|
_getDefaultErrorSettings(fnName, error) {
|
|
542
|
-
var _a, _b;
|
|
543
666
|
return {
|
|
544
|
-
status:
|
|
545
|
-
message:
|
|
667
|
+
status: error?.___status ?? 500,
|
|
668
|
+
message: error?.message ?? `${fnName} was UNSUCCESFUL (NTS; ${this.dataParams.dataName})`,
|
|
546
669
|
addECToUserMsg: true,
|
|
547
670
|
userMessage: this.defaultErrorUserMsg,
|
|
548
671
|
issuer: this.issuer,
|