@futdevpro/nts-dynamo 1.5.50 → 1.5.52
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/_models/dynamo-nts-endpoint-params.js +3 -2
- package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
- package/lib/_services/dynamo-nts-api.service.d.ts +1 -0
- package/lib/_services/dynamo-nts-api.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-api.service.js +6 -5
- package/lib/_services/dynamo-nts-api.service.js.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.d.ts +87 -7
- package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.js +87 -7
- package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
- package/lib/_services/dynamo-nts-app.d.ts +131 -22
- package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app.js +104 -1
- package/lib/_services/dynamo-nts-app.js.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.d.ts +79 -5
- package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.js +3 -2
- package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
- package/lib/_services/dynamo-nts-data.service.d.ts +25 -1
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +98 -70
- package/lib/_services/dynamo-nts-data.service.js.map +1 -1
- package/lib/_services/dynamo-nts-db.service.d.ts +165 -119
- package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-db.service.js +348 -293
- package/lib/_services/dynamo-nts-db.service.js.map +1 -1
- package/lib/_services/dynamo-nts-email.service.d.ts +1 -0
- package/lib/_services/dynamo-nts-email.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-email.service.js +5 -4
- package/lib/_services/dynamo-nts-email.service.js.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.d.ts +40 -0
- package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.js +43 -3
- package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.d.ts +1 -0
- package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.js +6 -2
- package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -12
- package/src/_models/dynamo-nts-endpoint-params.ts +2 -2
- package/src/_services/dynamo-nts-api.service.ts +7 -5
- package/src/_services/dynamo-nts-app-extended.ts +87 -7
- package/src/_services/dynamo-nts-app.ts +131 -22
- package/src/_services/dynamo-nts-auth.service.ts +83 -7
- package/src/_services/dynamo-nts-data.service.ts +100 -71
- package/src/_services/dynamo-nts-db.service.ts +377 -297
- package/src/_services/dynamo-nts-email.service.ts +6 -4
- package/src/_services/dynamo-nts-routing-module.service.ts +44 -3
- package/src/_services/dynamo-nts-socket.service.ts +13 -7
- package/futdevpro-nts-dynamo-01.05.40.tgz +0 -0
- package/futdevpro-nts-dynamo-01.05.41.tgz +0 -0
- package/futdevpro-nts-dynamo-01.05.42.tgz +0 -0
- package/futdevpro-nts-dynamo-01.05.43.tgz +0 -0
- package/futdevpro-nts-dynamo-01.05.44.tgz +0 -0
- package/futdevpro-nts-dynamo-01.05.45.tgz +0 -0
- package/futdevpro-nts-dynamo-01.05.47.tgz +0 -0
- package/futdevpro-nts-dynamo-01.05.49.tgz +0 -0
- package/futdevpro-nts-dynamo-01.05.50.tgz +0 -0
- package/lib/_constants/dynamo-nts-global.settings.d.ts +0 -3
- package/lib/_constants/dynamo-nts-global.settings.d.ts.map +0 -1
- package/lib/_constants/dynamo-nts-global.settings.js +0 -18
- package/lib/_constants/dynamo-nts-global.settings.js.map +0 -1
- package/lib/_constants/dynamobe-global.settings.d.ts +0 -3
- package/lib/_constants/dynamobe-global.settings.d.ts.map +0 -1
- package/lib/_constants/dynamobe-global.settings.js +0 -13
- package/lib/_constants/dynamobe-global.settings.js.map +0 -1
- package/lib/_enums/dynamobe-data-service-function.enum.d.ts +0 -8
- package/lib/_enums/dynamobe-data-service-function.enum.d.ts.map +0 -1
- package/lib/_enums/dynamobe-data-service-function.enum.js +0 -15
- package/lib/_enums/dynamobe-data-service-function.enum.js.map +0 -1
- package/lib/_enums/dynamobe-route-security.enum.d.ts +0 -6
- package/lib/_enums/dynamobe-route-security.enum.d.ts.map +0 -1
- package/lib/_enums/dynamobe-route-security.enum.js +0 -10
- package/lib/_enums/dynamobe-route-security.enum.js.map +0 -1
- package/lib/_enums/log-style.enum.d.ts +0 -26
- package/lib/_enums/log-style.enum.d.ts.map +0 -1
- package/lib/_enums/log-style.enum.js +0 -30
- package/lib/_enums/log-style.enum.js.map +0 -1
- package/lib/_models/dynamo-module-settings.d.ts +0 -4
- package/lib/_models/dynamo-module-settings.d.ts.map +0 -1
- package/lib/_models/dynamo-module-settings.js +0 -10
- package/lib/_models/dynamo-module-settings.js.map +0 -1
- package/lib/_models/dynamo-nts-socket-module-settings.d.ts +0 -19
- package/lib/_models/dynamo-nts-socket-module-settings.d.ts.map +0 -1
- package/lib/_models/dynamo-nts-socket-module-settings.js +0 -27
- package/lib/_models/dynamo-nts-socket-module-settings.js.map +0 -1
- package/lib/_models/dynamobe-api-call-params.d.ts +0 -37
- package/lib/_models/dynamobe-api-call-params.d.ts.map +0 -1
- package/lib/_models/dynamobe-api-call-params.js +0 -29
- package/lib/_models/dynamobe-api-call-params.js.map +0 -1
- package/lib/_models/dynamobe-app-params.d.ts +0 -18
- package/lib/_models/dynamobe-app-params.d.ts.map +0 -1
- package/lib/_models/dynamobe-app-params.js +0 -17
- package/lib/_models/dynamobe-app-params.js.map +0 -1
- package/lib/_models/dynamobe-data-model-params.d.ts +0 -1
- package/lib/_models/dynamobe-data-model-params.d.ts.map +0 -1
- package/lib/_models/dynamobe-data-model-params.js +0 -25
- package/lib/_models/dynamobe-data-model-params.js.map +0 -1
- package/lib/_models/dynamobe-endpoint-params.d.ts +0 -46
- package/lib/_models/dynamobe-endpoint-params.d.ts.map +0 -1
- package/lib/_models/dynamobe-endpoint-params.js +0 -117
- package/lib/_models/dynamobe-endpoint-params.js.map +0 -1
- package/lib/_models/dynamobe-global-settings.d.ts +0 -13
- package/lib/_models/dynamobe-global-settings.d.ts.map +0 -1
- package/lib/_models/dynamobe-global-settings.js +0 -3
- package/lib/_models/dynamobe-global-settings.js.map +0 -1
- package/lib/_modules/data-models.index.d.ts +0 -3
- package/lib/_modules/data-models.index.d.ts.map +0 -1
- package/lib/_modules/data-models.index.js +0 -6
- package/lib/_modules/data-models.index.js.map +0 -1
- package/lib/_services/dynamobe-api.service.d.ts +0 -19
- package/lib/_services/dynamobe-api.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-api.service.js +0 -167
- package/lib/_services/dynamobe-api.service.js.map +0 -1
- package/lib/_services/dynamobe-app.d.ts +0 -129
- package/lib/_services/dynamobe-app.d.ts.map +0 -1
- package/lib/_services/dynamobe-app.js +0 -238
- package/lib/_services/dynamobe-app.js.map +0 -1
- package/lib/_services/dynamobe-auth.service.d.ts +0 -54
- package/lib/_services/dynamobe-auth.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-auth.service.js +0 -46
- package/lib/_services/dynamobe-auth.service.js.map +0 -1
- package/lib/_services/dynamobe-controller.service.d.ts +0 -14
- package/lib/_services/dynamobe-controller.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-controller.service.js +0 -21
- package/lib/_services/dynamobe-controller.service.js.map +0 -1
- package/lib/_services/dynamobe-data.service.d.ts +0 -54
- package/lib/_services/dynamobe-data.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-data.service.js +0 -301
- package/lib/_services/dynamobe-data.service.js.map +0 -1
- package/lib/_services/dynamobe-db-service-collection.service.d.ts +0 -9
- package/lib/_services/dynamobe-db-service-collection.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-db-service-collection.service.js +0 -11
- package/lib/_services/dynamobe-db-service-collection.service.js.map +0 -1
- package/lib/_services/dynamobe-db.service.d.ts +0 -244
- package/lib/_services/dynamobe-db.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-db.service.js +0 -759
- package/lib/_services/dynamobe-db.service.js.map +0 -1
- package/lib/_services/dynamobe-email-service-collection.service.d.ts +0 -19
- package/lib/_services/dynamobe-email-service-collection.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-email-service-collection.service.js +0 -21
- package/lib/_services/dynamobe-email-service-collection.service.js.map +0 -1
- package/lib/_services/dynamobe-email.service.d.ts +0 -56
- package/lib/_services/dynamobe-email.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-email.service.js +0 -194
- package/lib/_services/dynamobe-email.service.js.map +0 -1
- package/lib/_services/dynamobe-global.service.d.ts +0 -62
- package/lib/_services/dynamobe-global.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-global.service.js +0 -107
- package/lib/_services/dynamobe-global.service.js.map +0 -1
- package/lib/_services/dynamobe-routing-module.service.d.ts +0 -42
- package/lib/_services/dynamobe-routing-module.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-routing-module.service.js +0 -146
- package/lib/_services/dynamobe-routing-module.service.js.map +0 -1
- package/lib/_services/dynamobe-shared-be.service.d.ts +0 -8
- package/lib/_services/dynamobe-shared-be.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-shared-be.service.js +0 -45
- package/lib/_services/dynamobe-shared-be.service.js.map +0 -1
- package/lib/_services/dynamobe-shared.service.d.ts +0 -26
- package/lib/_services/dynamobe-shared.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-shared.service.js +0 -63
- package/lib/_services/dynamobe-shared.service.js.map +0 -1
- package/lib/_services/dynamobe-singleton.service.d.ts +0 -9
- package/lib/_services/dynamobe-singleton.service.d.ts.map +0 -1
- package/lib/_services/dynamobe-singleton.service.js +0 -19
- package/lib/_services/dynamobe-singleton.service.js.map +0 -1
|
@@ -31,10 +31,14 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
31
31
|
|
|
32
32
|
depKey?: string;
|
|
33
33
|
depDBServiceKey?: string;
|
|
34
|
+
private depDataDBService: DynamoNTS_DBService<any>;
|
|
34
35
|
|
|
35
36
|
// dataModelParams?: DynamoBEDataPropertyParams[] = [];
|
|
36
37
|
dataParams: DynamoNTS_DataParams;
|
|
37
38
|
|
|
39
|
+
defaultErrorUserMsg = 'We encountered an unhandled Data Error, please contact the responsible development team.';
|
|
40
|
+
defaultValidationErrorUserMsg = `We encountered an unhandled Validation Error, please contact the responsible development team.`;
|
|
41
|
+
|
|
38
42
|
constructor(
|
|
39
43
|
data: T,
|
|
40
44
|
dataParams: DynamoNTS_DataParams,
|
|
@@ -53,42 +57,49 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
53
57
|
*/
|
|
54
58
|
async getAll(): Promise<void> {
|
|
55
59
|
try {
|
|
56
|
-
await this.dataDBService.getAll()
|
|
57
|
-
this.dataList = dataList;
|
|
58
|
-
});
|
|
60
|
+
this.dataList = await this.dataDBService.getAll();
|
|
59
61
|
} catch (error) {
|
|
60
62
|
throw new Dynamo_Error({
|
|
61
63
|
status: 417,
|
|
62
64
|
errorCode: 'NTS-DS0-GA0',
|
|
63
65
|
addECToUserMsg: true,
|
|
64
|
-
message:
|
|
65
|
-
userMessage:
|
|
66
|
+
message: `getAll was unsuccessful (${this.dataParams.dataName})`,
|
|
67
|
+
userMessage: this.defaultErrorUserMsg,
|
|
66
68
|
error: error
|
|
67
69
|
});
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
/**
|
|
74
|
+
* @description
|
|
72
75
|
* returns data from database by id
|
|
76
|
+
* also if dontSetToService is false or not setted,
|
|
77
|
+
* the data will be saved to the service
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* If you need to get-save a data, if possible,
|
|
81
|
+
* use db-service update instead.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} id
|
|
84
|
+
* @param dontSetToService
|
|
85
|
+
*
|
|
86
|
+
* @return {T} data: T
|
|
73
87
|
*/
|
|
74
88
|
async getDataById(id?: string, dontSetToService?: boolean): Promise<T> {
|
|
75
89
|
try {
|
|
76
90
|
if (id || this.data._id) {
|
|
77
|
-
let dataExists: T;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
dataExists = data;
|
|
83
|
-
});
|
|
91
|
+
let dataExists: T = await this.dataDBService.getDataById(id ? id : this.data._id);
|
|
92
|
+
if (!dontSetToService && dataExists) {
|
|
93
|
+
this.data = dataExists;
|
|
94
|
+
}
|
|
84
95
|
return dataExists;
|
|
85
96
|
} else {
|
|
86
97
|
throw new Dynamo_Error({
|
|
87
98
|
status: 417,
|
|
88
99
|
errorCode: 'NTS-DS0-GI1',
|
|
89
100
|
addECToUserMsg: true,
|
|
90
|
-
message: `ID is missing! (maybe you wanted to use getDataByDependencyId instead...)`,
|
|
91
|
-
userMessage:
|
|
101
|
+
message: `ID is missing! (maybe you wanted to use getDataByDependencyId() instead...) (${this.dataParams.dataName})`,
|
|
102
|
+
userMessage: this.defaultErrorUserMsg
|
|
92
103
|
});
|
|
93
104
|
}
|
|
94
105
|
} catch (error) {
|
|
@@ -96,8 +107,8 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
96
107
|
status: 417,
|
|
97
108
|
errorCode: 'NTS-DS0-GI0',
|
|
98
109
|
addECToUserMsg: true,
|
|
99
|
-
message:
|
|
100
|
-
userMessage:
|
|
110
|
+
message: `getDataById was unsuccessful (${this.dataParams.dataName})`,
|
|
111
|
+
userMessage: this.defaultErrorUserMsg,
|
|
101
112
|
error: error
|
|
102
113
|
});
|
|
103
114
|
}
|
|
@@ -111,21 +122,18 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
111
122
|
try {
|
|
112
123
|
if (this.depKey) {
|
|
113
124
|
if (dependencyId || this.data[this.depKey]) {
|
|
114
|
-
let dataExists: T;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
dataExists = data;
|
|
120
|
-
});
|
|
125
|
+
let dataExists: T = await this.dataDBService.getDataByDependencyId(dependencyId ? dependencyId : this.data[this.depKey]);
|
|
126
|
+
if (!dontSetToService && dataExists) {
|
|
127
|
+
this.data = dataExists;
|
|
128
|
+
}
|
|
121
129
|
return dataExists;
|
|
122
130
|
} else {
|
|
123
131
|
throw new Dynamo_Error({
|
|
124
132
|
status: 417,
|
|
125
133
|
errorCode: 'NTS-DS0-GD3',
|
|
126
134
|
addECToUserMsg: true,
|
|
127
|
-
message: `${this.depKey} is missing
|
|
128
|
-
userMessage:
|
|
135
|
+
message: `${this.depKey} is missing! (${this.dataParams.dataName})`,
|
|
136
|
+
userMessage: this.defaultErrorUserMsg
|
|
129
137
|
});
|
|
130
138
|
}
|
|
131
139
|
} else {
|
|
@@ -133,8 +141,8 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
133
141
|
status: 417,
|
|
134
142
|
errorCode: 'NTS-DS0-GD2',
|
|
135
143
|
addECToUserMsg: true,
|
|
136
|
-
message: 'dependencyDataIdKey is missing from service!
|
|
137
|
-
userMessage:
|
|
144
|
+
message: `'dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
|
|
145
|
+
userMessage: this.defaultErrorUserMsg
|
|
138
146
|
});
|
|
139
147
|
}
|
|
140
148
|
} catch (error) {
|
|
@@ -142,8 +150,8 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
142
150
|
status: 417,
|
|
143
151
|
errorCode: 'NTS-DS0-GD0',
|
|
144
152
|
addECToUserMsg: true,
|
|
145
|
-
message:
|
|
146
|
-
userMessage:
|
|
153
|
+
message: `getDataByDependencyId was unsuccessful (${this.dataParams.dataName})`,
|
|
154
|
+
userMessage: this.defaultErrorUserMsg,
|
|
147
155
|
error: error
|
|
148
156
|
});
|
|
149
157
|
}
|
|
@@ -157,16 +165,14 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
157
165
|
try {
|
|
158
166
|
if (this.depKey) {
|
|
159
167
|
if (dependencyId || this.data[this.depKey]) {
|
|
160
|
-
await this.dataDBService.getDataListByDependencyId(dependencyId ? dependencyId : this.data[this.depKey])
|
|
161
|
-
this.dataList = data;
|
|
162
|
-
});
|
|
168
|
+
this.dataList = await this.dataDBService.getDataListByDependencyId(dependencyId ? dependencyId : this.data[this.depKey]);
|
|
163
169
|
} else {
|
|
164
170
|
throw new Dynamo_Error({
|
|
165
171
|
status: 417,
|
|
166
172
|
errorCode: 'NTS-DS0-GLD3',
|
|
167
173
|
addECToUserMsg: true,
|
|
168
|
-
message: `${this.depKey} is missing
|
|
169
|
-
userMessage:
|
|
174
|
+
message: `${this.depKey} is missing (${this.dataParams.dataName})`,
|
|
175
|
+
userMessage: this.defaultErrorUserMsg
|
|
170
176
|
});
|
|
171
177
|
}
|
|
172
178
|
} else {
|
|
@@ -174,8 +180,8 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
174
180
|
status: 417,
|
|
175
181
|
errorCode: 'NTS-DS0-GLD2',
|
|
176
182
|
addECToUserMsg: true,
|
|
177
|
-
message:
|
|
178
|
-
userMessage:
|
|
183
|
+
message: `dependencyDataIdKey is missing from service! (${this.dataParams.dataName})`,
|
|
184
|
+
userMessage: this.defaultErrorUserMsg
|
|
179
185
|
});
|
|
180
186
|
}
|
|
181
187
|
} catch (error) {
|
|
@@ -183,8 +189,27 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
183
189
|
status: 417,
|
|
184
190
|
errorCode: 'NTS-DS0-GLD0',
|
|
185
191
|
addECToUserMsg: true,
|
|
186
|
-
message:
|
|
187
|
-
userMessage:
|
|
192
|
+
message: `getDataListByDependencyId was unsuccessful (${this.dataParams.dataName})`,
|
|
193
|
+
userMessage: this.defaultErrorUserMsg,
|
|
194
|
+
error: error
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
async updateData(set: { updateBy?: any, update: any }): Promise<void> {
|
|
201
|
+
try {
|
|
202
|
+
if (set.updateBy) {
|
|
203
|
+
this.data = await this.dataDBService.updateOne(set.updateBy, set.update, this.issuer);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
} catch (error) {
|
|
207
|
+
throw new Dynamo_Error({
|
|
208
|
+
status: 417,
|
|
209
|
+
errorCode: 'NTS-DS0-UD0',
|
|
210
|
+
addECToUserMsg: true,
|
|
211
|
+
message: `updateData was unsuccessful (${this.dataParams.dataName})`,
|
|
212
|
+
userMessage: this.defaultErrorUserMsg,
|
|
188
213
|
error: error
|
|
189
214
|
});
|
|
190
215
|
}
|
|
@@ -193,31 +218,30 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
193
218
|
/**
|
|
194
219
|
* modifies data if the data have ID and already exists in the DB,
|
|
195
220
|
* creates new if the ID is not present or cant find in DB,
|
|
196
|
-
* and if dependency data setted up, will check before creation
|
|
221
|
+
* and if dependency data setted up, will check before creation,
|
|
222
|
+
* @warning
|
|
223
|
+
* but the proper way to update data, if you use update method instead,
|
|
224
|
+
* this way, you can avoid data override errors
|
|
225
|
+
* (when you simultaneously trying to change the same data's
|
|
226
|
+
* different values from different flows)
|
|
197
227
|
*/
|
|
198
228
|
async saveData(): Promise<void> {
|
|
199
229
|
try {
|
|
200
230
|
if (this.data._id) {
|
|
201
231
|
// check if already exists
|
|
202
|
-
let dataExists: T;
|
|
203
|
-
await this.getDataById(null, true).then((data: T) => {
|
|
204
|
-
dataExists = data;
|
|
205
|
-
}).catch(() => {});
|
|
232
|
+
let dataExists: T = await this.getDataById(null, true).catch(() => null);
|
|
206
233
|
if (!dataExists) {
|
|
207
234
|
// if data not exists check that dependency already exists for this
|
|
208
235
|
if (this.depKey) {
|
|
209
236
|
if (this.data[this.depKey]) {
|
|
210
|
-
let dependencyExists =
|
|
211
|
-
await this.getDependencyDataDBService().getDataById(this.data[this.depKey]).then((dep) => {
|
|
212
|
-
dependencyExists = !!dep;
|
|
213
|
-
});
|
|
237
|
+
let dependencyExists = await this.getDependencyDataDBService().getDataById(this.data[this.depKey]);
|
|
214
238
|
if (!dependencyExists) {
|
|
215
239
|
throw new Dynamo_Error({
|
|
216
240
|
status: 417,
|
|
217
241
|
errorCode: 'NTS-DS0-SD1',
|
|
218
242
|
addECToUserMsg: true,
|
|
219
243
|
message: `saveData was unsuccessful: dependency data not exists (key: ${this.depKey}, id: ${this.data[this.depKey]})`,
|
|
220
|
-
userMessage:
|
|
244
|
+
userMessage: this.defaultErrorUserMsg
|
|
221
245
|
});
|
|
222
246
|
}
|
|
223
247
|
} else {
|
|
@@ -226,25 +250,19 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
226
250
|
errorCode: 'NTS-DS0-SD2',
|
|
227
251
|
addECToUserMsg: true,
|
|
228
252
|
message: `saveData was unsuccessful: dependency data id missing from data (key: ${this.depKey})`,
|
|
229
|
-
userMessage:
|
|
253
|
+
userMessage: this.defaultErrorUserMsg
|
|
230
254
|
});
|
|
231
255
|
}
|
|
232
256
|
}
|
|
233
257
|
// if data not exists create new data
|
|
234
|
-
await this.dataDBService.createData(this.data, this.issuer)
|
|
235
|
-
this.data = data;
|
|
236
|
-
});
|
|
258
|
+
this.data = await this.dataDBService.createData(this.data, this.issuer);
|
|
237
259
|
} else {
|
|
238
260
|
// if data exists do modify
|
|
239
|
-
await this.dataDBService.modifyData(this.data, this.issuer)
|
|
240
|
-
this.data = data;
|
|
241
|
-
});
|
|
261
|
+
this.data = await this.dataDBService.modifyData(this.data, this.issuer);
|
|
242
262
|
}
|
|
243
263
|
} else {
|
|
244
264
|
// if ID is not present, data not exists, create new data
|
|
245
|
-
await this.dataDBService.createData(this.data, this.issuer)
|
|
246
|
-
this.data = data;
|
|
247
|
-
});
|
|
265
|
+
this.data = await this.dataDBService.createData(this.data, this.issuer);
|
|
248
266
|
}
|
|
249
267
|
} catch (error) {
|
|
250
268
|
throw new Dynamo_Error({
|
|
@@ -252,7 +270,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
252
270
|
errorCode: 'NTS-DS0-SD0',
|
|
253
271
|
addECToUserMsg: true,
|
|
254
272
|
message: `modifyData was unsuccessful (${this.dataParams.dataName})`,
|
|
255
|
-
userMessage:
|
|
273
|
+
userMessage: this.defaultErrorUserMsg,
|
|
256
274
|
error: error
|
|
257
275
|
});
|
|
258
276
|
}
|
|
@@ -266,15 +284,21 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
266
284
|
if (this.data._id) {
|
|
267
285
|
await this.dataDBService.deleteDataById(this.data._id);
|
|
268
286
|
} else {
|
|
269
|
-
throw new Dynamo_Error({
|
|
287
|
+
throw new Dynamo_Error({
|
|
288
|
+
status: 417,
|
|
289
|
+
errorCode: 'NTS-DS0-DD1',
|
|
290
|
+
addECToUserMsg: true,
|
|
291
|
+
message: `ID is missing! (${this.dataParams.dataName})` ,
|
|
292
|
+
userMessage: this.defaultErrorUserMsg,
|
|
293
|
+
});
|
|
270
294
|
}
|
|
271
295
|
} catch (error) {
|
|
272
296
|
throw new Dynamo_Error({
|
|
273
297
|
status: 417,
|
|
274
298
|
errorCode: 'NTS-DS0-DD0',
|
|
275
299
|
addECToUserMsg: true,
|
|
276
|
-
message:
|
|
277
|
-
userMessage:
|
|
300
|
+
message: `deleteData was unsuccessful (${this.dataParams.dataName})`,
|
|
301
|
+
userMessage: this.defaultErrorUserMsg,
|
|
278
302
|
error: error
|
|
279
303
|
});
|
|
280
304
|
}
|
|
@@ -294,17 +318,17 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
294
318
|
errorCode: 'NTS-DS0-VD1',
|
|
295
319
|
addECToUserMsg: true,
|
|
296
320
|
message: `${this.dataParams.modelParams[i].key} is missing! (${this.dataParams.modelParams[i].required ? 'required' : 'index'})`,
|
|
297
|
-
userMessage:
|
|
321
|
+
userMessage: this.defaultValidationErrorUserMsg
|
|
298
322
|
});
|
|
299
323
|
}
|
|
300
324
|
// specific Date validation
|
|
301
325
|
if (this.dataParams.modelParams[i].type === 'Date' && !(new Date(this.data[this.dataParams.modelParams[i].key]) instanceof Date)) {
|
|
302
|
-
throw new Dynamo_Error({
|
|
326
|
+
throw new Dynamo_Error({
|
|
303
327
|
status: 422,
|
|
304
328
|
errorCode: 'NTS-DS0-VD2',
|
|
305
329
|
addECToUserMsg: true,
|
|
306
330
|
message: `${this.dataParams.modelParams[i].key} is not a date!`,
|
|
307
|
-
userMessage:
|
|
331
|
+
userMessage: this.defaultValidationErrorUserMsg
|
|
308
332
|
});
|
|
309
333
|
}
|
|
310
334
|
// call additional validators
|
|
@@ -319,8 +343,8 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
319
343
|
status: 422,
|
|
320
344
|
errorCode: 'NTS-DS0-VD0',
|
|
321
345
|
addECToUserMsg: true,
|
|
322
|
-
message:
|
|
323
|
-
userMessage:
|
|
346
|
+
message: `validateForSave was unsuccessful (${this.dataParams.dataName})`,
|
|
347
|
+
userMessage: this.defaultErrorUserMsg,
|
|
324
348
|
error: error
|
|
325
349
|
});
|
|
326
350
|
}
|
|
@@ -333,8 +357,8 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
333
357
|
const dependencyParam: DynamoNTS_DataPropertyParams = this.dataParams.modelParams.find((modelParams: DynamoNTS_DataPropertyParams) => modelParams.isDependencyHook);
|
|
334
358
|
if (dependencyParam) {
|
|
335
359
|
this.depKey = dependencyParam.key;
|
|
336
|
-
if (dependencyParam.
|
|
337
|
-
this.depDBServiceKey = dependencyParam.
|
|
360
|
+
if (dependencyParam.dependencyDataName) {
|
|
361
|
+
this.depDBServiceKey = dependencyParam.dependencyDataName;
|
|
338
362
|
}
|
|
339
363
|
}
|
|
340
364
|
}
|
|
@@ -345,14 +369,19 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
345
369
|
*/
|
|
346
370
|
getDependencyDataDBService(): DynamoNTS_DBService<any> {
|
|
347
371
|
if (this.depDBServiceKey) {
|
|
348
|
-
|
|
372
|
+
if (this.depDataDBService) {
|
|
373
|
+
return this.depDataDBService;
|
|
374
|
+
} else {
|
|
375
|
+
this.depDataDBService = DynamoNTS_GlobalService.getDBServiceByKey(this.depDBServiceKey);
|
|
376
|
+
return this.depDataDBService;
|
|
377
|
+
}
|
|
349
378
|
} else {
|
|
350
379
|
throw new Dynamo_Error({
|
|
351
380
|
status: 501,
|
|
352
381
|
errorCode: 'NTS-DS0-GDDB0',
|
|
353
382
|
addECToUserMsg: true,
|
|
354
383
|
message: 'getDependencyDataDBService was unsuccessful, service key not setted up!',
|
|
355
|
-
userMessage:
|
|
384
|
+
userMessage: this.defaultErrorUserMsg
|
|
356
385
|
});
|
|
357
386
|
}
|
|
358
387
|
}
|