@futdevpro/nts-dynamo 1.5.45 → 1.5.49
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/futdevpro-nts-dynamo-01.05.47.tgz +0 -0
- package/futdevpro-nts-dynamo-01.05.49.tgz +0 -0
- package/lib/_models/dynamo-nts-endpoint-params.js +1 -1
- package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
- package/lib/_models/dynamo-nts-socket-dictionary.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-dictionary.js +5 -2
- package/lib/_models/dynamo-nts-socket-dictionary.js.map +1 -1
- package/lib/_modules/test/custom-data.service.d.ts +3 -3
- package/lib/_modules/test/custom-data.service.d.ts.map +1 -1
- package/lib/_modules/test/custom-data.service.js +4 -4
- package/lib/_modules/test/custom-data.service.js.map +1 -1
- package/lib/_modules/test/test-controller.js +6 -6
- package/lib/_modules/test/test-controller.js.map +1 -1
- package/lib/_modules/usage/usage-controller.js +1 -1
- package/lib/_modules/usage/usage-controller.js.map +1 -1
- package/lib/_modules/usage/usage.service.d.ts +6 -6
- package/lib/_modules/usage/usage.service.d.ts.map +1 -1
- package/lib/_modules/usage/usage.service.js +10 -6
- package/lib/_modules/usage/usage.service.js.map +1 -1
- package/lib/_services/dynamo-nts-api.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-api.service.js +16 -6
- package/lib/_services/dynamo-nts-api.service.js.map +1 -1
- package/lib/_services/dynamo-nts-app.d.ts +1 -0
- package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.js +8 -4
- package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
- package/lib/_services/dynamo-nts-data.service.d.ts +2 -2
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +72 -43
- package/lib/_services/dynamo-nts-data.service.js.map +1 -1
- package/lib/_services/dynamo-nts-db.service.d.ts +4 -4
- package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-db.service.js +124 -84
- package/lib/_services/dynamo-nts-db.service.js.map +1 -1
- package/lib/_services/dynamo-nts-email.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-email.service.js +20 -16
- package/lib/_services/dynamo-nts-email.service.js.map +1 -1
- package/lib/_services/dynamo-nts-global.service.d.ts +3 -3
- package/lib/_services/dynamo-nts-global.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-global.service.js.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.js +17 -11
- package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.js +5 -1
- package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
- package/lib/_services/dynamobe-data.service.d.ts +2 -2
- package/lib/_services/dynamobe-db.service.d.ts +4 -4
- package/lib/_services/dynamobe-db.service.js +4 -4
- package/lib/_services/dynamobe-global.service.d.ts +3 -3
- package/lib/tsconfig.tsbuildinfo +1 -5589
- package/package.json +13 -6
- package/src/_models/dynamo-nts-endpoint-params.ts +1 -1
- package/src/_models/dynamo-nts-socket-dictionary.ts +6 -3
- package/src/_modules/test/custom-data.service.ts +4 -4
- package/src/_modules/test/test-controller.ts +7 -7
- package/src/_modules/usage/usage-controller.ts +2 -2
- package/src/_modules/usage/usage.service.ts +26 -22
- package/src/_services/dynamo-nts-api.service.ts +22 -8
- package/src/_services/dynamo-nts-auth.service.ts +10 -6
- package/src/_services/dynamo-nts-data.service.ts +74 -45
- package/src/_services/dynamo-nts-db.service.ts +157 -87
- package/src/_services/dynamo-nts-email.service.ts +21 -17
- package/src/_services/dynamo-nts-global.service.ts +3 -3
- package/src/_services/dynamo-nts-routing-module.service.ts +16 -10
- package/src/_services/dynamo-nts-socket.service.ts +6 -2
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
import * as mongoose from 'mongoose';
|
|
3
3
|
import { Schema } from 'mongoose';
|
|
4
|
-
import {
|
|
4
|
+
import { Dynamo_Metadata, DynamoNTS_DataParams, DynamoNTS_DataPropertyParams, Dynamo_Error } from '@futdevpro/fsm-dynamo';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
export class DynamoNTS_DBService<T extends
|
|
9
|
+
export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
10
10
|
dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
|
|
11
11
|
|
|
12
12
|
private depDataName: string;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @param dataName name the model
|
|
16
|
-
* @param typeSample sample data for scheme creation (dont include
|
|
16
|
+
* @param typeSample sample data for scheme creation (dont include Dynamo_Metadata!)
|
|
17
17
|
* @param schemaSettings additional settings for specific parameters as unique, required, minlength or maxlength
|
|
18
18
|
* schemaSettings also MUST contain specific types that differs from the listed above (Array, Date)
|
|
19
19
|
*/
|
|
@@ -33,32 +33,39 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
33
33
|
data.__lastModified = new Date();
|
|
34
34
|
data.__createdBy = creator;
|
|
35
35
|
data.__lastModifiedBy = creator;
|
|
36
|
+
|
|
36
37
|
const dataModel = new this.dataModel(data);
|
|
37
38
|
let newData: T;
|
|
39
|
+
|
|
38
40
|
await dataModel.save().then(res => {
|
|
39
41
|
if (res) {
|
|
40
42
|
newData = res.toObject() as T;
|
|
41
43
|
} else {
|
|
42
|
-
throw new
|
|
44
|
+
throw new Dynamo_Error({
|
|
43
45
|
status: 204,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
errorCode: 'NTS-DBS-CD1',
|
|
47
|
+
addECToUserMsg: true,
|
|
48
|
+
message: `save ${this.dataParams.dbName} result not found! (NTS DB)`,
|
|
49
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`
|
|
47
50
|
});
|
|
48
51
|
}
|
|
49
52
|
}).catch(error => {
|
|
50
|
-
throw new
|
|
53
|
+
throw new Dynamo_Error({
|
|
51
54
|
status: 422,
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
errorCode: 'NTS-DBS-CD0',
|
|
56
|
+
addECToUserMsg: true,
|
|
57
|
+
message: `Create new ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
58
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
54
59
|
error
|
|
55
60
|
});
|
|
56
61
|
});
|
|
62
|
+
|
|
57
63
|
if (typeof newData._id === 'object') {
|
|
58
64
|
newData._id = `${newData._id}`;
|
|
59
65
|
}
|
|
60
66
|
data._id = newData._id;
|
|
61
67
|
data.__v = newData.__v;
|
|
68
|
+
|
|
62
69
|
return data;
|
|
63
70
|
}
|
|
64
71
|
|
|
@@ -70,28 +77,35 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
70
77
|
async modifyData(data: T, modifier: string): Promise<T> {
|
|
71
78
|
data.__lastModified = new Date();
|
|
72
79
|
data.__lastModifiedBy = modifier;
|
|
80
|
+
|
|
73
81
|
const dataModel = new this.dataModel(data);
|
|
74
82
|
let newData: T;
|
|
83
|
+
|
|
75
84
|
await this.dataModel.findByIdAndUpdate(data._id, dataModel).then(res => {
|
|
76
85
|
if (res) {
|
|
77
86
|
newData = res.toObject() as T;
|
|
78
87
|
} else {
|
|
79
|
-
throw new
|
|
88
|
+
throw new Dynamo_Error({
|
|
80
89
|
status: 204,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
errorCode: 'NTS-DBS-FU1',
|
|
91
|
+
addECToUserMsg: true,
|
|
92
|
+
message: `update ${this.dataParams.dbName} result not found! (NTS DB)`,
|
|
93
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`
|
|
84
94
|
});
|
|
85
95
|
}
|
|
86
96
|
}).catch(error => {
|
|
87
|
-
throw new
|
|
97
|
+
throw new Dynamo_Error({
|
|
88
98
|
status: 417,
|
|
89
|
-
|
|
90
|
-
|
|
99
|
+
errorCode: 'NTS-DBS-FU0',
|
|
100
|
+
addECToUserMsg: true,
|
|
101
|
+
message: `modify ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
102
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
91
103
|
error
|
|
92
104
|
});
|
|
93
105
|
});
|
|
106
|
+
|
|
94
107
|
data.__v = newData.__v;
|
|
108
|
+
|
|
95
109
|
return data;
|
|
96
110
|
}
|
|
97
111
|
|
|
@@ -102,6 +116,7 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
102
116
|
*/
|
|
103
117
|
async getDataById(id: string): Promise<T> {
|
|
104
118
|
let data: T;
|
|
119
|
+
|
|
105
120
|
await this.dataModel.findById(id).then(res => {
|
|
106
121
|
if (res) {
|
|
107
122
|
data = res.toObject() as T;
|
|
@@ -109,16 +124,20 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
109
124
|
data = null;
|
|
110
125
|
}
|
|
111
126
|
}).catch(error => {
|
|
112
|
-
throw new
|
|
127
|
+
throw new Dynamo_Error({
|
|
113
128
|
status: 417,
|
|
114
|
-
|
|
115
|
-
|
|
129
|
+
errorCode: 'NTS-DBS-GI0',
|
|
130
|
+
addECToUserMsg: true,
|
|
131
|
+
message: `get ${this.dataParams.dbName} by ID was unsuccessful (NTS DB)`,
|
|
132
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
116
133
|
error
|
|
117
134
|
});
|
|
118
135
|
});
|
|
136
|
+
|
|
119
137
|
if (data && typeof data._id === 'object') {
|
|
120
138
|
data._id = `${data._id}`;
|
|
121
139
|
}
|
|
140
|
+
|
|
122
141
|
return data;
|
|
123
142
|
}
|
|
124
143
|
|
|
@@ -137,10 +156,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
137
156
|
data = null;
|
|
138
157
|
}
|
|
139
158
|
}).catch(error => {
|
|
140
|
-
throw new
|
|
159
|
+
throw new Dynamo_Error({
|
|
141
160
|
status: 417,
|
|
142
|
-
|
|
143
|
-
|
|
161
|
+
errorCode: 'NTS-DBS-GD1',
|
|
162
|
+
addECToUserMsg: true,
|
|
163
|
+
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
164
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
144
165
|
error
|
|
145
166
|
});
|
|
146
167
|
});
|
|
@@ -149,11 +170,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
149
170
|
}
|
|
150
171
|
return data;
|
|
151
172
|
} else {
|
|
152
|
-
throw new
|
|
173
|
+
throw new Dynamo_Error({
|
|
153
174
|
status: 501,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
175
|
+
errorCode: 'NTS-DBS-GD0',
|
|
176
|
+
addECToUserMsg: true,
|
|
177
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
178
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`
|
|
157
179
|
});
|
|
158
180
|
}
|
|
159
181
|
}
|
|
@@ -171,10 +193,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
171
193
|
dataList = res;
|
|
172
194
|
}
|
|
173
195
|
}).catch(error => {
|
|
174
|
-
throw new
|
|
196
|
+
throw new Dynamo_Error({
|
|
175
197
|
status: 417,
|
|
176
|
-
|
|
177
|
-
|
|
198
|
+
errorCode: 'NTS-DBS-GLD1',
|
|
199
|
+
addECToUserMsg: true,
|
|
200
|
+
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
201
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
178
202
|
error
|
|
179
203
|
});
|
|
180
204
|
});
|
|
@@ -185,11 +209,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
185
209
|
}
|
|
186
210
|
return dataList;
|
|
187
211
|
} else {
|
|
188
|
-
throw new
|
|
212
|
+
throw new Dynamo_Error({
|
|
189
213
|
status: 501,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
214
|
+
errorCode: 'NTS-DBS-GLD0',
|
|
215
|
+
addECToUserMsg: true,
|
|
216
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
217
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`
|
|
193
218
|
});
|
|
194
219
|
}
|
|
195
220
|
}
|
|
@@ -207,20 +232,23 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
207
232
|
dataList = res;
|
|
208
233
|
}
|
|
209
234
|
}).catch(error => {
|
|
210
|
-
throw new
|
|
235
|
+
throw new Dynamo_Error({
|
|
211
236
|
status: 417,
|
|
212
|
-
|
|
213
|
-
|
|
237
|
+
errorCode: 'NTS-DBS-GLDS1',
|
|
238
|
+
addECToUserMsg: true,
|
|
239
|
+
message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (NTS DB)`,
|
|
240
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
214
241
|
error
|
|
215
242
|
});
|
|
216
243
|
});
|
|
217
244
|
return dataList;
|
|
218
245
|
} else {
|
|
219
|
-
throw new
|
|
246
|
+
throw new Dynamo_Error({
|
|
220
247
|
status: 501,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
248
|
+
errorCode: 'NTS-DBS-GLDS0',
|
|
249
|
+
addECToUserMsg: true,
|
|
250
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
251
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`
|
|
224
252
|
});
|
|
225
253
|
}
|
|
226
254
|
}
|
|
@@ -239,14 +267,16 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
239
267
|
if (this.depDataName) {
|
|
240
268
|
filter[this.depDataName] = { $in: narrowByDependencyIds };
|
|
241
269
|
} else {
|
|
242
|
-
throw new
|
|
270
|
+
throw new Dynamo_Error({
|
|
243
271
|
status: 501,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
272
|
+
errorCode: 'NTS-DBS-SD0',
|
|
273
|
+
addECToUserMsg: true,
|
|
274
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
275
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`
|
|
247
276
|
});
|
|
248
277
|
}
|
|
249
278
|
}
|
|
279
|
+
|
|
250
280
|
await this.dataParams.modelParams.forEach((modelParam: DynamoNTS_DataPropertyParams) => {
|
|
251
281
|
if ((searchBy[modelParam.key] !== null && searchBy[modelParam.key] !== undefined) || searchBy[modelParam.key + 'Range']) {
|
|
252
282
|
if (modelParam.key.includes('Range') || modelParam.type.includes('[]')) {
|
|
@@ -291,18 +321,22 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
291
321
|
dataList = res;
|
|
292
322
|
}
|
|
293
323
|
}).catch(error => {
|
|
294
|
-
throw new
|
|
324
|
+
throw new Dynamo_Error({
|
|
295
325
|
status: 417,
|
|
296
|
-
|
|
297
|
-
|
|
326
|
+
errorCode: 'NTS-DBS-SD1',
|
|
327
|
+
addECToUserMsg: true,
|
|
328
|
+
message: `search ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
329
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
298
330
|
error
|
|
299
331
|
});
|
|
300
332
|
});
|
|
333
|
+
|
|
301
334
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
302
335
|
dataList.forEach((data: T) => {
|
|
303
336
|
data._id = `˙${data._id}`;
|
|
304
337
|
});
|
|
305
338
|
}
|
|
339
|
+
|
|
306
340
|
return dataList as T[];
|
|
307
341
|
}
|
|
308
342
|
|
|
@@ -326,7 +360,7 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
326
360
|
data = null;
|
|
327
361
|
}
|
|
328
362
|
}).catch(error => {
|
|
329
|
-
throw new
|
|
363
|
+
throw new Dynamo_Error({ status: 417, message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`, error });
|
|
330
364
|
});
|
|
331
365
|
if (data && typeof data._id === 'object') {
|
|
332
366
|
data._id = `${data._id}`;
|
|
@@ -340,23 +374,28 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
340
374
|
*/
|
|
341
375
|
async getAll(): Promise<T[]> {
|
|
342
376
|
let dataList = [];
|
|
377
|
+
|
|
343
378
|
await this.dataModel.find({}).then(res => {
|
|
344
379
|
if (res) {
|
|
345
380
|
dataList = res;
|
|
346
381
|
}
|
|
347
382
|
}).catch(error => {
|
|
348
|
-
throw new
|
|
383
|
+
throw new Dynamo_Error({
|
|
349
384
|
status: 417,
|
|
350
|
-
|
|
351
|
-
|
|
385
|
+
errorCode: 'NTS-DBS-GA0',
|
|
386
|
+
addECToUserMsg: true,
|
|
387
|
+
message: `get all ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
388
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
352
389
|
error
|
|
353
390
|
});
|
|
354
391
|
});
|
|
392
|
+
|
|
355
393
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
356
394
|
dataList.forEach((data: T) => {
|
|
357
395
|
data._id = `˙${data._id}`;
|
|
358
396
|
});
|
|
359
397
|
}
|
|
398
|
+
|
|
360
399
|
return dataList as T[];
|
|
361
400
|
}
|
|
362
401
|
|
|
@@ -366,10 +405,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
366
405
|
*/
|
|
367
406
|
async deleteDataById(id: string): Promise<void> {
|
|
368
407
|
await this.dataModel.findByIdAndDelete(id).catch(error => {
|
|
369
|
-
throw new
|
|
408
|
+
throw new Dynamo_Error({
|
|
370
409
|
status: 417,
|
|
371
|
-
|
|
372
|
-
|
|
410
|
+
errorCode: 'NTS-DBS-DD0',
|
|
411
|
+
addECToUserMsg: true,
|
|
412
|
+
message: `delete ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
413
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
373
414
|
error
|
|
374
415
|
});
|
|
375
416
|
});
|
|
@@ -382,19 +423,22 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
382
423
|
async deleteDataByDependencyId(dependencyId: string): Promise<void> {
|
|
383
424
|
if (this.depDataName) {
|
|
384
425
|
await this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
|
|
385
|
-
throw new
|
|
426
|
+
throw new Dynamo_Error({
|
|
386
427
|
status: 417,
|
|
387
|
-
|
|
388
|
-
|
|
428
|
+
errorCode: 'NTS-DBS-DDD1',
|
|
429
|
+
addECToUserMsg: true,
|
|
430
|
+
message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
431
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
389
432
|
error
|
|
390
433
|
});
|
|
391
434
|
});
|
|
392
435
|
} else {
|
|
393
|
-
throw new
|
|
436
|
+
throw new Dynamo_Error({
|
|
394
437
|
status: 501,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
438
|
+
errorCode: 'NTS-DBS-DDD0',
|
|
439
|
+
addECToUserMsg: true,
|
|
440
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
441
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`
|
|
398
442
|
});
|
|
399
443
|
}
|
|
400
444
|
}
|
|
@@ -432,10 +476,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
432
476
|
data = null;
|
|
433
477
|
}
|
|
434
478
|
}).catch(error => {
|
|
435
|
-
throw new
|
|
479
|
+
throw new Dynamo_Error({
|
|
436
480
|
status: 417,
|
|
437
|
-
|
|
438
|
-
|
|
481
|
+
errorCode: 'NTS-DBS-FO0',
|
|
482
|
+
addECToUserMsg: true,
|
|
483
|
+
message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
484
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
439
485
|
error
|
|
440
486
|
});
|
|
441
487
|
});
|
|
@@ -465,23 +511,28 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
465
511
|
*/
|
|
466
512
|
async find(filter: any): Promise<T[]> {
|
|
467
513
|
let dataList = [];
|
|
514
|
+
|
|
468
515
|
await this.dataModel.find(filter).then(res => {
|
|
469
516
|
if (res) {
|
|
470
517
|
dataList = res;
|
|
471
518
|
}
|
|
472
519
|
}).catch(error => {
|
|
473
|
-
throw new
|
|
520
|
+
throw new Dynamo_Error({
|
|
474
521
|
status: 417,
|
|
475
|
-
|
|
476
|
-
|
|
522
|
+
errorCode: 'NTS-DBS-F0',
|
|
523
|
+
addECToUserMsg: true,
|
|
524
|
+
message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
525
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
477
526
|
error
|
|
478
527
|
});
|
|
479
528
|
});
|
|
529
|
+
|
|
480
530
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
481
531
|
dataList.forEach((data: T) => {
|
|
482
532
|
data._id = `˙${data._id}`;
|
|
483
533
|
});
|
|
484
534
|
}
|
|
535
|
+
|
|
485
536
|
return dataList as T[];
|
|
486
537
|
}
|
|
487
538
|
|
|
@@ -517,18 +568,22 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
517
568
|
dataList = res;
|
|
518
569
|
}
|
|
519
570
|
}).catch(error => {
|
|
520
|
-
throw new
|
|
571
|
+
throw new Dynamo_Error({
|
|
521
572
|
status: 417,
|
|
522
|
-
|
|
523
|
-
|
|
573
|
+
errorCode: 'NTS-DBS-WP0',
|
|
574
|
+
addECToUserMsg: true,
|
|
575
|
+
message: `findWithPaging ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
576
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
524
577
|
error
|
|
525
578
|
});
|
|
526
579
|
});
|
|
580
|
+
|
|
527
581
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
528
582
|
dataList.forEach((data: T) => {
|
|
529
583
|
data._id = `˙${data._id}`;
|
|
530
584
|
});
|
|
531
585
|
}
|
|
586
|
+
|
|
532
587
|
return dataList;
|
|
533
588
|
}
|
|
534
589
|
|
|
@@ -542,23 +597,27 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
542
597
|
let data: T;
|
|
543
598
|
update.__lastModified = new Date();
|
|
544
599
|
update.__lastModifiedBy = modifier;
|
|
600
|
+
|
|
545
601
|
await this.dataModel.findByIdAndUpdate(id, update).then(res => {
|
|
546
602
|
if (res) {
|
|
547
603
|
data = res.toObject() as T;
|
|
548
604
|
} else {
|
|
549
|
-
throw new
|
|
605
|
+
throw new Dynamo_Error({
|
|
550
606
|
status: 204,
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
607
|
+
errorCode: 'NTS-DBS-FIU1',
|
|
608
|
+
addECToUserMsg: true,
|
|
609
|
+
message: `${this.dataParams.dbName} not found! (NTS DB)`,
|
|
610
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`
|
|
554
611
|
});
|
|
555
612
|
}
|
|
556
613
|
}).catch(error => {
|
|
557
|
-
throw new
|
|
614
|
+
throw new Dynamo_Error({
|
|
558
615
|
status: 417,
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
616
|
+
errorCode: 'NTS-DBS-FIU0',
|
|
617
|
+
addECToUserMsg: true,
|
|
618
|
+
message: `findByIdAndUpdate ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
619
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
620
|
+
error
|
|
562
621
|
});
|
|
563
622
|
});
|
|
564
623
|
update.__v = data.__v;
|
|
@@ -601,10 +660,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
601
660
|
update.__lastModified = new Date();
|
|
602
661
|
update.__lastModifiedBy = modifier;
|
|
603
662
|
await this.dataModel.updateOne(updateBy, update).catch(error => {
|
|
604
|
-
throw new
|
|
663
|
+
throw new Dynamo_Error({
|
|
605
664
|
status: 417,
|
|
606
|
-
|
|
607
|
-
|
|
665
|
+
errorCode: 'NTS-DBS-UO0',
|
|
666
|
+
addECToUserMsg: true,
|
|
667
|
+
message: `updateOne ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
668
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
608
669
|
error
|
|
609
670
|
});
|
|
610
671
|
});
|
|
@@ -644,11 +705,14 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
644
705
|
async updateMany(updateBy: any, update: any, modifier: string): Promise<void> {
|
|
645
706
|
update.__lastModified = new Date();
|
|
646
707
|
update.__lastModifiedBy = modifier;
|
|
708
|
+
|
|
647
709
|
await this.dataModel.updateMany(updateBy, update).catch(error => {
|
|
648
|
-
throw new
|
|
710
|
+
throw new Dynamo_Error({
|
|
649
711
|
status: 417,
|
|
650
|
-
|
|
651
|
-
|
|
712
|
+
errorCode: 'NTS-DBS-UM0',
|
|
713
|
+
addECToUserMsg: true,
|
|
714
|
+
message: `updateMany ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
715
|
+
userMessage: `We encountered an unhandled DB Error, please contact the responsible development team.`,
|
|
652
716
|
error
|
|
653
717
|
});
|
|
654
718
|
});
|
|
@@ -665,12 +729,14 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
665
729
|
*/
|
|
666
730
|
private getSchema(): mongoose.Schema {
|
|
667
731
|
let schema: any = this.buildMongooseSchemaByModelParams();
|
|
668
|
-
schema = this.
|
|
732
|
+
schema = this.addDynamo_MetadataToSchema(schema);
|
|
733
|
+
|
|
669
734
|
// tslint:disable-next-line: no-string-literal
|
|
670
735
|
if (schema['_id']) {
|
|
671
736
|
// tslint:disable-next-line: no-string-literal
|
|
672
737
|
delete schema['_id'];
|
|
673
738
|
}
|
|
739
|
+
|
|
674
740
|
return new Schema(schema);
|
|
675
741
|
}
|
|
676
742
|
|
|
@@ -681,9 +747,11 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
681
747
|
*/
|
|
682
748
|
private buildMongooseSchemaByModelParams(params?: DynamoNTS_DataPropertyParams[]): any {
|
|
683
749
|
const schemaSettingsObj = {};
|
|
750
|
+
|
|
684
751
|
if (!params) {
|
|
685
752
|
params = this.dataParams.modelParams;
|
|
686
753
|
}
|
|
754
|
+
|
|
687
755
|
params.forEach((property: DynamoNTS_DataPropertyParams) => {
|
|
688
756
|
const beType = this.getBEType(property.type);
|
|
689
757
|
if (beType !== Object || !property.subObjectParams) {
|
|
@@ -709,6 +777,7 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
709
777
|
schemaSettingsObj[property.key] = this.buildMongooseSchemaByModelParams(property.subObjectParams);
|
|
710
778
|
}
|
|
711
779
|
});
|
|
780
|
+
|
|
712
781
|
return schemaSettingsObj;
|
|
713
782
|
}
|
|
714
783
|
|
|
@@ -740,11 +809,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
740
809
|
* @param schema schema to update
|
|
741
810
|
* @returns updated schema
|
|
742
811
|
*/
|
|
743
|
-
private
|
|
812
|
+
private addDynamo_MetadataToSchema(schema: any): any {
|
|
744
813
|
schema.__created = { type: Date };
|
|
745
814
|
schema.__createdBy = { type: String };
|
|
746
815
|
schema.__lastModified = { type: Date };
|
|
747
816
|
schema.__lastModifiedBy = { type: String };
|
|
817
|
+
|
|
748
818
|
return schema;
|
|
749
819
|
}
|
|
750
820
|
|
|
@@ -3,7 +3,7 @@ import * as FileSystem from 'fs';
|
|
|
3
3
|
import * as Path from 'path';
|
|
4
4
|
import * as NodeMailer from 'nodemailer';
|
|
5
5
|
import { Options as MailOptions, Attachment } from 'nodemailer/lib/mailer';
|
|
6
|
-
import {
|
|
6
|
+
import { Dynamo_Error } from '@futdevpro/fsm-dynamo';
|
|
7
7
|
|
|
8
8
|
import { DynamoNTS_Shared } from './dynamo-nts-shared.service';
|
|
9
9
|
|
|
@@ -87,10 +87,11 @@ export class DynamoNTS_EmailService {
|
|
|
87
87
|
content = set.content
|
|
88
88
|
} else if (set.useTemplate) {
|
|
89
89
|
if (!this.templates[set.useTemplate]) {
|
|
90
|
-
throw new
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
throw new Dynamo_Error({
|
|
91
|
+
errorCode: 'NTS-ES4-101',
|
|
92
|
+
addECToUserMsg: true,
|
|
93
|
+
message: `No email template found with this parameter! (${set.useTemplate})`,
|
|
94
|
+
userMessage: `We encountered an uncought BackEnd Email Service Error, please contact the responsible development team.`
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
content = this.templates[set.useTemplate];
|
|
@@ -102,25 +103,27 @@ export class DynamoNTS_EmailService {
|
|
|
102
103
|
props += `${key}${index != this.templatePropertyKeys[set.useTemplate].length - 1 ? ', ' : ''}`;
|
|
103
104
|
});
|
|
104
105
|
DynamoNTS_Shared.logError('\nDynamoBEEmailService ERROR: INVALID sendEmail settings', set);
|
|
105
|
-
throw new
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
throw new Dynamo_Error({
|
|
107
|
+
errorCode: 'NTS-ES4-102',
|
|
108
|
+
addECToUserMsg: true,
|
|
109
|
+
message: `TemplateProperties missing! properties needed: ${props}`,
|
|
110
|
+
userMessage: `We encountered an uncought BackEnd Email Service Error, please contact the responsible development team.`
|
|
109
111
|
});
|
|
110
112
|
}
|
|
111
113
|
this.templatePropertyKeys[set.useTemplate].forEach((propertyKey: string) => {
|
|
112
114
|
if (!set.templateProperties[propertyKey]) {
|
|
113
|
-
DynamoNTS_Shared.logError(`
|
|
115
|
+
DynamoNTS_Shared.logError(`TemplateProperty missing! (${propertyKey})`);
|
|
114
116
|
}
|
|
115
117
|
const reg = new RegExp(`{{${propertyKey}}}`, 'g')
|
|
116
118
|
content = content.replace(reg, set.templateProperties[propertyKey]);
|
|
117
119
|
});
|
|
118
120
|
}
|
|
119
121
|
} else {
|
|
120
|
-
throw new
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
throw new Dynamo_Error({
|
|
123
|
+
errorCode: 'NTS-ES4-100',
|
|
124
|
+
addECToUserMsg: true,
|
|
125
|
+
message: 'No content setting passsed to emailSending!',
|
|
126
|
+
userMessage: `We encountered an uncought BackEnd Email Service Error, please contact the responsible development team.`,
|
|
124
127
|
});
|
|
125
128
|
}
|
|
126
129
|
|
|
@@ -195,10 +198,11 @@ export class DynamoNTS_EmailService {
|
|
|
195
198
|
while (propertyOpenTagIndex >= 0) {
|
|
196
199
|
if (propertyCloseTagIndex === -1) {
|
|
197
200
|
DynamoNTS_Shared.logError(`\nDynamoBEEmailService ERROR, missing closing tag from email template! (${propertyOpenTagIndex} -)`, propertyKeys);
|
|
198
|
-
throw new
|
|
201
|
+
throw new Dynamo_Error({
|
|
202
|
+
errorCode: 'NTS-ES4-200',
|
|
203
|
+
addECToUserMsg: true,
|
|
199
204
|
message: `ERROR, missing closing tag from email template! (${propertyOpenTagIndex} -)`,
|
|
200
|
-
userMessage: `We encountered an uncought BackEnd Email Service Error, please contact the responsible development team
|
|
201
|
-
error: new Error()
|
|
205
|
+
userMessage: `We encountered an uncought BackEnd Email Service Error, please contact the responsible development team.`
|
|
202
206
|
});
|
|
203
207
|
}
|
|
204
208
|
const newKey: string = template.substring(propertyOpenTagIndex + 2, propertyCloseTagIndex);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { Dynamo_Metadata, DynamoNTS_DataParams } from '@futdevpro/fsm-dynamo';
|
|
4
4
|
|
|
5
5
|
import { DynamoNTS_AuthService } from './dynamo-nts-auth.service';
|
|
6
6
|
import { DynamoNTS_DBServiceCollection } from './dynamo-nts-db-service-collection.service';
|
|
@@ -103,7 +103,7 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
103
103
|
* @param dataParams
|
|
104
104
|
* @returns
|
|
105
105
|
*/
|
|
106
|
-
static getDBService<T extends
|
|
106
|
+
static getDBService<T extends Dynamo_Metadata>(dataParams: DynamoNTS_DataParams): DynamoNTS_DBService<T> {
|
|
107
107
|
return this.getDBServiceByKey<T>(dataParams.dataName);
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -112,7 +112,7 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
112
112
|
* @param key
|
|
113
113
|
* @returns
|
|
114
114
|
*/
|
|
115
|
-
static getDBServiceByKey<T extends
|
|
115
|
+
static getDBServiceByKey<T extends Dynamo_Metadata>(key: string): DynamoNTS_DBService<T> {
|
|
116
116
|
const collection = this.getDBServiceCollection();
|
|
117
117
|
if (collection[key]) {
|
|
118
118
|
return collection[key] as DynamoNTS_DBService<T>;
|