@futdevpro/nts-dynamo 1.5.17 → 1.5.20
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-module-settings.d.ts +3 -0
- package/lib/_models/dynamo-module-settings.d.ts.map +1 -1
- package/lib/_models/dynamobe-app-params.d.ts +3 -0
- package/lib/_models/dynamobe-app-params.d.ts.map +1 -1
- package/lib/_models/dynamobe-app-params.js +3 -0
- package/lib/_models/dynamobe-app-params.js.map +1 -1
- package/lib/_models/dynamobe-endpoint-params.d.ts +17 -1
- package/lib/_models/dynamobe-endpoint-params.d.ts.map +1 -1
- package/lib/_models/dynamobe-endpoint-params.js +16 -0
- package/lib/_models/dynamobe-endpoint-params.js.map +1 -1
- package/lib/_models/dynamobe-global-settings.d.ts +3 -0
- package/lib/_models/dynamobe-global-settings.d.ts.map +1 -1
- package/lib/_modules/usage/usage.service.d.ts.map +1 -1
- package/lib/_modules/usage/usage.service.js +20 -4
- package/lib/_modules/usage/usage.service.js.map +1 -1
- package/lib/_services/dynamobe-api.service.d.ts +9 -0
- package/lib/_services/dynamobe-api.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-api.service.js +20 -3
- package/lib/_services/dynamobe-api.service.js.map +1 -1
- package/lib/_services/dynamobe-app.d.ts +24 -0
- package/lib/_services/dynamobe-app.d.ts.map +1 -1
- package/lib/_services/dynamobe-app.js +28 -4
- package/lib/_services/dynamobe-app.js.map +1 -1
- package/lib/_services/dynamobe-auth.service.d.ts +13 -0
- package/lib/_services/dynamobe-auth.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-auth.service.js +8 -2
- package/lib/_services/dynamobe-auth.service.js.map +1 -1
- package/lib/_services/dynamobe-controller.service.d.ts +3 -0
- package/lib/_services/dynamobe-controller.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-controller.service.js +3 -0
- package/lib/_services/dynamobe-controller.service.js.map +1 -1
- package/lib/_services/dynamobe-data.service.d.ts +8 -4
- package/lib/_services/dynamobe-data.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-data.service.js +87 -32
- package/lib/_services/dynamobe-data.service.js.map +1 -1
- package/lib/_services/dynamobe-db-service-collection.service.d.ts +3 -0
- package/lib/_services/dynamobe-db-service-collection.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-db-service-collection.service.js +3 -0
- package/lib/_services/dynamobe-db-service-collection.service.js.map +1 -1
- package/lib/_services/dynamobe-db.service.d.ts +110 -15
- package/lib/_services/dynamobe-db.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-db.service.js +237 -63
- package/lib/_services/dynamobe-db.service.js.map +1 -1
- package/lib/_services/dynamobe-email.service.d.ts +22 -0
- package/lib/_services/dynamobe-email.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-email.service.js +45 -11
- package/lib/_services/dynamobe-email.service.js.map +1 -1
- package/lib/_services/dynamobe-global.service.d.ts +22 -0
- package/lib/_services/dynamobe-global.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-global.service.js +22 -0
- package/lib/_services/dynamobe-global.service.js.map +1 -1
- package/lib/_services/dynamobe-routing-module.service.d.ts +15 -0
- package/lib/_services/dynamobe-routing-module.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-routing-module.service.js +28 -3
- package/lib/_services/dynamobe-routing-module.service.js.map +1 -1
- package/lib/_services/dynamobe-shared.service.d.ts +18 -0
- package/lib/_services/dynamobe-shared.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-shared.service.js +18 -0
- package/lib/_services/dynamobe-shared.service.js.map +1 -1
- package/lib/_services/dynamobe-singleton.service.d.ts +3 -0
- package/lib/_services/dynamobe-singleton.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-singleton.service.js +3 -0
- package/lib/_services/dynamobe-singleton.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +33 -47
- package/package.json +11 -11
- package/src/_models/dynamo-module-settings.ts +3 -1
- package/src/_models/dynamobe-app-params.ts +3 -0
- package/src/_models/dynamobe-endpoint-params.ts +17 -1
- package/src/_models/dynamobe-global-settings.ts +3 -0
- package/src/_modules/usage/usage.service.ts +20 -4
- package/src/_services/dynamobe-api.service.ts +20 -3
- package/src/_services/dynamobe-app.ts +28 -4
- package/src/_services/dynamobe-auth.service.ts +21 -2
- package/src/_services/dynamobe-controller.service.ts +3 -0
- package/src/_services/dynamobe-data.service.ts +89 -32
- package/src/_services/dynamobe-db-service-collection.service.ts +3 -0
- package/src/_services/dynamobe-db.service.ts +224 -48
- package/src/_services/dynamobe-email.service.ts +45 -11
- package/src/_services/dynamobe-global.service.ts +22 -0
- package/src/_services/dynamobe-routing-module.service.ts +28 -3
- package/src/_services/dynamobe-shared.service.ts +18 -0
- package/src/_services/dynamobe-singleton.service.ts +3 -0
- package/src/_models/dynamobe-data-model-params.ts +0 -24
|
@@ -3,6 +3,9 @@ import * as mongoose from 'mongoose';
|
|
|
3
3
|
import { Schema } from 'mongoose';
|
|
4
4
|
import { Metadata, DynamoBEDataParams, DynamoBEDataPropertyParams, DynamoBEError } from '@futdevpro/fsm-dynamo';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
6
9
|
export class DynamoBEDBService<T extends Metadata> {
|
|
7
10
|
dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
|
|
8
11
|
|
|
@@ -36,10 +39,17 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
36
39
|
if (res) {
|
|
37
40
|
newData = res.toObject() as T;
|
|
38
41
|
} else {
|
|
39
|
-
throw new DynamoBEError({
|
|
42
|
+
throw new DynamoBEError({
|
|
43
|
+
status: 204, message: `${this.dataParams.dbName} not found! (BD)`,
|
|
44
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-401`,
|
|
45
|
+
});
|
|
40
46
|
}
|
|
41
47
|
}).catch(error => {
|
|
42
|
-
throw new DynamoBEError({
|
|
48
|
+
throw new DynamoBEError({
|
|
49
|
+
status: 422, message: `Create new ${this.dataParams.dbName} was unsuccessful (BD)`,
|
|
50
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-400`,
|
|
51
|
+
error
|
|
52
|
+
});
|
|
43
53
|
});
|
|
44
54
|
if (typeof newData._id === 'object') {
|
|
45
55
|
newData._id = `${newData._id}`;
|
|
@@ -63,10 +73,17 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
63
73
|
if (res) {
|
|
64
74
|
newData = res.toObject() as T;
|
|
65
75
|
} else {
|
|
66
|
-
throw new DynamoBEError({
|
|
76
|
+
throw new DynamoBEError({
|
|
77
|
+
status: 204, message: `${this.dataParams.dbName} not found! (BD)`,
|
|
78
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-411`,
|
|
79
|
+
});
|
|
67
80
|
}
|
|
68
81
|
}).catch(error => {
|
|
69
|
-
throw new DynamoBEError({
|
|
82
|
+
throw new DynamoBEError({
|
|
83
|
+
status: 417, message: `modify ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
84
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-410`,
|
|
85
|
+
error
|
|
86
|
+
});
|
|
70
87
|
});
|
|
71
88
|
data.__v = newData.__v;
|
|
72
89
|
return data;
|
|
@@ -86,7 +103,11 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
86
103
|
data = null;
|
|
87
104
|
}
|
|
88
105
|
}).catch(error => {
|
|
89
|
-
throw new DynamoBEError({
|
|
106
|
+
throw new DynamoBEError({
|
|
107
|
+
status: 417, message: `get ${this.dataParams.dbName} by ID was unsuccessful (DB)`,
|
|
108
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-430`,
|
|
109
|
+
error
|
|
110
|
+
});
|
|
90
111
|
});
|
|
91
112
|
if (data && typeof data._id === 'object') {
|
|
92
113
|
data._id = `${data._id}`;
|
|
@@ -109,14 +130,21 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
109
130
|
data = null;
|
|
110
131
|
}
|
|
111
132
|
}).catch(error => {
|
|
112
|
-
throw new DynamoBEError({
|
|
133
|
+
throw new DynamoBEError({
|
|
134
|
+
status: 417, message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (DB)`,
|
|
135
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-441`,
|
|
136
|
+
error
|
|
137
|
+
});
|
|
113
138
|
});
|
|
114
139
|
if (data && typeof data._id === 'object') {
|
|
115
140
|
data._id = `${data._id}`;
|
|
116
141
|
}
|
|
117
142
|
return data;
|
|
118
143
|
} else {
|
|
119
|
-
throw new DynamoBEError({
|
|
144
|
+
throw new DynamoBEError({
|
|
145
|
+
status: 501, message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (BD)`,
|
|
146
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-440`,
|
|
147
|
+
});
|
|
120
148
|
}
|
|
121
149
|
}
|
|
122
150
|
|
|
@@ -133,7 +161,11 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
133
161
|
dataList = res;
|
|
134
162
|
}
|
|
135
163
|
}).catch(error => {
|
|
136
|
-
throw new DynamoBEError({
|
|
164
|
+
throw new DynamoBEError({
|
|
165
|
+
status: 417, message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (DB)`,
|
|
166
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-451`,
|
|
167
|
+
error
|
|
168
|
+
});
|
|
137
169
|
});
|
|
138
170
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
139
171
|
dataList.forEach((data: T) => {
|
|
@@ -142,7 +174,10 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
142
174
|
}
|
|
143
175
|
return dataList;
|
|
144
176
|
} else {
|
|
145
|
-
throw new DynamoBEError({
|
|
177
|
+
throw new DynamoBEError({
|
|
178
|
+
status: 501, message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (BD)`,
|
|
179
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-450`,
|
|
180
|
+
});
|
|
146
181
|
}
|
|
147
182
|
}
|
|
148
183
|
|
|
@@ -159,11 +194,18 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
159
194
|
dataList = res;
|
|
160
195
|
}
|
|
161
196
|
}).catch(error => {
|
|
162
|
-
throw new DynamoBEError({
|
|
197
|
+
throw new DynamoBEError({
|
|
198
|
+
status: 417, message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (DB)`,
|
|
199
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-461`,
|
|
200
|
+
error
|
|
201
|
+
});
|
|
163
202
|
});
|
|
164
203
|
return dataList;
|
|
165
204
|
} else {
|
|
166
|
-
throw new DynamoBEError({
|
|
205
|
+
throw new DynamoBEError({
|
|
206
|
+
status: 501, message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (BD)`,
|
|
207
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-460`,
|
|
208
|
+
});
|
|
167
209
|
}
|
|
168
210
|
}
|
|
169
211
|
|
|
@@ -181,7 +223,10 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
181
223
|
if (this.depDataName) {
|
|
182
224
|
filter[this.depDataName] = { $in: narrowByDependencyIds };
|
|
183
225
|
} else {
|
|
184
|
-
throw new DynamoBEError({
|
|
226
|
+
throw new DynamoBEError({
|
|
227
|
+
status: 501, message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (BD)`,
|
|
228
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-470`,
|
|
229
|
+
});
|
|
185
230
|
}
|
|
186
231
|
}
|
|
187
232
|
await this.dataParams.modelParams.forEach((modelParam: DynamoBEDataPropertyParams) => {
|
|
@@ -228,7 +273,11 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
228
273
|
dataList = res;
|
|
229
274
|
}
|
|
230
275
|
}).catch(error => {
|
|
231
|
-
throw new DynamoBEError({
|
|
276
|
+
throw new DynamoBEError({
|
|
277
|
+
status: 417, message: `search ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
278
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-471`,
|
|
279
|
+
error
|
|
280
|
+
});
|
|
232
281
|
});
|
|
233
282
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
234
283
|
dataList.forEach((data: T) => {
|
|
@@ -240,11 +289,17 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
240
289
|
|
|
241
290
|
/**
|
|
242
291
|
* find data by any of its parameters, throws error if not found
|
|
243
|
-
* @param data
|
|
292
|
+
* @param data
|
|
293
|
+
* (always use unique parameters for find!)
|
|
294
|
+
* etc.: by email:
|
|
295
|
+
* { email: email }
|
|
296
|
+
* or by id that is in list:
|
|
244
297
|
* { userIds: { $in: this.userId } }
|
|
298
|
+
* or by number or Date that is greater than OR less than:
|
|
299
|
+
* { points: { $gte: 2, $lte: 14 } }
|
|
245
300
|
* @returns data
|
|
246
301
|
*/
|
|
247
|
-
async findData(data: T): Promise<T> {
|
|
302
|
+
/* async findData(data: T): Promise<T> {
|
|
248
303
|
await this.dataModel.findOne(data).then(res => {
|
|
249
304
|
if (res) {
|
|
250
305
|
data = res.toObject() as T;
|
|
@@ -258,7 +313,7 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
258
313
|
data._id = `${data._id}`;
|
|
259
314
|
}
|
|
260
315
|
return data;
|
|
261
|
-
}
|
|
316
|
+
} */
|
|
262
317
|
|
|
263
318
|
/**
|
|
264
319
|
* returns all data from database, throws error if not found
|
|
@@ -271,7 +326,11 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
271
326
|
dataList = res;
|
|
272
327
|
}
|
|
273
328
|
}).catch(error => {
|
|
274
|
-
throw new DynamoBEError({
|
|
329
|
+
throw new DynamoBEError({
|
|
330
|
+
status: 417, message: `get all ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
331
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-480`,
|
|
332
|
+
error
|
|
333
|
+
});
|
|
275
334
|
});
|
|
276
335
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
277
336
|
dataList.forEach((data: T) => {
|
|
@@ -281,27 +340,17 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
281
340
|
return dataList as T[];
|
|
282
341
|
}
|
|
283
342
|
|
|
284
|
-
/**
|
|
285
|
-
* update one parameter by a specific
|
|
286
|
-
* { _id: pictureId }, { approved: true }
|
|
287
|
-
* @param updateBy etc.: { email: email } (always use unique parameters for find!)
|
|
288
|
-
* @param update etc.: { $inc: { popularity: this.newVote.amount }, emailVerified: true }
|
|
289
|
-
*/
|
|
290
|
-
/* async updateOneParameter(updateBy: any, update: any, modifier: string): Promise<void> {
|
|
291
|
-
update.__lastModified = new Date();
|
|
292
|
-
update.__lastModifiedBy = modifier;
|
|
293
|
-
await this.dataModel.updateOne(updateBy, update).catch(error => {
|
|
294
|
-
throw new DynamoBEError({ status: 417, message: `update one parameter on ${this.dataParams.dbName} was unsuccessful (DB)`, error });
|
|
295
|
-
});
|
|
296
|
-
} */
|
|
297
|
-
|
|
298
343
|
/**
|
|
299
344
|
* deleted data by id
|
|
300
345
|
* @param id id
|
|
301
346
|
*/
|
|
302
347
|
async deleteDataById(id: string): Promise<void> {
|
|
303
348
|
await this.dataModel.findByIdAndDelete(id).catch(error => {
|
|
304
|
-
throw new DynamoBEError({
|
|
349
|
+
throw new DynamoBEError({
|
|
350
|
+
status: 417, message: `delete ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
351
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-490`,
|
|
352
|
+
error
|
|
353
|
+
});
|
|
305
354
|
});
|
|
306
355
|
}
|
|
307
356
|
|
|
@@ -312,10 +361,17 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
312
361
|
async deleteDataByDependencyId(dependencyId: string): Promise<void> {
|
|
313
362
|
if (this.depDataName) {
|
|
314
363
|
await this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
|
|
315
|
-
throw new DynamoBEError({
|
|
364
|
+
throw new DynamoBEError({
|
|
365
|
+
status: 417, message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (DB)`,
|
|
366
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-591`,
|
|
367
|
+
error
|
|
368
|
+
});
|
|
316
369
|
});
|
|
317
370
|
} else {
|
|
318
|
-
throw new DynamoBEError({
|
|
371
|
+
throw new DynamoBEError({
|
|
372
|
+
status: 501, message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (BD)`,
|
|
373
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-590`,
|
|
374
|
+
});
|
|
319
375
|
}
|
|
320
376
|
}
|
|
321
377
|
|
|
@@ -326,7 +382,21 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
326
382
|
|
|
327
383
|
/**
|
|
328
384
|
* find the data first by any of its parameters, throws error if not found
|
|
329
|
-
* @param filter
|
|
385
|
+
* @param filter
|
|
386
|
+
* (always use unique parameters for find!)
|
|
387
|
+
* etc.: by email:
|
|
388
|
+
* { email: email }
|
|
389
|
+
* or by id that is in list:
|
|
390
|
+
* { userIds: { $in: this.userId } }
|
|
391
|
+
* or by number or Date that is GREATER THAN OR LESS THAN:
|
|
392
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
393
|
+
* further tools (syntax matches with $gt):
|
|
394
|
+
* $eq: Matches values that are EQUAL to a specified value.
|
|
395
|
+
* $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
|
|
396
|
+
* $lte: Matches values that are LESS THAN or EQUAL to a specified value.
|
|
397
|
+
* $ne: Matches all values that are NOT EQUAL to a specified value.
|
|
398
|
+
* $nin: Matches NONE of the values specified IN an array.
|
|
399
|
+
*
|
|
330
400
|
* @returns data
|
|
331
401
|
*/
|
|
332
402
|
async findOne(filter: any): Promise<T> {
|
|
@@ -338,7 +408,11 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
338
408
|
data = null;
|
|
339
409
|
}
|
|
340
410
|
}).catch(error => {
|
|
341
|
-
throw new DynamoBEError({
|
|
411
|
+
throw new DynamoBEError({
|
|
412
|
+
status: 417, message: `findOne ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
413
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-510`,
|
|
414
|
+
error
|
|
415
|
+
});
|
|
342
416
|
});
|
|
343
417
|
if (data && typeof data._id === 'object') {
|
|
344
418
|
data._id = `${data._id}`;
|
|
@@ -348,7 +422,20 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
348
422
|
|
|
349
423
|
/**
|
|
350
424
|
* find all data by any of its parameters, throws error if not found
|
|
351
|
-
* @param filter
|
|
425
|
+
* @param filter
|
|
426
|
+
* etc.: by email:
|
|
427
|
+
* { email: email }
|
|
428
|
+
* or by id that is in list:
|
|
429
|
+
* { userIds: { $in: this.userId } }
|
|
430
|
+
* or by number or Date that is GREATER THAN OR LESS THAN:
|
|
431
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
432
|
+
* further tools (syntax matches with $gt):
|
|
433
|
+
* $eq: Matches values that are EQUAL to a specified value.
|
|
434
|
+
* $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
|
|
435
|
+
* $lte: Matches values that are LESS THAN or EQUAL to a specified value.
|
|
436
|
+
* $ne: Matches all values that are NOT EQUAL to a specified value.
|
|
437
|
+
* $nin: Matches NONE of the values specified IN an array.
|
|
438
|
+
*
|
|
352
439
|
* @returns dataList
|
|
353
440
|
*/
|
|
354
441
|
async find(filter: any): Promise<T[]> {
|
|
@@ -358,7 +445,11 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
358
445
|
dataList = res;
|
|
359
446
|
}
|
|
360
447
|
}).catch(error => {
|
|
361
|
-
throw new DynamoBEError({
|
|
448
|
+
throw new DynamoBEError({
|
|
449
|
+
status: 417, message: `find ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
450
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-520`,
|
|
451
|
+
error
|
|
452
|
+
});
|
|
362
453
|
});
|
|
363
454
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
364
455
|
dataList.forEach((data: T) => {
|
|
@@ -370,7 +461,20 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
370
461
|
|
|
371
462
|
/**
|
|
372
463
|
* find all data by any of its parameters, throws error if not found
|
|
373
|
-
* @param filter
|
|
464
|
+
* @param filter
|
|
465
|
+
* etc.: by email:
|
|
466
|
+
* { email: email }
|
|
467
|
+
* or by id that is in list:
|
|
468
|
+
* { userIds: { $in: this.userId } }
|
|
469
|
+
* or by number or Date that is GREATER THAN OR LESS THAN:
|
|
470
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
471
|
+
* further tools (syntax matches with $gt):
|
|
472
|
+
* $eq: Matches values that are EQUAL to a specified value.
|
|
473
|
+
* $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
|
|
474
|
+
* $lte: Matches values that are LESS THAN or EQUAL to a specified value.
|
|
475
|
+
* $ne: Matches all values that are NOT EQUAL to a specified value.
|
|
476
|
+
* $nin: Matches NONE of the values specified IN an array.
|
|
477
|
+
*
|
|
374
478
|
* @param page page
|
|
375
479
|
* @param pageSize pageSize
|
|
376
480
|
* @param sort etc. by dateTime: { dateTime: -1 }
|
|
@@ -387,7 +491,11 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
387
491
|
dataList = res;
|
|
388
492
|
}
|
|
389
493
|
}).catch(error => {
|
|
390
|
-
throw new DynamoBEError({
|
|
494
|
+
throw new DynamoBEError({
|
|
495
|
+
status: 417, message: `findWithPaging ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
496
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-530`,
|
|
497
|
+
error
|
|
498
|
+
});
|
|
391
499
|
});
|
|
392
500
|
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
393
501
|
dataList.forEach((data: T) => {
|
|
@@ -411,10 +519,17 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
411
519
|
if (res) {
|
|
412
520
|
data = res.toObject() as T;
|
|
413
521
|
} else {
|
|
414
|
-
throw new DynamoBEError({
|
|
522
|
+
throw new DynamoBEError({
|
|
523
|
+
status: 204, message: `${this.dataParams.dbName} not found! (BD)`,
|
|
524
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-541`,
|
|
525
|
+
});
|
|
415
526
|
}
|
|
416
527
|
}).catch(error => {
|
|
417
|
-
throw new DynamoBEError({
|
|
528
|
+
throw new DynamoBEError({
|
|
529
|
+
status: 417, message: `findByIdAndUpdate ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
530
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-540`,
|
|
531
|
+
error
|
|
532
|
+
});
|
|
418
533
|
});
|
|
419
534
|
update.__v = data.__v;
|
|
420
535
|
return update;
|
|
@@ -422,27 +537,88 @@ export class DynamoBEDBService<T extends Metadata> {
|
|
|
422
537
|
|
|
423
538
|
/**
|
|
424
539
|
* update one parameter by a specific
|
|
425
|
-
* @param updateBy
|
|
426
|
-
*
|
|
540
|
+
* @param updateBy
|
|
541
|
+
* (always use unique parameters for find!)
|
|
542
|
+
* etc.: by email:
|
|
543
|
+
* { email: email }
|
|
544
|
+
* or by id that is in list:
|
|
545
|
+
* { userIds: { $in: this.userId } }
|
|
546
|
+
* or by number or Date that is GREATER THAN OR LESS THAN:
|
|
547
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
548
|
+
* further tools (syntax matches with $gt):
|
|
549
|
+
* $eq: Matches values that are EQUAL to a specified value.
|
|
550
|
+
* $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
|
|
551
|
+
* $lte: Matches values that are LESS THAN or EQUAL to a specified value.
|
|
552
|
+
* $ne: Matches all values that are NOT EQUAL to a specified value.
|
|
553
|
+
* $nin: Matches NONE of the values specified IN an array.
|
|
554
|
+
*
|
|
555
|
+
* @param update
|
|
556
|
+
* etc.: increase a specific value:
|
|
557
|
+
* { $inc: { popularity: 15 } }
|
|
558
|
+
* or add element to a list:
|
|
559
|
+
* { $push: { reactions: this.newReaction }
|
|
560
|
+
* or all at once
|
|
561
|
+
* { $inc: { popularity: this.newVote.amount }, emailVerified: true, $push: { reactions: this.newReaction } }
|
|
562
|
+
* further tools (syntax matches with $inc):
|
|
563
|
+
* $currentDate: Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
564
|
+
* $min: Only updates the field if the specified value is less than the existing field value.
|
|
565
|
+
* $max: Only updates the field if the specified value is greater than the existing field value.
|
|
566
|
+
* $mul: Multiplies the value of the field by the specified amount.
|
|
567
|
+
* $rename: Renames a field.
|
|
568
|
+
* $unset: Removes the specified field from a document. (set: "" to value)
|
|
427
569
|
*/
|
|
428
570
|
async updateOne(updateBy: any, update: any, modifier: string): Promise<void> {
|
|
429
571
|
update.__lastModified = new Date();
|
|
430
572
|
update.__lastModifiedBy = modifier;
|
|
431
573
|
await this.dataModel.updateOne(updateBy, update).catch(error => {
|
|
432
|
-
throw new DynamoBEError({
|
|
574
|
+
throw new DynamoBEError({
|
|
575
|
+
status: 417, message: `updateOne ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
576
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-550`,
|
|
577
|
+
error
|
|
578
|
+
});
|
|
433
579
|
});
|
|
434
580
|
}
|
|
435
581
|
|
|
436
582
|
/**
|
|
437
583
|
* update one parameter by a specific
|
|
438
|
-
* @param updateBy
|
|
439
|
-
*
|
|
584
|
+
* @param updateBy
|
|
585
|
+
* etc.: by email:
|
|
586
|
+
* { email: email }
|
|
587
|
+
* or by id that is in list:
|
|
588
|
+
* { userIds: { $in: this.userId } }
|
|
589
|
+
* or by number or Date that is GREATER THAN OR LESS THAN:
|
|
590
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
591
|
+
* further tools (syntax matches with $gt):
|
|
592
|
+
* $eq: Matches values that are EQUAL to a specified value.
|
|
593
|
+
* $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
|
|
594
|
+
* $lte: Matches values that are LESS THAN or EQUAL to a specified value.
|
|
595
|
+
* $ne: Matches all values that are NOT EQUAL to a specified value.
|
|
596
|
+
* $nin: Matches NONE of the values specified IN an array.
|
|
597
|
+
*
|
|
598
|
+
* @param update
|
|
599
|
+
* etc.: increase a specific value:
|
|
600
|
+
* { $inc: { popularity: 15 } }
|
|
601
|
+
* or add element to a list:
|
|
602
|
+
* { $push: { reactions: this.newReaction }
|
|
603
|
+
* or all at once
|
|
604
|
+
* { $inc: { popularity: this.newVote.amount }, emailVerified: true, $push: { reactions: this.newReaction } }
|
|
605
|
+
* further tools (syntax matches with $inc):
|
|
606
|
+
* $currentDate: Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
607
|
+
* $min: Only updates the field if the specified value is less than the existing field value.
|
|
608
|
+
* $max: Only updates the field if the specified value is greater than the existing field value.
|
|
609
|
+
* $mul: Multiplies the value of the field by the specified amount.
|
|
610
|
+
* $rename: Renames a field.
|
|
611
|
+
* $unset: Removes the specified field from a document. (set: "" to value)
|
|
440
612
|
*/
|
|
441
613
|
async updateMany(updateBy: any, update: any, modifier: string): Promise<void> {
|
|
442
614
|
update.__lastModified = new Date();
|
|
443
615
|
update.__lastModifiedBy = modifier;
|
|
444
616
|
await this.dataModel.updateMany(updateBy, update).catch(error => {
|
|
445
|
-
throw new DynamoBEError({
|
|
617
|
+
throw new DynamoBEError({
|
|
618
|
+
status: 417, message: `updateMany ${this.dataParams.dbName} was unsuccessful (DB)`,
|
|
619
|
+
userMessage: `We encountered an uncought DB Error, please contact the responsible development team. errorcode: 505-223-560`,
|
|
620
|
+
error
|
|
621
|
+
});
|
|
446
622
|
});
|
|
447
623
|
}
|
|
448
624
|
|
|
@@ -7,6 +7,9 @@ import { DynamoBEError } from '@futdevpro/fsm-dynamo';
|
|
|
7
7
|
|
|
8
8
|
import { DBE_Shared } from './dynamobe-shared.service';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
10
13
|
export class DynamoBEEmailService {
|
|
11
14
|
private nmTransporter: NodeMailer.Transporter;
|
|
12
15
|
private senderName: string;
|
|
@@ -52,14 +55,21 @@ export class DynamoBEEmailService {
|
|
|
52
55
|
this.constructionFinished();
|
|
53
56
|
}
|
|
54
57
|
} catch (error) {
|
|
55
|
-
|
|
58
|
+
DBE_Shared.logError(`\nDynamoBEEmailService ERROR, The emailService construction failed for ${set.email}.`, new Error());
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
*/
|
|
59
65
|
private constructionFinished(): void {
|
|
60
66
|
DBE_Shared.logSuccess(`\nEmailService construction (${this.senderName}) Finished!\n`)
|
|
61
67
|
}
|
|
62
68
|
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param set
|
|
72
|
+
*/
|
|
63
73
|
public async sendEmail(set: {
|
|
64
74
|
to: string,
|
|
65
75
|
subject: string,
|
|
@@ -77,24 +87,33 @@ export class DynamoBEEmailService {
|
|
|
77
87
|
content = set.content
|
|
78
88
|
} else if (set.useTemplate) {
|
|
79
89
|
if (!this.templates[set.useTemplate]) {
|
|
80
|
-
throw new DynamoBEError({
|
|
90
|
+
throw new DynamoBEError({
|
|
91
|
+
message: `no template found with this parameter! (${set.useTemplate})`,
|
|
92
|
+
userMessage: `We encountered an uncought BackEnd Email Service Error, please contact the responsible development team. errorcode: 701-114-101`,
|
|
93
|
+
});
|
|
81
94
|
}
|
|
82
95
|
content = this.templates[set.useTemplate];
|
|
83
96
|
|
|
84
97
|
if (this.templatePropertyKeys[set.useTemplate].length > 0) {
|
|
85
98
|
if (!set.templateProperties) {
|
|
86
|
-
throw new DynamoBEError({
|
|
99
|
+
throw new DynamoBEError({
|
|
100
|
+
message: `templateProperties missing!`,
|
|
101
|
+
userMessage: `We encountered an uncought BackEnd Email Service Error, please contact the responsible development team. errorcode: 701-114-102`,
|
|
102
|
+
});
|
|
87
103
|
}
|
|
88
104
|
this.templatePropertyKeys[set.useTemplate].forEach((propertyKey: string) => {
|
|
89
105
|
if (!set.templateProperties[propertyKey]) {
|
|
90
|
-
|
|
106
|
+
DBE_Shared.logError(`templateProperty missing! (${propertyKey})`);
|
|
91
107
|
}
|
|
92
108
|
const reg = new RegExp(`{{${propertyKey}}}`, 'g')
|
|
93
109
|
content = content.replace(reg, set.templateProperties[propertyKey]);
|
|
94
110
|
})
|
|
95
111
|
}
|
|
96
112
|
} else {
|
|
97
|
-
throw new DynamoBEError({
|
|
113
|
+
throw new DynamoBEError({
|
|
114
|
+
message: 'no content setting passsed to emailSending!',
|
|
115
|
+
userMessage: `We encountered an uncought BackEnd Email Service Error, please contact the responsible development team. errorcode: 701-114-100`,
|
|
116
|
+
});
|
|
98
117
|
}
|
|
99
118
|
|
|
100
119
|
let mailOptions: MailOptions = {
|
|
@@ -112,10 +131,17 @@ export class DynamoBEEmailService {
|
|
|
112
131
|
}
|
|
113
132
|
});
|
|
114
133
|
} catch (error) {
|
|
115
|
-
|
|
134
|
+
DBE_Shared.logError('\nDynamoBEEmailService ERROR, email sending error', error);
|
|
116
135
|
}
|
|
117
136
|
}
|
|
118
137
|
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
* @param templateName
|
|
141
|
+
* @param rootPath
|
|
142
|
+
* @param templatePath
|
|
143
|
+
* @returns
|
|
144
|
+
*/
|
|
119
145
|
private async loadTemplate(templateName: string, rootPath: string, templatePath: string): Promise<void> {
|
|
120
146
|
try {
|
|
121
147
|
this.templateLoadingInProgressCounter++;
|
|
@@ -123,7 +149,7 @@ export class DynamoBEEmailService {
|
|
|
123
149
|
templatePath = Path.join(rootPath, templatePath);
|
|
124
150
|
FileSystem.readFile(templatePath, 'utf8' , (err, template) => {
|
|
125
151
|
if (err) {
|
|
126
|
-
|
|
152
|
+
DBE_Shared.logError(`\nDynamoBEEmailService readFile ERROR (0), Couldn't load email template; ${templateName} from ${templatePath}\nerror:\n`, err, '\n');
|
|
127
153
|
reject(err);
|
|
128
154
|
return;
|
|
129
155
|
} else {
|
|
@@ -139,10 +165,15 @@ export class DynamoBEEmailService {
|
|
|
139
165
|
});
|
|
140
166
|
});
|
|
141
167
|
} catch (error) {
|
|
142
|
-
|
|
168
|
+
DBE_Shared.logError(`\nDynamoBEEmailService ERROR (1), Couldn't load email template; ${templateName} from ${templatePath}`, new Error());
|
|
143
169
|
}
|
|
144
170
|
}
|
|
145
171
|
|
|
172
|
+
/**
|
|
173
|
+
*
|
|
174
|
+
* @param template
|
|
175
|
+
* @returns
|
|
176
|
+
*/
|
|
146
177
|
private getTemplatePropertyKeys(template: string): string[] {
|
|
147
178
|
try {
|
|
148
179
|
const propertyKeys: string[] = [];
|
|
@@ -150,8 +181,11 @@ export class DynamoBEEmailService {
|
|
|
150
181
|
let propertyCloseTagIndex = template.indexOf('}}', propertyOpenTagIndex + 2);
|
|
151
182
|
while (propertyOpenTagIndex >= 0) {
|
|
152
183
|
if (propertyCloseTagIndex === -1) {
|
|
153
|
-
|
|
154
|
-
throw new DynamoBEError({
|
|
184
|
+
DBE_Shared.logError(`\nDynamoBEEmailService ERROR, missing closing tag from email template! (${propertyOpenTagIndex} -)`, propertyKeys);
|
|
185
|
+
throw new DynamoBEError({
|
|
186
|
+
message: `ERROR, missing closing tag from email template! (${propertyOpenTagIndex} -)`,
|
|
187
|
+
userMessage: `We encountered an uncought BackEnd Email Service Error, please contact the responsible development team. errorcode: 701-114-200`,
|
|
188
|
+
});
|
|
155
189
|
}
|
|
156
190
|
const newKey: string = template.substring(propertyOpenTagIndex + 2, propertyCloseTagIndex);
|
|
157
191
|
if (!propertyKeys.includes(newKey)) {
|
|
@@ -163,7 +197,7 @@ export class DynamoBEEmailService {
|
|
|
163
197
|
// console.log('\n\n\nTEST propertyKeys: ', propertyKeys);
|
|
164
198
|
return propertyKeys;
|
|
165
199
|
} catch (error) {
|
|
166
|
-
|
|
200
|
+
DBE_Shared.logError(`\nDynamoBEEmailService ERROR, getTemplatePropertyKeys ERROR`, new Error(), '\ntemplate:\n', template);
|
|
167
201
|
}
|
|
168
202
|
}
|
|
169
203
|
}
|
|
@@ -55,6 +55,10 @@ export class DBE_Global_S extends DynamoBESingletonService {
|
|
|
55
55
|
this.instance.emailServiceCollection = set.emailServiceCollection;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
58
62
|
static getAuthService(): DynamoBEAuthService {
|
|
59
63
|
if (!this.instance?.authService?.authenticateToken) {
|
|
60
64
|
throw new Error(
|
|
@@ -65,6 +69,10 @@ export class DBE_Global_S extends DynamoBESingletonService {
|
|
|
65
69
|
return this.instance.authService;
|
|
66
70
|
}
|
|
67
71
|
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
68
76
|
static getDBServiceCollection(): DynamoBEDBServiceCollection {
|
|
69
77
|
if (!this.instance?.dbServiceCollection) {
|
|
70
78
|
throw new Error(
|
|
@@ -75,10 +83,20 @@ export class DBE_Global_S extends DynamoBESingletonService {
|
|
|
75
83
|
return this.instance.dbServiceCollection;
|
|
76
84
|
}
|
|
77
85
|
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* @param dataParams
|
|
89
|
+
* @returns
|
|
90
|
+
*/
|
|
78
91
|
static getDBService<T extends Metadata>(dataParams: DynamoBEDataParams): DynamoBEDBService<T> {
|
|
79
92
|
return this.getDBServiceByKey<T>(dataParams.dataName);
|
|
80
93
|
}
|
|
81
94
|
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param key
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
82
100
|
static getDBServiceByKey<T extends Metadata>(key: string): DynamoBEDBService<T> {
|
|
83
101
|
const collection = this.getDBServiceCollection();
|
|
84
102
|
if (collection[key]) {
|
|
@@ -94,6 +112,10 @@ export class DBE_Global_S extends DynamoBESingletonService {
|
|
|
94
112
|
}
|
|
95
113
|
}
|
|
96
114
|
|
|
115
|
+
/**
|
|
116
|
+
*
|
|
117
|
+
* @returns
|
|
118
|
+
*/
|
|
97
119
|
static getEmailServiceCollection(): DynamoBEEmailServiceCollection {
|
|
98
120
|
if (!this.instance?.emailServiceCollection) {
|
|
99
121
|
throw new Error(
|