@futdevpro/nts-dynamo 1.5.40 → 1.5.47
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.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/lib/_enums/http/socket-event.enum.d.ts +2 -0
- package/lib/_enums/http/socket-event.enum.d.ts.map +1 -1
- package/lib/_enums/http/socket-event.enum.js +2 -0
- package/lib/_enums/http/socket-event.enum.js.map +1 -1
- 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 +16 -0
- package/lib/_models/dynamo-nts-socket-dictionary.d.ts.map +1 -0
- package/lib/_models/dynamo-nts-socket-dictionary.js +31 -0
- package/lib/_models/dynamo-nts-socket-dictionary.js.map +1 -0
- package/lib/_models/dynamo-nts-socket-event-params.d.ts +2 -0
- package/lib/_models/dynamo-nts-socket-event-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-event-params.js +6 -5
- package/lib/_models/dynamo-nts-socket-event-params.js.map +1 -1
- package/lib/_models/index.d.ts +1 -0
- package/lib/_models/index.d.ts.map +1 -1
- package/lib/_models/index.js +1 -0
- package/lib/_models/index.js.map +1 -1
- package/lib/_modules/app-extended.index.d.ts +1 -0
- package/lib/_modules/app-extended.index.d.ts.map +1 -1
- package/lib/_modules/app-extended.index.js +1 -0
- package/lib/_modules/app-extended.index.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 +18 -10
- 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 +19 -8
- package/lib/_services/dynamo-nts-api.service.js.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.d.ts +1 -1
- package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.js +2 -4
- package/lib/_services/dynamo-nts-app-extended.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-app.js +4 -1
- package/lib/_services/dynamo-nts-app.js.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.js +10 -4
- package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
- package/lib/_services/dynamo-nts-controller.service.d.ts +37 -0
- package/lib/_services/dynamo-nts-controller.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-controller.service.js +37 -0
- package/lib/_services/dynamo-nts-controller.service.js.map +1 -1
- package/lib/_services/dynamo-nts-data.service.d.ts +21 -2
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +121 -53
- 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 +148 -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 +5 -5
- 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-shared.service.d.ts +6 -0
- package/lib/_services/dynamo-nts-shared.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-shared.service.js +8 -0
- package/lib/_services/dynamo-nts-shared.service.js.map +1 -1
- package/lib/_services/dynamo-nts-socket-service-collection.service.d.ts +1 -1
- package/lib/_services/dynamo-nts-socket-service-collection.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.d.ts +6 -9
- package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.js +25 -20
- package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
- package/lib/_services/dynamobe-api.service.js +2 -2
- package/lib/_services/dynamobe-auth.service.js +2 -2
- package/lib/_services/dynamobe-data.service.d.ts +2 -2
- package/lib/_services/dynamobe-data.service.js +15 -15
- package/lib/_services/dynamobe-db.service.d.ts +4 -4
- package/lib/_services/dynamobe-db.service.js +28 -28
- package/lib/_services/dynamobe-email.service.js +4 -4
- package/lib/_services/dynamobe-global.service.d.ts +3 -3
- package/lib/_services/dynamobe-routing-module.service.js +3 -3
- package/lib/tsconfig.tsbuildinfo +1 -5564
- package/package.json +22 -12
- package/src/_enums/http/socket-event.enum.ts +2 -0
- package/src/_models/dynamo-nts-endpoint-params.ts +1 -1
- package/src/_models/dynamo-nts-socket-dictionary.ts +39 -0
- package/src/_models/dynamo-nts-socket-event-params.ts +8 -5
- package/src/_models/index.ts +1 -0
- package/src/_modules/app-extended.index.ts +1 -0
- 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 +34 -26
- package/src/_services/dynamo-nts-api.service.ts +26 -9
- package/src/_services/dynamo-nts-app-extended.ts +9 -9
- package/src/_services/dynamo-nts-app.ts +2 -2
- package/src/_services/dynamo-nts-auth.service.ts +13 -5
- package/src/_services/dynamo-nts-controller.service.ts +37 -0
- package/src/_services/dynamo-nts-data.service.ts +123 -55
- package/src/_services/dynamo-nts-db.service.ts +181 -87
- package/src/_services/dynamo-nts-email.service.ts +21 -17
- package/src/_services/dynamo-nts-global.service.ts +12 -5
- package/src/_services/dynamo-nts-routing-module.service.ts +16 -10
- package/src/_services/dynamo-nts-shared.service.ts +9 -0
- package/src/_services/dynamo-nts-socket-service-collection.service.ts +1 -1
- package/src/_services/dynamo-nts-socket.service.ts +33 -29
|
@@ -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,30 +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
|
|
43
|
-
status: 204,
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
throw new Dynamo_Error({
|
|
45
|
+
status: 204,
|
|
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.`
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
52
|
}).catch(error => {
|
|
49
|
-
throw new
|
|
50
|
-
status: 422,
|
|
51
|
-
|
|
53
|
+
throw new Dynamo_Error({
|
|
54
|
+
status: 422,
|
|
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.`,
|
|
52
59
|
error
|
|
53
60
|
});
|
|
54
61
|
});
|
|
62
|
+
|
|
55
63
|
if (typeof newData._id === 'object') {
|
|
56
64
|
newData._id = `${newData._id}`;
|
|
57
65
|
}
|
|
58
66
|
data._id = newData._id;
|
|
59
67
|
data.__v = newData.__v;
|
|
68
|
+
|
|
60
69
|
return data;
|
|
61
70
|
}
|
|
62
71
|
|
|
@@ -68,26 +77,35 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
68
77
|
async modifyData(data: T, modifier: string): Promise<T> {
|
|
69
78
|
data.__lastModified = new Date();
|
|
70
79
|
data.__lastModifiedBy = modifier;
|
|
80
|
+
|
|
71
81
|
const dataModel = new this.dataModel(data);
|
|
72
82
|
let newData: T;
|
|
83
|
+
|
|
73
84
|
await this.dataModel.findByIdAndUpdate(data._id, dataModel).then(res => {
|
|
74
85
|
if (res) {
|
|
75
86
|
newData = res.toObject() as T;
|
|
76
87
|
} else {
|
|
77
|
-
throw new
|
|
78
|
-
status: 204,
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
throw new Dynamo_Error({
|
|
89
|
+
status: 204,
|
|
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.`
|
|
81
94
|
});
|
|
82
95
|
}
|
|
83
96
|
}).catch(error => {
|
|
84
|
-
throw new
|
|
85
|
-
status: 417,
|
|
86
|
-
|
|
97
|
+
throw new Dynamo_Error({
|
|
98
|
+
status: 417,
|
|
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.`,
|
|
87
103
|
error
|
|
88
104
|
});
|
|
89
105
|
});
|
|
106
|
+
|
|
90
107
|
data.__v = newData.__v;
|
|
108
|
+
|
|
91
109
|
return data;
|
|
92
110
|
}
|
|
93
111
|
|
|
@@ -98,6 +116,7 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
98
116
|
*/
|
|
99
117
|
async getDataById(id: string): Promise<T> {
|
|
100
118
|
let data: T;
|
|
119
|
+
|
|
101
120
|
await this.dataModel.findById(id).then(res => {
|
|
102
121
|
if (res) {
|
|
103
122
|
data = res.toObject() as T;
|
|
@@ -105,15 +124,20 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
105
124
|
data = null;
|
|
106
125
|
}
|
|
107
126
|
}).catch(error => {
|
|
108
|
-
throw new
|
|
109
|
-
status: 417,
|
|
110
|
-
|
|
127
|
+
throw new Dynamo_Error({
|
|
128
|
+
status: 417,
|
|
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.`,
|
|
111
133
|
error
|
|
112
134
|
});
|
|
113
135
|
});
|
|
136
|
+
|
|
114
137
|
if (data && typeof data._id === 'object') {
|
|
115
138
|
data._id = `${data._id}`;
|
|
116
139
|
}
|
|
140
|
+
|
|
117
141
|
return data;
|
|
118
142
|
}
|
|
119
143
|
|
|
@@ -132,9 +156,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
132
156
|
data = null;
|
|
133
157
|
}
|
|
134
158
|
}).catch(error => {
|
|
135
|
-
throw new
|
|
136
|
-
status: 417,
|
|
137
|
-
|
|
159
|
+
throw new Dynamo_Error({
|
|
160
|
+
status: 417,
|
|
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.`,
|
|
138
165
|
error
|
|
139
166
|
});
|
|
140
167
|
});
|
|
@@ -143,10 +170,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
143
170
|
}
|
|
144
171
|
return data;
|
|
145
172
|
} else {
|
|
146
|
-
throw new
|
|
147
|
-
status: 501,
|
|
148
|
-
|
|
149
|
-
|
|
173
|
+
throw new Dynamo_Error({
|
|
174
|
+
status: 501,
|
|
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.`
|
|
150
179
|
});
|
|
151
180
|
}
|
|
152
181
|
}
|
|
@@ -164,9 +193,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
164
193
|
dataList = res;
|
|
165
194
|
}
|
|
166
195
|
}).catch(error => {
|
|
167
|
-
throw new
|
|
168
|
-
status: 417,
|
|
169
|
-
|
|
196
|
+
throw new Dynamo_Error({
|
|
197
|
+
status: 417,
|
|
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.`,
|
|
170
202
|
error
|
|
171
203
|
});
|
|
172
204
|
});
|
|
@@ -177,10 +209,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
177
209
|
}
|
|
178
210
|
return dataList;
|
|
179
211
|
} else {
|
|
180
|
-
throw new
|
|
181
|
-
status: 501,
|
|
182
|
-
|
|
183
|
-
|
|
212
|
+
throw new Dynamo_Error({
|
|
213
|
+
status: 501,
|
|
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.`
|
|
184
218
|
});
|
|
185
219
|
}
|
|
186
220
|
}
|
|
@@ -198,18 +232,23 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
198
232
|
dataList = res;
|
|
199
233
|
}
|
|
200
234
|
}).catch(error => {
|
|
201
|
-
throw new
|
|
202
|
-
status: 417,
|
|
203
|
-
|
|
235
|
+
throw new Dynamo_Error({
|
|
236
|
+
status: 417,
|
|
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.`,
|
|
204
241
|
error
|
|
205
242
|
});
|
|
206
243
|
});
|
|
207
244
|
return dataList;
|
|
208
245
|
} else {
|
|
209
|
-
throw new
|
|
210
|
-
status: 501,
|
|
211
|
-
|
|
212
|
-
|
|
246
|
+
throw new Dynamo_Error({
|
|
247
|
+
status: 501,
|
|
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.`
|
|
213
252
|
});
|
|
214
253
|
}
|
|
215
254
|
}
|
|
@@ -228,13 +267,16 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
228
267
|
if (this.depDataName) {
|
|
229
268
|
filter[this.depDataName] = { $in: narrowByDependencyIds };
|
|
230
269
|
} else {
|
|
231
|
-
throw new
|
|
232
|
-
status: 501,
|
|
233
|
-
|
|
234
|
-
|
|
270
|
+
throw new Dynamo_Error({
|
|
271
|
+
status: 501,
|
|
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.`
|
|
235
276
|
});
|
|
236
277
|
}
|
|
237
278
|
}
|
|
279
|
+
|
|
238
280
|
await this.dataParams.modelParams.forEach((modelParam: DynamoNTS_DataPropertyParams) => {
|
|
239
281
|
if ((searchBy[modelParam.key] !== null && searchBy[modelParam.key] !== undefined) || searchBy[modelParam.key + 'Range']) {
|
|
240
282
|
if (modelParam.key.includes('Range') || modelParam.type.includes('[]')) {
|
|
@@ -279,17 +321,22 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
279
321
|
dataList = res;
|
|
280
322
|
}
|
|
281
323
|
}).catch(error => {
|
|
282
|
-
throw new
|
|
283
|
-
status: 417,
|
|
284
|
-
|
|
324
|
+
throw new Dynamo_Error({
|
|
325
|
+
status: 417,
|
|
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.`,
|
|
285
330
|
error
|
|
286
331
|
});
|
|
287
332
|
});
|
|
333
|
+
|
|
288
334
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
289
335
|
dataList.forEach((data: T) => {
|
|
290
336
|
data._id = `˙${data._id}`;
|
|
291
337
|
});
|
|
292
338
|
}
|
|
339
|
+
|
|
293
340
|
return dataList as T[];
|
|
294
341
|
}
|
|
295
342
|
|
|
@@ -313,7 +360,7 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
313
360
|
data = null;
|
|
314
361
|
}
|
|
315
362
|
}).catch(error => {
|
|
316
|
-
throw new
|
|
363
|
+
throw new Dynamo_Error({ status: 417, message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`, error });
|
|
317
364
|
});
|
|
318
365
|
if (data && typeof data._id === 'object') {
|
|
319
366
|
data._id = `${data._id}`;
|
|
@@ -327,22 +374,28 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
327
374
|
*/
|
|
328
375
|
async getAll(): Promise<T[]> {
|
|
329
376
|
let dataList = [];
|
|
377
|
+
|
|
330
378
|
await this.dataModel.find({}).then(res => {
|
|
331
379
|
if (res) {
|
|
332
380
|
dataList = res;
|
|
333
381
|
}
|
|
334
382
|
}).catch(error => {
|
|
335
|
-
throw new
|
|
336
|
-
status: 417,
|
|
337
|
-
|
|
383
|
+
throw new Dynamo_Error({
|
|
384
|
+
status: 417,
|
|
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.`,
|
|
338
389
|
error
|
|
339
390
|
});
|
|
340
391
|
});
|
|
392
|
+
|
|
341
393
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
342
394
|
dataList.forEach((data: T) => {
|
|
343
395
|
data._id = `˙${data._id}`;
|
|
344
396
|
});
|
|
345
397
|
}
|
|
398
|
+
|
|
346
399
|
return dataList as T[];
|
|
347
400
|
}
|
|
348
401
|
|
|
@@ -352,9 +405,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
352
405
|
*/
|
|
353
406
|
async deleteDataById(id: string): Promise<void> {
|
|
354
407
|
await this.dataModel.findByIdAndDelete(id).catch(error => {
|
|
355
|
-
throw new
|
|
356
|
-
status: 417,
|
|
357
|
-
|
|
408
|
+
throw new Dynamo_Error({
|
|
409
|
+
status: 417,
|
|
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.`,
|
|
358
414
|
error
|
|
359
415
|
});
|
|
360
416
|
});
|
|
@@ -367,17 +423,22 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
367
423
|
async deleteDataByDependencyId(dependencyId: string): Promise<void> {
|
|
368
424
|
if (this.depDataName) {
|
|
369
425
|
await this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
|
|
370
|
-
throw new
|
|
371
|
-
status: 417,
|
|
372
|
-
|
|
426
|
+
throw new Dynamo_Error({
|
|
427
|
+
status: 417,
|
|
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.`,
|
|
373
432
|
error
|
|
374
433
|
});
|
|
375
434
|
});
|
|
376
435
|
} else {
|
|
377
|
-
throw new
|
|
378
|
-
status: 501,
|
|
379
|
-
|
|
380
|
-
|
|
436
|
+
throw new Dynamo_Error({
|
|
437
|
+
status: 501,
|
|
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.`
|
|
381
442
|
});
|
|
382
443
|
}
|
|
383
444
|
}
|
|
@@ -415,9 +476,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
415
476
|
data = null;
|
|
416
477
|
}
|
|
417
478
|
}).catch(error => {
|
|
418
|
-
throw new
|
|
419
|
-
status: 417,
|
|
420
|
-
|
|
479
|
+
throw new Dynamo_Error({
|
|
480
|
+
status: 417,
|
|
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.`,
|
|
421
485
|
error
|
|
422
486
|
});
|
|
423
487
|
});
|
|
@@ -447,22 +511,28 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
447
511
|
*/
|
|
448
512
|
async find(filter: any): Promise<T[]> {
|
|
449
513
|
let dataList = [];
|
|
514
|
+
|
|
450
515
|
await this.dataModel.find(filter).then(res => {
|
|
451
516
|
if (res) {
|
|
452
517
|
dataList = res;
|
|
453
518
|
}
|
|
454
519
|
}).catch(error => {
|
|
455
|
-
throw new
|
|
456
|
-
status: 417,
|
|
457
|
-
|
|
520
|
+
throw new Dynamo_Error({
|
|
521
|
+
status: 417,
|
|
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.`,
|
|
458
526
|
error
|
|
459
527
|
});
|
|
460
528
|
});
|
|
529
|
+
|
|
461
530
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
462
531
|
dataList.forEach((data: T) => {
|
|
463
532
|
data._id = `˙${data._id}`;
|
|
464
533
|
});
|
|
465
534
|
}
|
|
535
|
+
|
|
466
536
|
return dataList as T[];
|
|
467
537
|
}
|
|
468
538
|
|
|
@@ -498,17 +568,22 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
498
568
|
dataList = res;
|
|
499
569
|
}
|
|
500
570
|
}).catch(error => {
|
|
501
|
-
throw new
|
|
502
|
-
status: 417,
|
|
503
|
-
|
|
571
|
+
throw new Dynamo_Error({
|
|
572
|
+
status: 417,
|
|
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.`,
|
|
504
577
|
error
|
|
505
578
|
});
|
|
506
579
|
});
|
|
580
|
+
|
|
507
581
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
508
582
|
dataList.forEach((data: T) => {
|
|
509
583
|
data._id = `˙${data._id}`;
|
|
510
584
|
});
|
|
511
585
|
}
|
|
586
|
+
|
|
512
587
|
return dataList;
|
|
513
588
|
}
|
|
514
589
|
|
|
@@ -522,21 +597,27 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
522
597
|
let data: T;
|
|
523
598
|
update.__lastModified = new Date();
|
|
524
599
|
update.__lastModifiedBy = modifier;
|
|
600
|
+
|
|
525
601
|
await this.dataModel.findByIdAndUpdate(id, update).then(res => {
|
|
526
602
|
if (res) {
|
|
527
603
|
data = res.toObject() as T;
|
|
528
604
|
} else {
|
|
529
|
-
throw new
|
|
530
|
-
status: 204,
|
|
531
|
-
|
|
532
|
-
|
|
605
|
+
throw new Dynamo_Error({
|
|
606
|
+
status: 204,
|
|
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.`
|
|
533
611
|
});
|
|
534
612
|
}
|
|
535
613
|
}).catch(error => {
|
|
536
|
-
throw new
|
|
537
|
-
status: 417,
|
|
538
|
-
|
|
539
|
-
|
|
614
|
+
throw new Dynamo_Error({
|
|
615
|
+
status: 417,
|
|
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
|
|
540
621
|
});
|
|
541
622
|
});
|
|
542
623
|
update.__v = data.__v;
|
|
@@ -579,9 +660,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
579
660
|
update.__lastModified = new Date();
|
|
580
661
|
update.__lastModifiedBy = modifier;
|
|
581
662
|
await this.dataModel.updateOne(updateBy, update).catch(error => {
|
|
582
|
-
throw new
|
|
583
|
-
status: 417,
|
|
584
|
-
|
|
663
|
+
throw new Dynamo_Error({
|
|
664
|
+
status: 417,
|
|
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.`,
|
|
585
669
|
error
|
|
586
670
|
});
|
|
587
671
|
});
|
|
@@ -621,10 +705,14 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
621
705
|
async updateMany(updateBy: any, update: any, modifier: string): Promise<void> {
|
|
622
706
|
update.__lastModified = new Date();
|
|
623
707
|
update.__lastModifiedBy = modifier;
|
|
708
|
+
|
|
624
709
|
await this.dataModel.updateMany(updateBy, update).catch(error => {
|
|
625
|
-
throw new
|
|
626
|
-
status: 417,
|
|
627
|
-
|
|
710
|
+
throw new Dynamo_Error({
|
|
711
|
+
status: 417,
|
|
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.`,
|
|
628
716
|
error
|
|
629
717
|
});
|
|
630
718
|
});
|
|
@@ -641,12 +729,14 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
641
729
|
*/
|
|
642
730
|
private getSchema(): mongoose.Schema {
|
|
643
731
|
let schema: any = this.buildMongooseSchemaByModelParams();
|
|
644
|
-
schema = this.
|
|
732
|
+
schema = this.addDynamo_MetadataToSchema(schema);
|
|
733
|
+
|
|
645
734
|
// tslint:disable-next-line: no-string-literal
|
|
646
735
|
if (schema['_id']) {
|
|
647
736
|
// tslint:disable-next-line: no-string-literal
|
|
648
737
|
delete schema['_id'];
|
|
649
738
|
}
|
|
739
|
+
|
|
650
740
|
return new Schema(schema);
|
|
651
741
|
}
|
|
652
742
|
|
|
@@ -657,9 +747,11 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
657
747
|
*/
|
|
658
748
|
private buildMongooseSchemaByModelParams(params?: DynamoNTS_DataPropertyParams[]): any {
|
|
659
749
|
const schemaSettingsObj = {};
|
|
750
|
+
|
|
660
751
|
if (!params) {
|
|
661
752
|
params = this.dataParams.modelParams;
|
|
662
753
|
}
|
|
754
|
+
|
|
663
755
|
params.forEach((property: DynamoNTS_DataPropertyParams) => {
|
|
664
756
|
const beType = this.getBEType(property.type);
|
|
665
757
|
if (beType !== Object || !property.subObjectParams) {
|
|
@@ -685,6 +777,7 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
685
777
|
schemaSettingsObj[property.key] = this.buildMongooseSchemaByModelParams(property.subObjectParams);
|
|
686
778
|
}
|
|
687
779
|
});
|
|
780
|
+
|
|
688
781
|
return schemaSettingsObj;
|
|
689
782
|
}
|
|
690
783
|
|
|
@@ -716,11 +809,12 @@ export class DynamoNTS_DBService<T extends Metadata> {
|
|
|
716
809
|
* @param schema schema to update
|
|
717
810
|
* @returns updated schema
|
|
718
811
|
*/
|
|
719
|
-
private
|
|
812
|
+
private addDynamo_MetadataToSchema(schema: any): any {
|
|
720
813
|
schema.__created = { type: Date };
|
|
721
814
|
schema.__createdBy = { type: String };
|
|
722
815
|
schema.__lastModified = { type: Date };
|
|
723
816
|
schema.__lastModifiedBy = { type: String };
|
|
817
|
+
|
|
724
818
|
return schema;
|
|
725
819
|
}
|
|
726
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);
|