@futdevpro/nts-dynamo 1.6.59 → 1.7.1
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/_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.js +10 -9
- 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.js +370 -295
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/base/db.service.js +315 -246
- 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.js +38 -40
- 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.js +404 -412
- 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/nodemon.json +12 -5
- package/package.json +24 -24
- 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,150 +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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
const dataExists = await this.dataDBService.getDataById(id ?? this.data._id);
|
|
116
|
+
if (!dontSetToService) {
|
|
117
|
+
this.data = dataExists;
|
|
118
|
+
}
|
|
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
|
+
});
|
|
118
130
|
}
|
|
119
|
-
}
|
|
131
|
+
}
|
|
120
132
|
}
|
|
121
|
-
getDataByIds(ids, dontSetToService) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (!dontSetToService) {
|
|
132
|
-
this.dataList = datas;
|
|
133
|
-
}
|
|
134
|
-
return datas;
|
|
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 [];
|
|
135
143
|
}
|
|
136
|
-
|
|
137
|
-
|
|
144
|
+
const datas = await this.dataDBService.find({ _id: { $in: ids, }, });
|
|
145
|
+
if (!dontSetToService) {
|
|
146
|
+
this.dataList = datas;
|
|
138
147
|
}
|
|
139
|
-
|
|
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
|
+
}
|
|
140
156
|
}
|
|
141
157
|
/**
|
|
142
158
|
* returns data from database by dependencyId to the service
|
|
143
159
|
* (using id from service.data, if not provided)
|
|
144
160
|
* @param dependencyId
|
|
145
161
|
*/
|
|
146
|
-
getDataByDependencyId(dependencyId, dontSetToService) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (!dependencyId && !this.data[this.depKey]) {
|
|
153
|
-
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' }));
|
|
154
|
-
}
|
|
155
|
-
const dataExists = yield this.dataDBService.getDataByDependencyId(dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]).catch(error => {
|
|
156
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GD2') {
|
|
157
|
-
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.`);
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
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',
|
|
163
168
|
});
|
|
164
|
-
if (!dontSetToService) {
|
|
165
|
-
this.data = dataExists;
|
|
166
|
-
}
|
|
167
|
-
return dataExists;
|
|
168
169
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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;
|
|
172
180
|
}
|
|
173
181
|
else {
|
|
174
|
-
throw
|
|
182
|
+
throw error;
|
|
175
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;
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
196
|
+
...this._getDefaultErrorSettings('getDataByDependencyId', error),
|
|
197
|
+
errorCode: 'NTS-DS0-GD0',
|
|
198
|
+
});
|
|
176
199
|
}
|
|
177
|
-
}
|
|
200
|
+
}
|
|
178
201
|
}
|
|
179
|
-
getDatasByDependencyIds(dependencyIds, dontSetToService) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('getDatasByDependencyIds', new Error(`getDatasByDependencyIds failed, dependencyIds is missing! (${this.dataParams.dataName})`))), { errorCode: 'NTS-DS0-GDS2' }));
|
|
187
|
-
}
|
|
188
|
-
if (dependencyIds.length === 0) {
|
|
189
|
-
return [];
|
|
190
|
-
}
|
|
191
|
-
const datas = yield this.dataDBService.getDatasByDependencyIds(dependencyIds);
|
|
192
|
-
if (!dontSetToService) {
|
|
193
|
-
this.dataList = datas;
|
|
194
|
-
}
|
|
195
|
-
return datas;
|
|
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
|
+
});
|
|
196
209
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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 [];
|
|
204
218
|
}
|
|
205
|
-
|
|
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
|
+
}
|
|
206
236
|
}
|
|
207
237
|
/**
|
|
208
238
|
* returns dataList from database by dependencyId to the service
|
|
209
239
|
* @param dependencyId
|
|
210
240
|
*/
|
|
211
|
-
getDataListByDependencyId(dependencyId, dontSetToService) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (!dependencyId && !this.data[this.depKey]) {
|
|
218
|
-
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' }));
|
|
219
|
-
}
|
|
220
|
-
const dataListExists = yield this.dataDBService.getDataListByDependencyId(dependencyId !== null && dependencyId !== void 0 ? dependencyId : this.data[this.depKey]).catch(error => {
|
|
221
|
-
if ((error === null || error === void 0 ? void 0 : error.errorCode) === 'NTS-DBS-GLD2') {
|
|
222
|
-
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.`);
|
|
223
|
-
return [];
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
throw error;
|
|
227
|
-
}
|
|
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',
|
|
228
247
|
});
|
|
229
|
-
if (!dontSetToService) {
|
|
230
|
-
this.dataList = dataListExists;
|
|
231
|
-
}
|
|
232
|
-
return dataListExists;
|
|
233
248
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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 [];
|
|
237
259
|
}
|
|
238
260
|
else {
|
|
239
|
-
throw
|
|
261
|
+
throw error;
|
|
240
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
|
+
});
|
|
241
278
|
}
|
|
242
|
-
}
|
|
279
|
+
}
|
|
243
280
|
}
|
|
244
281
|
/**
|
|
245
282
|
*
|
|
@@ -271,27 +308,28 @@ class DynamoNTS_DataService {
|
|
|
271
308
|
* //
|
|
272
309
|
* @returns {T} data: T
|
|
273
310
|
*/
|
|
274
|
-
findData(filterBy, dontSetToService) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return null;
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
throw error;
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
if (!dontSetToService) {
|
|
287
|
-
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;
|
|
288
317
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
318
|
+
else {
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
if (!dontSetToService) {
|
|
323
|
+
this.data = dataExists;
|
|
293
324
|
}
|
|
294
|
-
|
|
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
|
+
}
|
|
295
333
|
}
|
|
296
334
|
/**
|
|
297
335
|
*
|
|
@@ -323,27 +361,28 @@ class DynamoNTS_DataService {
|
|
|
323
361
|
* //
|
|
324
362
|
* @returns {T[]} dataList: T[]
|
|
325
363
|
*/
|
|
326
|
-
findDatas(filterBy, dontSetToService) {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
return [];
|
|
333
|
-
}
|
|
334
|
-
else {
|
|
335
|
-
throw error;
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
if (!dontSetToService) {
|
|
339
|
-
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 [];
|
|
340
370
|
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
371
|
+
else {
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
if (!dontSetToService) {
|
|
376
|
+
this.dataList = dataListExists;
|
|
345
377
|
}
|
|
346
|
-
|
|
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
|
+
}
|
|
347
386
|
}
|
|
348
387
|
/**
|
|
349
388
|
* This function uses the dataDBService.updateOne function.
|
|
@@ -401,31 +440,35 @@ class DynamoNTS_DataService {
|
|
|
401
440
|
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
402
441
|
* //
|
|
403
442
|
*/
|
|
404
|
-
updateData(set) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
yield this.dataDBService.updateOne(set.filterBy, set.update, this.issuer);
|
|
409
|
-
}
|
|
410
|
-
else if (this.data._id) {
|
|
411
|
-
yield this.dataDBService.updateOne({ _id: this.data._id }, set.update, this.issuer);
|
|
412
|
-
}
|
|
413
|
-
else if (this.depKey && this.data[this.depKey]) {
|
|
414
|
-
yield this.dataDBService.updateOne({ [this.depKey]: this.data[this.depKey] }, set.update, this.issuer);
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
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' }));
|
|
418
|
-
}
|
|
443
|
+
async updateData(set) {
|
|
444
|
+
try {
|
|
445
|
+
if (set.filterBy) {
|
|
446
|
+
await this.dataDBService.updateOne(set.filterBy, set.update, this.issuer);
|
|
419
447
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
448
|
+
else if (this.data._id) {
|
|
449
|
+
await this.dataDBService.updateOne({ _id: this.data._id }, set.update, this.issuer);
|
|
450
|
+
}
|
|
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
|
+
});
|
|
427
459
|
}
|
|
428
|
-
}
|
|
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
|
+
}
|
|
429
472
|
}
|
|
430
473
|
/**
|
|
431
474
|
* modifies data if the data have ID and already exists in the DB,
|
|
@@ -438,122 +481,151 @@ class DynamoNTS_DataService {
|
|
|
438
481
|
* (when you simultaneously trying to change the same data's
|
|
439
482
|
* different values from different flows)
|
|
440
483
|
*/
|
|
441
|
-
saveData() {
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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);
|
|
450
504
|
return;
|
|
451
505
|
}
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
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);
|
|
456
522
|
if (dataExists) {
|
|
457
523
|
// if data exists do modify
|
|
458
|
-
this.data =
|
|
524
|
+
this.data = await this.dataDBService.modifyData(this.data, this.issuer);
|
|
459
525
|
return;
|
|
460
526
|
}
|
|
461
527
|
else {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if (this.depKeyIsUnique) {
|
|
470
|
-
dataExists = yield this.getDataByDependencyId(null, true);
|
|
471
|
-
if (dataExists) {
|
|
472
|
-
// if data exists do modify
|
|
473
|
-
this.data = yield this.dataDBService.modifyData(this.data, this.issuer);
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
else {
|
|
477
|
-
// if data not exists check that dependency already exists for this
|
|
478
|
-
const dependencyExists = yield this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
|
|
479
|
-
if (!dependencyExists) {
|
|
480
|
-
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' }));
|
|
481
|
-
}
|
|
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
|
+
});
|
|
482
535
|
}
|
|
483
536
|
}
|
|
484
537
|
}
|
|
485
|
-
// if data not exists create new data
|
|
486
|
-
this.data = yield this.dataDBService.createData(this.data, this.issuer);
|
|
487
538
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
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;
|
|
495
545
|
}
|
|
496
|
-
|
|
546
|
+
else {
|
|
547
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
548
|
+
...this._getDefaultErrorSettings('saveData', error),
|
|
549
|
+
errorCode: 'NTS-DS0-SD0',
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
}
|
|
497
553
|
}
|
|
498
554
|
/**
|
|
499
555
|
* permanently deletes data from database by data._id
|
|
500
556
|
*/
|
|
501
|
-
deleteData() {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
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
|
+
});
|
|
508
564
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('deleteData', error)), { errorCode: 'NTS-DS0-DD0' }));
|
|
515
|
-
}
|
|
565
|
+
await this.dataDBService.deleteDataById(this.data._id);
|
|
566
|
+
}
|
|
567
|
+
catch (error) {
|
|
568
|
+
if (error?.errorCode == 'NTS-DS0-DD1') {
|
|
569
|
+
throw error;
|
|
516
570
|
}
|
|
517
|
-
|
|
571
|
+
else {
|
|
572
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
573
|
+
...this._getDefaultErrorSettings('deleteData', error),
|
|
574
|
+
errorCode: 'NTS-DS0-DD0',
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
}
|
|
518
578
|
}
|
|
519
579
|
/**
|
|
520
580
|
* validation of data, for modify and create, by the ModelParams
|
|
521
581
|
*/
|
|
522
|
-
validateForSave() {
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
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 &&
|
|
528
590
|
(this.data[this.dataParams.modelParams[i].key] === null ||
|
|
529
|
-
this.data[this.dataParams.modelParams[i].key] === undefined))
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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]);
|
|
545
613
|
}
|
|
546
614
|
}
|
|
547
615
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
else {
|
|
553
|
-
throw new fsm_dynamo_1.Dynamo_Error(Object.assign(Object.assign({}, this._getDefaultErrorSettings('validateForSave', error)), { status: 422, errorCode: 'NTS-DS0-VD0' }));
|
|
554
|
-
}
|
|
616
|
+
}
|
|
617
|
+
catch (error) {
|
|
618
|
+
if (['NTS-DS0-VD1', 'NTS-DS0-VD2'].includes(error?.errorCode)) {
|
|
619
|
+
throw error;
|
|
555
620
|
}
|
|
556
|
-
|
|
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
|
+
}
|
|
557
629
|
}
|
|
558
630
|
/**
|
|
559
631
|
* setting up dependency dataHook by DynamoBEDataModelParams
|
|
@@ -576,7 +648,11 @@ class DynamoNTS_DataService {
|
|
|
576
648
|
*/
|
|
577
649
|
getDependencyDataDBService() {
|
|
578
650
|
if (!this.depDBServiceKey) {
|
|
579
|
-
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
|
+
});
|
|
580
656
|
}
|
|
581
657
|
if (this.depDataDBService) {
|
|
582
658
|
return this.depDataDBService;
|
|
@@ -587,10 +663,9 @@ class DynamoNTS_DataService {
|
|
|
587
663
|
}
|
|
588
664
|
}
|
|
589
665
|
_getDefaultErrorSettings(fnName, error) {
|
|
590
|
-
var _a, _b;
|
|
591
666
|
return {
|
|
592
|
-
status:
|
|
593
|
-
message:
|
|
667
|
+
status: error?.___status ?? 500,
|
|
668
|
+
message: error?.message ?? `${fnName} was UNSUCCESFUL (NTS; ${this.dataParams.dataName})`,
|
|
594
669
|
addECToUserMsg: true,
|
|
595
670
|
userMessage: this.defaultErrorUserMsg,
|
|
596
671
|
issuer: this.issuer,
|