@futdevpro/nts-dynamo 1.5.18 → 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 +6 -2
- package/lib/_services/dynamobe-data.service.d.ts.map +1 -1
- package/lib/_services/dynamobe-data.service.js +76 -26
- 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 +78 -26
- 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
|
@@ -13,7 +13,8 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
13
13
|
depKey?: string;
|
|
14
14
|
depDBServiceKey?: string;
|
|
15
15
|
|
|
16
|
-
dataModelParams?: DynamoBEDataPropertyParams[] = [];
|
|
16
|
+
// dataModelParams?: DynamoBEDataPropertyParams[] = [];
|
|
17
|
+
dataParams: DynamoBEDataParams;
|
|
17
18
|
|
|
18
19
|
constructor(
|
|
19
20
|
data: T,
|
|
@@ -22,7 +23,8 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
22
23
|
) {
|
|
23
24
|
this.dataDBService = DBE_Global_S.getDBService<T>(dataParams);
|
|
24
25
|
this.data = data;
|
|
25
|
-
this.
|
|
26
|
+
this.dataParams = dataParams;
|
|
27
|
+
// this.dataModelParams = dataParams.modelParams;
|
|
26
28
|
this.lookForDependencyDataSettings();
|
|
27
29
|
this.issuer = issuer;
|
|
28
30
|
}
|
|
@@ -36,7 +38,11 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
36
38
|
this.dataList = dataList;
|
|
37
39
|
});
|
|
38
40
|
} catch (error) {
|
|
39
|
-
throw new DynamoBEError({
|
|
41
|
+
throw new DynamoBEError({
|
|
42
|
+
status: 417, message: 'getAll was unsuccessful',
|
|
43
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-130`,
|
|
44
|
+
error: error
|
|
45
|
+
});
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
|
|
@@ -55,10 +61,17 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
55
61
|
});
|
|
56
62
|
return dataExists;
|
|
57
63
|
} else {
|
|
58
|
-
throw new DynamoBEError({
|
|
64
|
+
throw new DynamoBEError({
|
|
65
|
+
status: 417, message: 'ID is missing!',
|
|
66
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-131B`,
|
|
67
|
+
});
|
|
59
68
|
}
|
|
60
69
|
} catch (error) {
|
|
61
|
-
throw new DynamoBEError({
|
|
70
|
+
throw new DynamoBEError({
|
|
71
|
+
status: 417, message: 'getDataById was unsuccessful',
|
|
72
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-131A`,
|
|
73
|
+
error: error
|
|
74
|
+
});
|
|
62
75
|
}
|
|
63
76
|
}
|
|
64
77
|
|
|
@@ -79,13 +92,23 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
79
92
|
});
|
|
80
93
|
return dataExists;
|
|
81
94
|
} else {
|
|
82
|
-
throw new DynamoBEError({
|
|
95
|
+
throw new DynamoBEError({
|
|
96
|
+
status: 417, message: `${this.depKey} is missing!`,
|
|
97
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-132C`,
|
|
98
|
+
});
|
|
83
99
|
}
|
|
84
100
|
} else {
|
|
85
|
-
throw new DynamoBEError({
|
|
101
|
+
throw new DynamoBEError({
|
|
102
|
+
status: 417, message: 'dependencyDataIdKey is missing from service!',
|
|
103
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-132B`,
|
|
104
|
+
});
|
|
86
105
|
}
|
|
87
106
|
} catch (error) {
|
|
88
|
-
throw new DynamoBEError({
|
|
107
|
+
throw new DynamoBEError({
|
|
108
|
+
status: 417, message: 'getDataByDependencyId was unsuccessful',
|
|
109
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-132A`,
|
|
110
|
+
error: error
|
|
111
|
+
});
|
|
89
112
|
}
|
|
90
113
|
}
|
|
91
114
|
|
|
@@ -101,13 +124,23 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
101
124
|
this.dataList = data;
|
|
102
125
|
});
|
|
103
126
|
} else {
|
|
104
|
-
throw new DynamoBEError({
|
|
127
|
+
throw new DynamoBEError({
|
|
128
|
+
status: 417, message: `${this.depKey} is missing!`,
|
|
129
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-133C`,
|
|
130
|
+
});
|
|
105
131
|
}
|
|
106
132
|
} else {
|
|
107
|
-
throw new DynamoBEError({
|
|
133
|
+
throw new DynamoBEError({
|
|
134
|
+
status: 417, message: 'dependencyDataIdKey is missing from service!',
|
|
135
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-133B`,
|
|
136
|
+
});
|
|
108
137
|
}
|
|
109
138
|
} catch (error) {
|
|
110
|
-
throw new DynamoBEError({ status: 417,
|
|
139
|
+
throw new DynamoBEError({ status: 417,
|
|
140
|
+
message: 'getDataListByDependencyId was unsuccessful',
|
|
141
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-133A`,
|
|
142
|
+
error: error
|
|
143
|
+
});
|
|
111
144
|
}
|
|
112
145
|
}
|
|
113
146
|
|
|
@@ -147,7 +180,11 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
147
180
|
});
|
|
148
181
|
}
|
|
149
182
|
} catch (error) {
|
|
150
|
-
throw new DynamoBEError({
|
|
183
|
+
throw new DynamoBEError({
|
|
184
|
+
status: 417, message: `modifyData was unsuccessful (${this.dataParams.dataName})`,
|
|
185
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-222`,
|
|
186
|
+
error: error
|
|
187
|
+
});
|
|
151
188
|
}
|
|
152
189
|
}
|
|
153
190
|
|
|
@@ -162,7 +199,11 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
162
199
|
throw new DynamoBEError({ status: 417, message: 'ID is missing!' });
|
|
163
200
|
}
|
|
164
201
|
} catch (error) {
|
|
165
|
-
throw new DynamoBEError({
|
|
202
|
+
throw new DynamoBEError({
|
|
203
|
+
status: 417, message: 'deleteData was unsuccessful',
|
|
204
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-223`,
|
|
205
|
+
error: error
|
|
206
|
+
});
|
|
166
207
|
}
|
|
167
208
|
}
|
|
168
209
|
|
|
@@ -171,25 +212,29 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
171
212
|
*/
|
|
172
213
|
async validateForSave(): Promise<void> {
|
|
173
214
|
try {
|
|
174
|
-
for (let i = 0; i < this.
|
|
215
|
+
for (let i = 0; i < this.dataParams.modelParams.length; i++) {
|
|
175
216
|
// basic required validations
|
|
176
|
-
if ((this.
|
|
177
|
-
(this.
|
|
178
|
-
throw new DynamoBEError({ status: 422, message: `${this.
|
|
217
|
+
if ((this.dataParams.modelParams[i].required && (this.data[this.dataParams.modelParams[i].key] === null || this.data[this.dataParams.modelParams[i].key] === undefined)) ||
|
|
218
|
+
(this.dataParams.modelParams[i].index && (this.data[this.dataParams.modelParams[i].key] === null || this.data[this.dataParams.modelParams[i].key] === undefined))) {
|
|
219
|
+
throw new DynamoBEError({ status: 422, message: `${this.dataParams.modelParams[i].key} is missing! (${this.dataParams.modelParams[i].required ? 'required' : 'index'})` });
|
|
179
220
|
}
|
|
180
221
|
// specific Date validation
|
|
181
|
-
if (this.
|
|
182
|
-
throw new DynamoBEError({ status: 422, message: `${this.
|
|
222
|
+
if (this.dataParams.modelParams[i].type === 'Date' && !(new Date(this.data[this.dataParams.modelParams[i].key]) instanceof Date)) {
|
|
223
|
+
throw new DynamoBEError({ status: 422, message: `${this.dataParams.modelParams[i].key} is not a date!` });
|
|
183
224
|
}
|
|
184
225
|
// call additional validators
|
|
185
|
-
if (this.
|
|
186
|
-
for (let j = 0; j < this.
|
|
187
|
-
this.
|
|
226
|
+
if (this.dataParams.modelParams[i].additionalValidators) {
|
|
227
|
+
for (let j = 0; j < this.dataParams.modelParams[i].additionalValidators.length; j++) {
|
|
228
|
+
this.dataParams.modelParams[i].additionalValidators[j](this.data[this.dataParams.modelParams[i].key]);
|
|
188
229
|
}
|
|
189
230
|
}
|
|
190
231
|
}
|
|
191
232
|
} catch (error) {
|
|
192
|
-
throw new DynamoBEError({
|
|
233
|
+
throw new DynamoBEError({
|
|
234
|
+
status: 422, message: 'validateForSave was unsuccessful',
|
|
235
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-220`,
|
|
236
|
+
error: error
|
|
237
|
+
});
|
|
193
238
|
}
|
|
194
239
|
}
|
|
195
240
|
|
|
@@ -197,7 +242,7 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
197
242
|
* setting up dependency dataHook by DynamoBEDataModelParams
|
|
198
243
|
*/
|
|
199
244
|
private lookForDependencyDataSettings(): void {
|
|
200
|
-
const dependencyParam: DynamoBEDataPropertyParams = this.
|
|
245
|
+
const dependencyParam: DynamoBEDataPropertyParams = this.dataParams.modelParams.find((modelParams: DynamoBEDataPropertyParams) => modelParams.isDependencyHook);
|
|
201
246
|
if (dependencyParam) {
|
|
202
247
|
this.depKey = dependencyParam.key;
|
|
203
248
|
if (dependencyParam.dependencyName) {
|
|
@@ -206,11 +251,18 @@ export class DynamoBEDataService<T extends Metadata> {
|
|
|
206
251
|
}
|
|
207
252
|
}
|
|
208
253
|
|
|
254
|
+
/**
|
|
255
|
+
*
|
|
256
|
+
* @returns
|
|
257
|
+
*/
|
|
209
258
|
getDependencyDataDBService(): DynamoBEDBService<any> {
|
|
210
259
|
if (this.depDBServiceKey) {
|
|
211
|
-
return DBE_Global_S.
|
|
260
|
+
return DBE_Global_S.getDBService(this.dataParams);
|
|
212
261
|
} else {
|
|
213
|
-
throw new DynamoBEError({
|
|
262
|
+
throw new DynamoBEError({
|
|
263
|
+
status: 501, message: 'getDependencyDataDBService was unsuccessful, service key not setted up!',
|
|
264
|
+
userMessage: `We encountered a DB Error, please contact the responsible development team. errorcode: 744-234-200`,
|
|
265
|
+
});
|
|
214
266
|
}
|
|
215
267
|
}
|
|
216
268
|
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import { DynamoBEDBService } from './dynamobe-db.service';
|
|
3
3
|
import { DynamoBESingletonService } from './dynamobe-singleton.service';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
5
8
|
export class DynamoBEDBServiceCollection extends DynamoBESingletonService {
|
|
6
9
|
|
|
7
10
|
[service: string]: DynamoBEDBService<any>;
|
|
@@ -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
|
|