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