@futdevpro/nts-dynamo 1.5.51 → 1.5.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_models/dynamo-nts-endpoint-params.js +3 -2
- package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.d.ts +87 -7
- package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.js +87 -7
- package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
- package/lib/_services/dynamo-nts-app.d.ts +131 -22
- package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app.js +104 -1
- package/lib/_services/dynamo-nts-app.js.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.d.ts +78 -5
- package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
- package/lib/_services/dynamo-nts-data.service.d.ts +28 -1
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +109 -75
- package/lib/_services/dynamo-nts-data.service.js.map +1 -1
- package/lib/_services/dynamo-nts-db.service.d.ts +165 -115
- package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-db.service.js +301 -277
- package/lib/_services/dynamo-nts-db.service.js.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.d.ts +39 -0
- package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.js +39 -0
- package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -12
- package/src/_models/dynamo-nts-endpoint-params.ts +2 -2
- package/src/_services/dynamo-nts-app-extended.ts +87 -7
- package/src/_services/dynamo-nts-app.ts +131 -22
- package/src/_services/dynamo-nts-auth.service.ts +79 -5
- package/src/_services/dynamo-nts-data.service.ts +110 -73
- package/src/_services/dynamo-nts-db.service.ts +323 -279
- package/src/_services/dynamo-nts-routing-module.service.ts +39 -0
|
@@ -37,11 +37,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
37
37
|
data.__lastModifiedBy = creator;
|
|
38
38
|
|
|
39
39
|
const dataModel = new this.dataModel(data);
|
|
40
|
-
let newData: T
|
|
41
|
-
|
|
42
|
-
await dataModel.save().then(res => {
|
|
40
|
+
let newData: T = await dataModel.save().then(res => {
|
|
43
41
|
if (res) {
|
|
44
|
-
|
|
42
|
+
return res.toObject() as T;
|
|
45
43
|
} else {
|
|
46
44
|
throw new Dynamo_Error({
|
|
47
45
|
status: 204,
|
|
@@ -81,11 +79,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
81
79
|
data.__lastModifiedBy = modifier;
|
|
82
80
|
|
|
83
81
|
const dataModel = new this.dataModel(data);
|
|
84
|
-
let newData: T
|
|
85
|
-
|
|
86
|
-
await this.dataModel.findByIdAndUpdate(data._id, dataModel).then(res => {
|
|
82
|
+
let newData: T = await this.dataModel.findByIdAndUpdate(data._id, dataModel).then(res => {
|
|
87
83
|
if (res) {
|
|
88
|
-
|
|
84
|
+
return res.toObject() as T;
|
|
89
85
|
} else {
|
|
90
86
|
throw new Dynamo_Error({
|
|
91
87
|
status: 204,
|
|
@@ -106,6 +102,10 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
106
102
|
});
|
|
107
103
|
});
|
|
108
104
|
|
|
105
|
+
if (typeof newData._id === 'object') {
|
|
106
|
+
newData._id = `${newData._id}`;
|
|
107
|
+
}
|
|
108
|
+
data._id = newData._id;
|
|
109
109
|
data.__v = newData.__v;
|
|
110
110
|
|
|
111
111
|
return data;
|
|
@@ -117,13 +117,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
117
117
|
* @returns data
|
|
118
118
|
*/
|
|
119
119
|
async getDataById(id: string): Promise<T> {
|
|
120
|
-
let data: T
|
|
121
|
-
|
|
122
|
-
await this.dataModel.findById(id).then(res => {
|
|
120
|
+
let data: T = await this.dataModel.findById(id).then(res => {
|
|
123
121
|
if (res) {
|
|
124
|
-
|
|
122
|
+
return res.toObject() as T;
|
|
125
123
|
} else {
|
|
126
|
-
|
|
124
|
+
return null;
|
|
127
125
|
}
|
|
128
126
|
}).catch(error => {
|
|
129
127
|
throw new Dynamo_Error({
|
|
@@ -149,29 +147,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
149
147
|
* @returns data
|
|
150
148
|
*/
|
|
151
149
|
async getDataByDependencyId(dependencyId: string): Promise<T> {
|
|
152
|
-
if (this.depDataName) {
|
|
153
|
-
let data: T;
|
|
154
|
-
await this.dataModel.findOne({ [this.depDataName]: dependencyId }).then(res => {
|
|
155
|
-
if (res) {
|
|
156
|
-
data = res.toObject() as T;
|
|
157
|
-
} else {
|
|
158
|
-
data = null;
|
|
159
|
-
}
|
|
160
|
-
}).catch(error => {
|
|
161
|
-
throw new Dynamo_Error({
|
|
162
|
-
status: 417,
|
|
163
|
-
errorCode: 'NTS-DBS-GD1',
|
|
164
|
-
addECToUserMsg: true,
|
|
165
|
-
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
166
|
-
userMessage: this.defaultErrorUserMsg,
|
|
167
|
-
error
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
if (data && typeof data._id === 'object') {
|
|
171
|
-
data._id = `${data._id}`;
|
|
172
|
-
}
|
|
173
|
-
return data;
|
|
174
|
-
} else {
|
|
150
|
+
if (!this.depDataName) {
|
|
175
151
|
throw new Dynamo_Error({
|
|
176
152
|
status: 501,
|
|
177
153
|
errorCode: 'NTS-DBS-GD0',
|
|
@@ -180,6 +156,29 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
180
156
|
userMessage: this.defaultErrorUserMsg
|
|
181
157
|
});
|
|
182
158
|
}
|
|
159
|
+
|
|
160
|
+
let data: T = await this.dataModel.findOne({ [this.depDataName]: dependencyId }).then(res => {
|
|
161
|
+
if (res) {
|
|
162
|
+
return res.toObject() as T;
|
|
163
|
+
} else {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
}).catch(error => {
|
|
167
|
+
throw new Dynamo_Error({
|
|
168
|
+
status: 417,
|
|
169
|
+
errorCode: 'NTS-DBS-GD1',
|
|
170
|
+
addECToUserMsg: true,
|
|
171
|
+
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
172
|
+
userMessage: this.defaultErrorUserMsg,
|
|
173
|
+
error
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if (data && typeof data._id === 'object') {
|
|
178
|
+
data._id = `${data._id}`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return data;
|
|
183
182
|
}
|
|
184
183
|
|
|
185
184
|
/**
|
|
@@ -188,29 +187,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
188
187
|
* @returns dataList
|
|
189
188
|
*/
|
|
190
189
|
async getDataListByDependencyId(dependencyId: string): Promise<T[]> {
|
|
191
|
-
if (this.depDataName) {
|
|
192
|
-
let dataList = [];
|
|
193
|
-
await this.dataModel.find({ [this.depDataName]: dependencyId }).then(res => {
|
|
194
|
-
if (res) {
|
|
195
|
-
dataList = res;
|
|
196
|
-
}
|
|
197
|
-
}).catch(error => {
|
|
198
|
-
throw new Dynamo_Error({
|
|
199
|
-
status: 417,
|
|
200
|
-
errorCode: 'NTS-DBS-GLD1',
|
|
201
|
-
addECToUserMsg: true,
|
|
202
|
-
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
203
|
-
userMessage: this.defaultErrorUserMsg,
|
|
204
|
-
error
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
208
|
-
dataList.forEach((data: T) => {
|
|
209
|
-
data._id = `˙${data._id}`;
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
return dataList;
|
|
213
|
-
} else {
|
|
190
|
+
if (!this.depDataName) {
|
|
214
191
|
throw new Dynamo_Error({
|
|
215
192
|
status: 501,
|
|
216
193
|
errorCode: 'NTS-DBS-GLD0',
|
|
@@ -219,6 +196,29 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
219
196
|
userMessage: this.defaultErrorUserMsg
|
|
220
197
|
});
|
|
221
198
|
}
|
|
199
|
+
|
|
200
|
+
let dataList: T[] = await this.dataModel.find({ [this.depDataName]: dependencyId })
|
|
201
|
+
.then(res => res ?? [])
|
|
202
|
+
.catch(error => {
|
|
203
|
+
throw new Dynamo_Error({
|
|
204
|
+
status: 417,
|
|
205
|
+
errorCode: 'NTS-DBS-GLD1',
|
|
206
|
+
addECToUserMsg: true,
|
|
207
|
+
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
208
|
+
userMessage: this.defaultErrorUserMsg,
|
|
209
|
+
error
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
if (0 < dataList.length) {
|
|
214
|
+
dataList.forEach((data: T) => {
|
|
215
|
+
if (data && typeof data._id === 'object') {
|
|
216
|
+
data._id = `${data._id}`;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return dataList;
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
/**
|
|
@@ -227,24 +227,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
227
227
|
* @returns dataList
|
|
228
228
|
*/
|
|
229
229
|
async getDataListByDependencyIds(ids: string[]): Promise<T[]> {
|
|
230
|
-
if (this.depDataName) {
|
|
231
|
-
let dataList = [];
|
|
232
|
-
await this.dataModel.find({ [this.depDataName]: { $in: ids }}).then(res => {
|
|
233
|
-
if (res) {
|
|
234
|
-
dataList = res;
|
|
235
|
-
}
|
|
236
|
-
}).catch(error => {
|
|
237
|
-
throw new Dynamo_Error({
|
|
238
|
-
status: 417,
|
|
239
|
-
errorCode: 'NTS-DBS-GLDS1',
|
|
240
|
-
addECToUserMsg: true,
|
|
241
|
-
message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (NTS DB)`,
|
|
242
|
-
userMessage: this.defaultErrorUserMsg,
|
|
243
|
-
error
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
return dataList;
|
|
247
|
-
} else {
|
|
230
|
+
if (!this.depDataName) {
|
|
248
231
|
throw new Dynamo_Error({
|
|
249
232
|
status: 501,
|
|
250
233
|
errorCode: 'NTS-DBS-GLDS0',
|
|
@@ -253,6 +236,29 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
253
236
|
userMessage: this.defaultErrorUserMsg
|
|
254
237
|
});
|
|
255
238
|
}
|
|
239
|
+
|
|
240
|
+
let dataList: T[] = await this.dataModel.find({ [this.depDataName]: { $in: ids }})
|
|
241
|
+
.then(res => res ?? [])
|
|
242
|
+
.catch(error => {
|
|
243
|
+
throw new Dynamo_Error({
|
|
244
|
+
status: 417,
|
|
245
|
+
errorCode: 'NTS-DBS-GLDS1',
|
|
246
|
+
addECToUserMsg: true,
|
|
247
|
+
message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (NTS DB)`,
|
|
248
|
+
userMessage: this.defaultErrorUserMsg,
|
|
249
|
+
error
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
if (0 < dataList.length) {
|
|
254
|
+
dataList.forEach((data: T) => {
|
|
255
|
+
if (data && typeof data._id === 'object') {
|
|
256
|
+
data._id = `${data._id}`;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return dataList;
|
|
256
262
|
}
|
|
257
263
|
|
|
258
264
|
/**
|
|
@@ -265,10 +271,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
265
271
|
async searchData(searchBy: object, narrowByDependencyIds?: string[]): Promise<T[]> {
|
|
266
272
|
const filter = {};
|
|
267
273
|
|
|
268
|
-
if (narrowByDependencyIds.length
|
|
269
|
-
if (this.depDataName) {
|
|
270
|
-
filter[this.depDataName] = { $in: narrowByDependencyIds };
|
|
271
|
-
} else {
|
|
274
|
+
if (0 < narrowByDependencyIds.length) {
|
|
275
|
+
if (!this.depDataName) {
|
|
272
276
|
throw new Dynamo_Error({
|
|
273
277
|
status: 501,
|
|
274
278
|
errorCode: 'NTS-DBS-SD0',
|
|
@@ -277,22 +281,33 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
277
281
|
userMessage: this.defaultErrorUserMsg
|
|
278
282
|
});
|
|
279
283
|
}
|
|
284
|
+
|
|
285
|
+
filter[this.depDataName] = { $in: narrowByDependencyIds };
|
|
280
286
|
}
|
|
281
287
|
|
|
282
288
|
await this.dataParams.modelParams.forEach((modelParam: DynamoNTS_DataPropertyParams) => {
|
|
283
|
-
if (
|
|
289
|
+
if (
|
|
290
|
+
(searchBy[modelParam.key] !== null && searchBy[modelParam.key] !== undefined) ||
|
|
291
|
+
searchBy[modelParam.key + 'Range']
|
|
292
|
+
) {
|
|
284
293
|
if (modelParam.key.includes('Range') || modelParam.type.includes('[]')) {
|
|
285
294
|
// inverz search filter (for Range and Array functions)
|
|
286
295
|
if (modelParam.key.includes('Range')) {
|
|
287
296
|
const searchParamKeyWithoutRange = modelParam.key.split('Range')[0];
|
|
288
|
-
if (
|
|
297
|
+
if (
|
|
298
|
+
searchBy[searchParamKeyWithoutRange] !== null &&
|
|
299
|
+
searchBy[searchParamKeyWithoutRange] !== undefined
|
|
300
|
+
) {
|
|
289
301
|
filter[modelParam.key] = {
|
|
290
302
|
from: { $lte: searchBy[searchParamKeyWithoutRange] },
|
|
291
303
|
to: { $gte: searchBy[searchParamKeyWithoutRange] }
|
|
292
304
|
};
|
|
293
305
|
}
|
|
294
306
|
} else {
|
|
295
|
-
if (
|
|
307
|
+
if (
|
|
308
|
+
searchBy[modelParam.key] !== null &&
|
|
309
|
+
searchBy[modelParam.key] !== undefined
|
|
310
|
+
) {
|
|
296
311
|
filter[modelParam.key] = { $in: searchBy[modelParam.key] };
|
|
297
312
|
}
|
|
298
313
|
}
|
|
@@ -317,12 +332,9 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
317
332
|
}
|
|
318
333
|
});
|
|
319
334
|
|
|
320
|
-
let dataList =
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
dataList = res;
|
|
324
|
-
}
|
|
325
|
-
}).catch(error => {
|
|
335
|
+
let dataList: T[] = await this.dataModel.find(filter)
|
|
336
|
+
.then(res => res ?? [])
|
|
337
|
+
.catch(error => {
|
|
326
338
|
throw new Dynamo_Error({
|
|
327
339
|
status: 417,
|
|
328
340
|
errorCode: 'NTS-DBS-SD1',
|
|
@@ -333,59 +345,25 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
333
345
|
});
|
|
334
346
|
});
|
|
335
347
|
|
|
336
|
-
if (0 < dataList.length
|
|
348
|
+
if (0 < dataList.length) {
|
|
337
349
|
dataList.forEach((data: T) => {
|
|
338
|
-
data._id
|
|
350
|
+
if (data && typeof data._id === 'object') {
|
|
351
|
+
data._id = `${data._id}`;
|
|
352
|
+
}
|
|
339
353
|
});
|
|
340
354
|
}
|
|
341
355
|
|
|
342
|
-
return dataList
|
|
356
|
+
return dataList;
|
|
343
357
|
}
|
|
344
358
|
|
|
345
|
-
/**
|
|
346
|
-
* find data by any of its parameters, throws error if not found
|
|
347
|
-
* @param data
|
|
348
|
-
* (always use unique parameters for find!)
|
|
349
|
-
* etc.: by email:
|
|
350
|
-
* @example { email: email }
|
|
351
|
-
* or by id that is in list:
|
|
352
|
-
* @example { userIds: { $in: this.userId } }
|
|
353
|
-
* or by number or Date that is greater than OR less than:
|
|
354
|
-
* @example { points: { $gte: 2, $lte: 14 } }
|
|
355
|
-
* @returns data
|
|
356
|
-
*/
|
|
357
|
-
/* async findData(data: T): Promise<T> {
|
|
358
|
-
await this.dataModel.findOne(data).then(res => {
|
|
359
|
-
if (res) {
|
|
360
|
-
data = res.toObject() as T;
|
|
361
|
-
} else {
|
|
362
|
-
data = null;
|
|
363
|
-
}
|
|
364
|
-
}).catch(error => {
|
|
365
|
-
throw new Dynamo_Error({
|
|
366
|
-
status: 417,
|
|
367
|
-
message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
368
|
-
error
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
if (data && typeof data._id === 'object') {
|
|
372
|
-
data._id = `${data._id}`;
|
|
373
|
-
}
|
|
374
|
-
return data;
|
|
375
|
-
} */
|
|
376
|
-
|
|
377
359
|
/**
|
|
378
360
|
* returns all data from database, throws error if not found
|
|
379
361
|
* @returns dataList
|
|
380
362
|
*/
|
|
381
363
|
async getAll(): Promise<T[]> {
|
|
382
|
-
let dataList =
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (res) {
|
|
386
|
-
dataList = res;
|
|
387
|
-
}
|
|
388
|
-
}).catch(error => {
|
|
364
|
+
let dataList: T[] = await this.dataModel.find({})
|
|
365
|
+
.then(res => res ?? [])
|
|
366
|
+
.catch(error => {
|
|
389
367
|
throw new Dynamo_Error({
|
|
390
368
|
status: 417,
|
|
391
369
|
errorCode: 'NTS-DBS-GA0',
|
|
@@ -427,18 +405,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
427
405
|
* @param dependencyId id
|
|
428
406
|
*/
|
|
429
407
|
async deleteDataByDependencyId(dependencyId: string): Promise<void> {
|
|
430
|
-
if (this.depDataName) {
|
|
431
|
-
await this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
|
|
432
|
-
throw new Dynamo_Error({
|
|
433
|
-
status: 417,
|
|
434
|
-
errorCode: 'NTS-DBS-DDD1',
|
|
435
|
-
addECToUserMsg: true,
|
|
436
|
-
message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
437
|
-
userMessage: this.defaultErrorUserMsg,
|
|
438
|
-
error
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
} else {
|
|
408
|
+
if (!this.depDataName) {
|
|
442
409
|
throw new Dynamo_Error({
|
|
443
410
|
status: 501,
|
|
444
411
|
errorCode: 'NTS-DBS-DDD0',
|
|
@@ -447,39 +414,55 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
447
414
|
userMessage: this.defaultErrorUserMsg
|
|
448
415
|
});
|
|
449
416
|
}
|
|
417
|
+
|
|
418
|
+
await this.dataModel.deleteMany({ [this.depDataName]: dependencyId })
|
|
419
|
+
.catch(error => {
|
|
420
|
+
throw new Dynamo_Error({
|
|
421
|
+
status: 417,
|
|
422
|
+
errorCode: 'NTS-DBS-DDD1',
|
|
423
|
+
addECToUserMsg: true,
|
|
424
|
+
message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
425
|
+
userMessage: this.defaultErrorUserMsg,
|
|
426
|
+
error
|
|
427
|
+
});
|
|
428
|
+
});
|
|
450
429
|
}
|
|
451
430
|
|
|
452
431
|
// ----------------------------------------------------------------------------------
|
|
453
432
|
// ----------------------------------------------------------------------------------
|
|
454
433
|
// ----------------------------------------------------------------------------------
|
|
455
|
-
// DIRECT MONGOOSE
|
|
434
|
+
// DIRECT Basic MONGOOSE FUNCTIONS (with error handlings)
|
|
456
435
|
|
|
457
436
|
/**
|
|
458
|
-
*
|
|
459
|
-
* @param filter
|
|
460
|
-
* (always use unique parameters for find!)
|
|
461
|
-
* etc.: by email:
|
|
462
|
-
* @example { email: email }
|
|
463
|
-
* or by id that is in list:
|
|
464
|
-
* @example { userIds: { $in: this.userId } }
|
|
465
|
-
* or by number or Date that is GREATER THAN OR LESS THAN:
|
|
466
|
-
* @example { points: { $gt: 2, $lt: 14 } }
|
|
467
|
-
* further tools (syntax matches with $gt):
|
|
468
|
-
* $eq: Matches values that are EQUAL to a specified value.
|
|
469
|
-
* $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
|
|
470
|
-
* $lte: Matches values that are LESS THAN or EQUAL to a specified value.
|
|
471
|
-
* $ne: Matches all values that are NOT EQUAL to a specified value.
|
|
472
|
-
* $nin: Matches NONE of the values specified IN an array.
|
|
437
|
+
* Find the data first by any of its parameters, throws error if not found
|
|
438
|
+
* @param filter if you can, use unique parameters for find!
|
|
473
439
|
*
|
|
474
|
-
* @
|
|
440
|
+
* @example
|
|
441
|
+
* // by email:
|
|
442
|
+
* { email: email }
|
|
443
|
+
* //
|
|
444
|
+
* @example
|
|
445
|
+
* // or by id that is in list:
|
|
446
|
+
* { userIds: { $in: this.userId } }
|
|
447
|
+
* //
|
|
448
|
+
* @example
|
|
449
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
450
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
451
|
+
* // further tools (syntax matches with $gt):
|
|
452
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
453
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
454
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
455
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
456
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
457
|
+
* //
|
|
458
|
+
* @returns {T} data: T
|
|
475
459
|
*/
|
|
476
460
|
async findOne(filter: any): Promise<T> {
|
|
477
|
-
let data: T
|
|
478
|
-
await this.dataModel.findOne(filter).then(res => {
|
|
461
|
+
let data: T = await this.dataModel.findOne(filter).then(res => {
|
|
479
462
|
if (res) {
|
|
480
|
-
|
|
463
|
+
return res.toObject() as T;
|
|
481
464
|
} else {
|
|
482
|
-
|
|
465
|
+
return null;
|
|
483
466
|
}
|
|
484
467
|
}).catch(error => {
|
|
485
468
|
throw new Dynamo_Error({
|
|
@@ -491,38 +474,43 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
491
474
|
error
|
|
492
475
|
});
|
|
493
476
|
});
|
|
477
|
+
|
|
494
478
|
if (data && typeof data._id === 'object') {
|
|
495
479
|
data._id = `${data._id}`;
|
|
496
480
|
}
|
|
481
|
+
|
|
497
482
|
return data;
|
|
498
483
|
}
|
|
499
484
|
|
|
500
485
|
/**
|
|
501
|
-
*
|
|
502
|
-
*
|
|
503
|
-
*
|
|
504
|
-
* @example { email: email }
|
|
505
|
-
* or by id that is in list:
|
|
506
|
-
* @example { userIds: { $in: this.userId } }
|
|
507
|
-
* or by number or Date that is GREATER THAN OR LESS THAN:
|
|
508
|
-
* @example { points: { $gt: 2, $lt: 14 } }
|
|
509
|
-
* further tools (syntax matches with $gt):
|
|
510
|
-
* $eq: Matches values that are EQUAL to a specified value.
|
|
511
|
-
* $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
|
|
512
|
-
* $lte: Matches values that are LESS THAN or EQUAL to a specified value.
|
|
513
|
-
* $ne: Matches all values that are NOT EQUAL to a specified value.
|
|
514
|
-
* $nin: Matches NONE of the values specified IN an array.
|
|
486
|
+
* #MONGOOSE FUNCTION
|
|
487
|
+
* Find the data first by any of its parameters, throws error if not found
|
|
488
|
+
* @param filter if you can, use unique parameters for find!
|
|
515
489
|
*
|
|
516
|
-
* @
|
|
490
|
+
* @example
|
|
491
|
+
* // by email:
|
|
492
|
+
* { email: email }
|
|
493
|
+
* //
|
|
494
|
+
* @example
|
|
495
|
+
* // or by id that is in list:
|
|
496
|
+
* { userIds: { $in: this.userId } }
|
|
497
|
+
* //
|
|
498
|
+
* @example
|
|
499
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
500
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
501
|
+
* // further tools (syntax matches with $gt):
|
|
502
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
503
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
504
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
505
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
506
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
507
|
+
* //
|
|
508
|
+
* @returns {T[]} dataList: T[]
|
|
517
509
|
*/
|
|
518
510
|
async find(filter: any): Promise<T[]> {
|
|
519
|
-
let dataList =
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
if (res) {
|
|
523
|
-
dataList = res;
|
|
524
|
-
}
|
|
525
|
-
}).catch(error => {
|
|
511
|
+
let dataList: T[] = await this.dataModel.find(filter)
|
|
512
|
+
.then(res => res ?? [])
|
|
513
|
+
.catch(error => {
|
|
526
514
|
throw new Dynamo_Error({
|
|
527
515
|
status: 417,
|
|
528
516
|
errorCode: 'NTS-DBS-F0',
|
|
@@ -533,9 +521,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
533
521
|
});
|
|
534
522
|
});
|
|
535
523
|
|
|
536
|
-
if (0 < dataList.length
|
|
524
|
+
if (0 < dataList.length) {
|
|
537
525
|
dataList.forEach((data: T) => {
|
|
538
|
-
data._id
|
|
526
|
+
if (data && typeof data._id === 'object') {
|
|
527
|
+
data._id = `${data._id}`;
|
|
528
|
+
}
|
|
539
529
|
});
|
|
540
530
|
}
|
|
541
531
|
|
|
@@ -543,37 +533,44 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
543
533
|
}
|
|
544
534
|
|
|
545
535
|
/**
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
* @example { email: email }
|
|
550
|
-
* or by id that is in list:
|
|
551
|
-
* @example { userIds: { $in: this.userId } }
|
|
552
|
-
* or by number or Date that is GREATER THAN OR LESS THAN:
|
|
553
|
-
* @example { points: { $gt: 2, $lt: 14 } }
|
|
554
|
-
* further tools (syntax matches with $gt):
|
|
555
|
-
* $eq: Matches values that are EQUAL to a specified value.
|
|
556
|
-
* $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
|
|
557
|
-
* $lte: Matches values that are LESS THAN or EQUAL to a specified value.
|
|
558
|
-
* $ne: Matches all values that are NOT EQUAL to a specified value.
|
|
559
|
-
* $nin: Matches NONE of the values specified IN an array.
|
|
536
|
+
* #MONGOOSE FUNCTION
|
|
537
|
+
* Find the data first by any of its parameters, throws error if not found
|
|
538
|
+
* @param filter if you can, use unique parameters for find!
|
|
560
539
|
*
|
|
540
|
+
* @example
|
|
541
|
+
* // by email:
|
|
542
|
+
* { email: email }
|
|
543
|
+
* //
|
|
544
|
+
* @example
|
|
545
|
+
* // or by id that is in list:
|
|
546
|
+
* { userIds: { $in: this.userId } }
|
|
547
|
+
* //
|
|
548
|
+
* @example
|
|
549
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
550
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
551
|
+
* // further tools (syntax matches with $gt):
|
|
552
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
553
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
554
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
555
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
556
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
557
|
+
* //
|
|
561
558
|
* @param page page
|
|
562
559
|
* @param pageSize pageSize
|
|
563
|
-
* @param sort
|
|
564
|
-
* @
|
|
560
|
+
* @param sort
|
|
561
|
+
* @example
|
|
562
|
+
* // by dateTime (this uses the basic sort function):
|
|
563
|
+
* { dateTime: -1 }
|
|
564
|
+
* //
|
|
565
|
+
* @returns {T[]} dataList: T[]
|
|
565
566
|
*/
|
|
566
567
|
async findWithPaging(filter: any, page: number, pageSize: number, sort?: any): Promise<T[]> {
|
|
567
|
-
let dataList =
|
|
568
|
-
await this.dataModel.find(filter)
|
|
568
|
+
let dataList: T[] = await this.dataModel.find(filter)
|
|
569
569
|
.sort(sort)
|
|
570
570
|
.skip(page * pageSize)
|
|
571
571
|
.limit(pageSize)
|
|
572
|
-
.then(res =>
|
|
573
|
-
|
|
574
|
-
dataList = res;
|
|
575
|
-
}
|
|
576
|
-
}).catch(error => {
|
|
572
|
+
.then(res => res ?? [])
|
|
573
|
+
.catch(error => {
|
|
577
574
|
throw new Dynamo_Error({
|
|
578
575
|
status: 417,
|
|
579
576
|
errorCode: 'NTS-DBS-WP0',
|
|
@@ -584,9 +581,11 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
584
581
|
});
|
|
585
582
|
});
|
|
586
583
|
|
|
587
|
-
if (0 < dataList.length
|
|
584
|
+
if (0 < dataList.length) {
|
|
588
585
|
dataList.forEach((data: T) => {
|
|
589
|
-
data._id
|
|
586
|
+
if (data && typeof data._id === 'object') {
|
|
587
|
+
data._id = `${data._id}`;
|
|
588
|
+
}
|
|
590
589
|
});
|
|
591
590
|
}
|
|
592
591
|
|
|
@@ -594,19 +593,19 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
594
593
|
}
|
|
595
594
|
|
|
596
595
|
/**
|
|
596
|
+
* #MONGOOSE FUNCTION
|
|
597
597
|
* Find data by _id and update
|
|
598
598
|
* @param id id
|
|
599
599
|
* @param update update
|
|
600
600
|
* @returns data
|
|
601
601
|
*/
|
|
602
602
|
async findByIdAndUpdate(id: string, update: any, modifier: string): Promise<T> {
|
|
603
|
-
let data: T;
|
|
604
603
|
update.__lastModified = new Date();
|
|
605
604
|
update.__lastModifiedBy = modifier;
|
|
606
605
|
|
|
607
|
-
await this.dataModel.findByIdAndUpdate(id, update).then(res => {
|
|
606
|
+
let newData: T = await this.dataModel.findByIdAndUpdate(id, update).then(res => {
|
|
608
607
|
if (res) {
|
|
609
|
-
|
|
608
|
+
return res.toObject() as T;
|
|
610
609
|
} else {
|
|
611
610
|
throw new Dynamo_Error({
|
|
612
611
|
status: 204,
|
|
@@ -626,47 +625,72 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
626
625
|
error
|
|
627
626
|
});
|
|
628
627
|
});
|
|
629
|
-
|
|
630
|
-
|
|
628
|
+
|
|
629
|
+
if (typeof newData._id === 'object') {
|
|
630
|
+
newData._id = `${newData._id}`;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
return newData;
|
|
631
634
|
}
|
|
632
635
|
|
|
633
636
|
/**
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
638
|
-
* @example
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
* @example
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
637
|
+
* #MONGOOSE FUNCTION
|
|
638
|
+
* Find the data first by any of its parameters, throws error if not found
|
|
639
|
+
* @param filter This uses the basic Mongoose updateOne.
|
|
640
|
+
* If you can, use unique parameters for find!
|
|
641
|
+
* @example
|
|
642
|
+
* // by email:
|
|
643
|
+
* { email: email }
|
|
644
|
+
* //
|
|
645
|
+
* @example
|
|
646
|
+
* // or by id that is in list:
|
|
647
|
+
* { userIds: { $in: this.userId } }
|
|
648
|
+
* //
|
|
649
|
+
* @example
|
|
650
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
651
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
652
|
+
* // further tools (syntax matches with $gt):
|
|
653
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
654
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
655
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
656
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
657
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
658
|
+
* //
|
|
649
659
|
*
|
|
650
|
-
* @param update
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
*
|
|
659
|
-
* $
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
*
|
|
663
|
-
*
|
|
660
|
+
* @param update this uses the basic Mongoose updateOne
|
|
661
|
+
* @example
|
|
662
|
+
* // increase a specific value (here by 15):
|
|
663
|
+
* { $inc: { popularity: 15 } }
|
|
664
|
+
* //
|
|
665
|
+
* @example
|
|
666
|
+
* // or add element to a list:
|
|
667
|
+
* { $push: { reactions: this.newReaction }
|
|
668
|
+
* // or add multiple elements to a list
|
|
669
|
+
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
670
|
+
* //
|
|
671
|
+
* @example
|
|
672
|
+
* // or all at once
|
|
673
|
+
* {
|
|
674
|
+
* $inc: { popularity: this.newVote.amount },
|
|
675
|
+
* emailVerified: true,
|
|
676
|
+
* $push: { reactions: this.newReaction }
|
|
677
|
+
* }
|
|
678
|
+
* // further tools (syntax matches with $inc):
|
|
679
|
+
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
680
|
+
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
681
|
+
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
682
|
+
* $mul: // Multiplies the value of the field by the specified amount.
|
|
683
|
+
* $rename: // Renames a field.
|
|
684
|
+
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
685
|
+
* //
|
|
664
686
|
*/
|
|
665
687
|
async updateOne(updateBy: any, update: any, modifier: string): Promise<void> {
|
|
666
688
|
update.__lastModified = new Date();
|
|
667
689
|
update.__lastModifiedBy = modifier;
|
|
668
|
-
|
|
669
|
-
|
|
690
|
+
|
|
691
|
+
await this.dataModel.updateOne(updateBy, update)
|
|
692
|
+
.catch(error => {
|
|
693
|
+
throw new Dynamo_Error({
|
|
670
694
|
status: 417,
|
|
671
695
|
errorCode: 'NTS-DBS-UO0',
|
|
672
696
|
addECToUserMsg: true,
|
|
@@ -678,41 +702,61 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
678
702
|
}
|
|
679
703
|
|
|
680
704
|
/**
|
|
705
|
+
* #MONGOOSE FUNCTION
|
|
681
706
|
* update one parameter by a specific
|
|
682
|
-
* @param
|
|
683
|
-
*
|
|
684
|
-
*
|
|
685
|
-
*
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
*
|
|
692
|
-
*
|
|
693
|
-
*
|
|
694
|
-
*
|
|
707
|
+
* @param filter This uses the basic Mongoose updateMany.
|
|
708
|
+
* @example
|
|
709
|
+
* // by email:
|
|
710
|
+
* { email: email }
|
|
711
|
+
* //
|
|
712
|
+
* @example
|
|
713
|
+
* // or by id that is in list:
|
|
714
|
+
* { userIds: { $in: this.userId } }
|
|
715
|
+
* //
|
|
716
|
+
* @example
|
|
717
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
718
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
719
|
+
* // further tools (syntax matches with $gt):
|
|
720
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
721
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
722
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
723
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
724
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
725
|
+
* //
|
|
695
726
|
*
|
|
696
|
-
* @param update
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
*
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
* $
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
*
|
|
727
|
+
* @param update this uses the basic Mongoose updateOne
|
|
728
|
+
* @example
|
|
729
|
+
* // increase a specific value (here by 15):
|
|
730
|
+
* { $inc: { popularity: 15 } }
|
|
731
|
+
* //
|
|
732
|
+
* @example
|
|
733
|
+
* // or add element to a list:
|
|
734
|
+
* { $push: { reactions: this.newReaction }
|
|
735
|
+
* // or add multiple elements to a list
|
|
736
|
+
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
737
|
+
* //
|
|
738
|
+
* @example
|
|
739
|
+
* // or all at once
|
|
740
|
+
* {
|
|
741
|
+
* $inc: { popularity: this.newVote.amount },
|
|
742
|
+
* emailVerified: true,
|
|
743
|
+
* $push: { reactions: this.newReaction }
|
|
744
|
+
* }
|
|
745
|
+
* // further tools (syntax matches with $inc):
|
|
746
|
+
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
747
|
+
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
748
|
+
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
749
|
+
* $mul: // Multiplies the value of the field by the specified amount.
|
|
750
|
+
* $rename: // Renames a field.
|
|
751
|
+
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
752
|
+
* //
|
|
710
753
|
*/
|
|
711
754
|
async updateMany(updateBy: any, update: any, modifier: string): Promise<void> {
|
|
712
755
|
update.__lastModified = new Date();
|
|
713
756
|
update.__lastModifiedBy = modifier;
|
|
714
757
|
|
|
715
|
-
await this.dataModel.updateMany(updateBy, update)
|
|
758
|
+
await this.dataModel.updateMany(updateBy, update)
|
|
759
|
+
.catch(error => {
|
|
716
760
|
throw new Dynamo_Error({
|
|
717
761
|
status: 417,
|
|
718
762
|
errorCode: 'NTS-DBS-UM0',
|
|
@@ -760,7 +804,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
760
804
|
|
|
761
805
|
params.forEach((property: DynamoNTS_DataPropertyParams) => {
|
|
762
806
|
const beType = this.getBEType(property.type);
|
|
763
|
-
if (beType !== Object || !property
|
|
807
|
+
if (beType !== Object || !property?.subObjectParams || property?.subObjectParams?.length == 0) {
|
|
764
808
|
schemaSettingsObj[property.key] = {
|
|
765
809
|
type: beType
|
|
766
810
|
};
|