@futdevpro/nts-dynamo 1.5.77 → 1.5.83
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/LICENSE +2 -2
- package/lib/_constants/dynamo-nts-global-settings.d.ts +2 -2
- package/lib/_constants/dynamo-nts-global-settings.js +17 -17
- package/lib/_constants/index.d.ts +1 -1
- package/lib/_constants/index.js +4 -4
- package/lib/_enums/data-model-type.enum.d.ts +12 -12
- package/lib/_enums/data-model-type.enum.js +16 -16
- package/lib/_enums/data-model-type.enum.js.map +1 -1
- package/lib/_enums/dynamo-nts-data-service-function.enum.d.ts +12 -12
- package/lib/_enums/dynamo-nts-data-service-function.enum.js +18 -18
- package/lib/_enums/dynamo-nts-data-service-function.enum.js.map +1 -1
- package/lib/_enums/dynamo-nts-route-security.enum.d.ts +11 -11
- package/lib/_enums/dynamo-nts-route-security.enum.js +15 -15
- package/lib/_enums/dynamo-nts-route-security.enum.js.map +1 -1
- package/lib/_enums/dynamo-nts-socket-security.enum.d.ts +10 -10
- package/lib/_enums/dynamo-nts-socket-security.enum.js +14 -14
- package/lib/_enums/dynamo-nts-socket-security.enum.js.map +1 -1
- package/lib/_enums/http/http-call-type.enum.d.ts +11 -11
- package/lib/_enums/http/http-call-type.enum.js +15 -15
- package/lib/_enums/http/http-call-type.enum.js.map +1 -1
- package/lib/_enums/http/http-response-type.enum.d.ts +6 -6
- package/lib/_enums/http/http-response-type.enum.js +10 -10
- package/lib/_enums/http/http-response-type.enum.js.map +1 -1
- package/lib/_enums/http/socket-event.enum.d.ts +9 -8
- package/lib/_enums/http/socket-event.enum.d.ts.map +1 -1
- package/lib/_enums/http/socket-event.enum.js +13 -12
- package/lib/_enums/http/socket-event.enum.js.map +1 -1
- package/lib/_enums/index.d.ts +8 -8
- package/lib/_enums/index.js +13 -13
- package/lib/_enums/predefined-data-types.enum.d.ts +10 -10
- package/lib/_enums/predefined-data-types.enum.js +14 -14
- package/lib/_enums/predefined-data-types.enum.js.map +1 -1
- package/lib/_interfaces/certification-settings.interface.d.ts +7 -0
- package/lib/_interfaces/certification-settings.interface.d.ts.map +1 -0
- package/lib/_interfaces/certification-settings.interface.js +3 -0
- package/lib/_interfaces/certification-settings.interface.js.map +1 -0
- package/lib/_interfaces/global-service-settings.interface.d.ts +18 -0
- package/lib/_interfaces/global-service-settings.interface.d.ts.map +1 -0
- package/lib/_interfaces/global-service-settings.interface.js +3 -0
- package/lib/_interfaces/global-service-settings.interface.js.map +1 -0
- package/lib/_interfaces/index.d.ts +1 -0
- package/lib/_interfaces/index.d.ts.map +1 -0
- package/lib/_interfaces/index.js +4 -0
- package/lib/_interfaces/index.js.map +1 -0
- package/lib/_interfaces/port-settings.interface.d.ts +5 -0
- package/lib/_interfaces/port-settings.interface.d.ts.map +1 -0
- package/lib/_interfaces/port-settings.interface.js +3 -0
- package/lib/_interfaces/port-settings.interface.js.map +1 -0
- package/lib/_models/dynamo-nts-api-call-params.d.ts +95 -95
- package/lib/_models/dynamo-nts-api-call-params.js +47 -47
- package/lib/_models/dynamo-nts-app-params.d.ts +49 -49
- package/lib/_models/dynamo-nts-app-params.js +17 -17
- package/lib/_models/dynamo-nts-endpoint-params.d.ts +80 -80
- package/lib/_models/dynamo-nts-endpoint-params.js +139 -139
- package/lib/_models/dynamo-nts-global-settings.d.ts +53 -53
- package/lib/_models/dynamo-nts-global-settings.js +2 -2
- package/lib/_models/dynamo-nts-routing-module-settings.d.ts +19 -19
- package/lib/_models/dynamo-nts-routing-module-settings.js +2 -2
- package/lib/_models/dynamo-nts-socket-event-params.d.ts +32 -30
- package/lib/_models/dynamo-nts-socket-event-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-event-params.js +80 -79
- package/lib/_models/dynamo-nts-socket-event-params.js.map +1 -1
- package/lib/_models/dynamo-nts-socket-presence.d.ts +21 -0
- package/lib/_models/dynamo-nts-socket-presence.d.ts.map +1 -0
- package/lib/_models/dynamo-nts-socket-presence.js +45 -0
- package/lib/_models/dynamo-nts-socket-presence.js.map +1 -0
- package/lib/_models/dynamo-nts-socket-service-params.d.ts +18 -18
- package/lib/_models/dynamo-nts-socket-service-params.d.ts.map +1 -1
- package/lib/_models/dynamo-nts-socket-service-params.js +26 -26
- package/lib/_models/dynamo-nts-socket-service-params.js.map +1 -1
- package/lib/_models/index.d.ts +7 -8
- package/lib/_models/index.d.ts.map +1 -1
- package/lib/_models/index.js +12 -12
- package/lib/_models/index.js.map +1 -1
- package/lib/_modules/api-service.index.d.ts +5 -5
- package/lib/_modules/api-service.index.js +11 -11
- package/lib/_modules/app-extended.index.d.ts +15 -12
- package/lib/_modules/app-extended.index.d.ts.map +1 -1
- package/lib/_modules/app-extended.index.js +23 -19
- package/lib/_modules/app-extended.index.js.map +1 -1
- package/lib/_modules/app.index.d.ts +13 -10
- package/lib/_modules/app.index.d.ts.map +1 -1
- package/lib/_modules/app.index.js +21 -17
- package/lib/_modules/app.index.js.map +1 -1
- package/lib/_modules/auth.index.d.ts +3 -3
- package/lib/_modules/auth.index.js +8 -8
- package/lib/_modules/constants.index.d.ts +1 -1
- package/lib/_modules/constants.index.js +4 -4
- package/lib/_modules/controller.index.d.ts +4 -4
- package/lib/_modules/controller.index.js +10 -10
- package/lib/_modules/custom-data/custom-data.controller.d.ts +5 -5
- package/lib/_modules/custom-data/custom-data.controller.js +55 -55
- package/lib/_modules/custom-data/custom-data.service.d.ts +5 -5
- package/lib/_modules/custom-data/custom-data.service.js +11 -11
- package/lib/_modules/custom-data/get-custom-data-routing-module.d.ts +3 -3
- package/lib/_modules/custom-data/get-custom-data-routing-module.js +17 -17
- package/lib/_modules/custom-data/index.d.ts +4 -4
- package/lib/_modules/custom-data/index.js +8 -8
- package/lib/_modules/custom-data-module.index.d.ts +1 -1
- package/lib/_modules/custom-data-module.index.js +4 -4
- package/lib/_modules/data-service.index.d.ts +5 -5
- package/lib/_modules/data-service.index.js +10 -10
- package/lib/_modules/email.index.d.ts +3 -3
- package/lib/_modules/email.index.js +8 -8
- package/lib/_modules/enums.index.d.ts +1 -1
- package/lib/_modules/enums.index.js +4 -4
- package/lib/_modules/models.index.d.ts +1 -1
- package/lib/_modules/models.index.js +4 -4
- package/lib/_modules/services.index.d.ts +1 -1
- package/lib/_modules/services.index.js +4 -4
- package/lib/_modules/test/get-test-routing-module.d.ts +3 -3
- package/lib/_modules/test/get-test-routing-module.js +17 -17
- package/lib/_modules/test/index.d.ts +3 -3
- package/lib/_modules/test/index.js +7 -7
- package/lib/_modules/test/test.controller.d.ts +5 -5
- package/lib/_modules/test/test.controller.js +104 -104
- package/lib/_modules/test-module.index.d.ts +1 -1
- package/lib/_modules/test-module.index.js +4 -4
- package/lib/_modules/usage/get-usage-routing-module.d.ts +3 -3
- package/lib/_modules/usage/get-usage-routing-module.js +17 -17
- package/lib/_modules/usage/index.d.ts +4 -4
- package/lib/_modules/usage/index.js +8 -8
- package/lib/_modules/usage/usage-controller.d.ts +6 -6
- package/lib/_modules/usage/usage-controller.js +88 -88
- package/lib/_modules/usage/usage.service.d.ts +16 -16
- package/lib/_modules/usage/usage.service.js +132 -132
- package/lib/_modules/usage-module.index.d.ts +1 -1
- package/lib/_modules/usage-module.index.js +4 -4
- package/lib/_services/dynamo-nts-api.service.d.ts +34 -34
- package/lib/_services/dynamo-nts-api.service.js +188 -188
- package/lib/_services/dynamo-nts-app-extended.d.ts +128 -128
- package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app-extended.js +212 -212
- package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
- package/lib/_services/dynamo-nts-app.d.ts +270 -278
- package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-app.js +371 -371
- package/lib/_services/dynamo-nts-app.js.map +1 -1
- package/lib/_services/dynamo-nts-app.spec.d.ts +1 -0
- package/lib/_services/dynamo-nts-app.spec.d.ts.map +1 -0
- package/lib/_services/dynamo-nts-app.spec.js +10 -0
- package/lib/_services/dynamo-nts-app.spec.js.map +1 -0
- package/lib/_services/dynamo-nts-auth.service.d.ts +127 -127
- package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-auth.service.js +53 -53
- package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
- package/lib/_services/dynamo-nts-controller.service.d.ts +105 -105
- package/lib/_services/dynamo-nts-controller.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-controller.service.js +57 -57
- package/lib/_services/dynamo-nts-controller.service.js.map +1 -1
- package/lib/_services/dynamo-nts-data.service.d.ts +230 -230
- package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-data.service.js +689 -689
- package/lib/_services/dynamo-nts-data.service.js.map +1 -1
- package/lib/_services/dynamo-nts-db-service-collection.service.d.ts +8 -8
- package/lib/_services/dynamo-nts-db-service-collection.service.js +10 -10
- package/lib/_services/dynamo-nts-db.service.d.ts +386 -312
- package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-db.service.js +856 -856
- package/lib/_services/dynamo-nts-db.service.js.map +1 -1
- package/lib/_services/dynamo-nts-email-service-collection.service.d.ts +18 -18
- package/lib/_services/dynamo-nts-email-service-collection.service.js +20 -20
- package/lib/_services/dynamo-nts-email.service.d.ts +56 -56
- package/lib/_services/dynamo-nts-email.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-email.service.js +203 -203
- package/lib/_services/dynamo-nts-email.service.js.map +1 -1
- package/lib/_services/dynamo-nts-global.service.d.ts +71 -84
- package/lib/_services/dynamo-nts-global.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-global.service.js +156 -156
- package/lib/_services/dynamo-nts-global.service.js.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.d.ts +76 -76
- package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-routing-module.service.js +191 -191
- package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
- package/lib/_services/dynamo-nts-shared.service.d.ts +31 -31
- package/lib/_services/dynamo-nts-shared.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-shared.service.js +70 -70
- package/lib/_services/dynamo-nts-shared.service.js.map +1 -1
- package/lib/_services/dynamo-nts-shared.service.spec.d.ts +2 -0
- package/lib/_services/dynamo-nts-shared.service.spec.d.ts.map +1 -0
- package/lib/_services/dynamo-nts-shared.service.spec.js +12 -0
- package/lib/_services/dynamo-nts-shared.service.spec.js.map +1 -0
- package/lib/_services/dynamo-nts-singleton.service.d.ts +8 -8
- package/lib/_services/dynamo-nts-singleton.service.js +18 -18
- package/lib/_services/dynamo-nts-singleton.service.js.map +1 -1
- package/lib/_services/dynamo-nts-socket-service-collection.service.d.ts +9 -9
- package/lib/_services/dynamo-nts-socket-service-collection.service.js +13 -13
- package/lib/_services/dynamo-nts-socket.service.d.ts +57 -45
- package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
- package/lib/_services/dynamo-nts-socket.service.js +188 -165
- package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
- package/lib/_services/index.d.ts +14 -16
- package/lib/_services/index.d.ts.map +1 -1
- package/lib/_services/index.js +20 -20
- package/lib/_services/index.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.js +14 -14
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package SAVE.json +216 -0
- package/package-NEW with test but not working.json +228 -0
- package/package.json +14 -8
- package/spec/support/jasmine.json +14 -0
- package/src/_enums/http/socket-event.enum.ts +2 -1
- package/src/_interfaces/certification-settings.interface.ts +7 -0
- package/src/_interfaces/global-service-settings.interface.ts +23 -0
- package/src/_interfaces/index.ts +5 -0
- package/src/_interfaces/port-settings.interface.ts +5 -0
- package/src/_models/dynamo-nts-socket-event-params.ts +23 -21
- package/src/_models/{dynamo-nts-socket-dictionary.ts → dynamo-nts-socket-presence.ts} +21 -5
- package/src/_models/dynamo-nts-socket-service-params.ts +1 -0
- package/src/_models/index.ts +2 -2
- package/src/_modules/app-extended.index.ts +7 -2
- package/src/_modules/app.index.ts +5 -0
- package/src/_services/dynamo-nts-app-extended.ts +6 -2
- package/src/_services/dynamo-nts-app.spec.ts +14 -0
- package/src/_services/dynamo-nts-app.ts +8 -14
- package/src/_services/dynamo-nts-auth.service.ts +1 -0
- package/src/_services/dynamo-nts-controller.service.ts +2 -1
- package/src/_services/dynamo-nts-data.service.ts +19 -19
- package/src/_services/dynamo-nts-db.service.ts +195 -115
- package/src/_services/dynamo-nts-email.service.ts +1 -0
- package/src/_services/dynamo-nts-global.service.ts +3 -18
- package/src/_services/dynamo-nts-routing-module.service.ts +1 -0
- package/src/_services/dynamo-nts-shared.service.spec.ts +10 -0
- package/src/_services/dynamo-nts-shared.service.ts +2 -1
- package/src/_services/dynamo-nts-socket.service.ts +80 -41
- package/src/_services/index.ts +2 -2
|
@@ -1,857 +1,857 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DynamoNTS_DBService = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const mongoose = tslib_1.__importStar(require("mongoose"));
|
|
6
|
-
const mongoose_1 = require("mongoose");
|
|
7
|
-
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
class DynamoNTS_DBService {
|
|
12
|
-
/**
|
|
13
|
-
* @param dataName name the model
|
|
14
|
-
* @param typeSample sample data for scheme creation (dont include Dynamo_Metadata!)
|
|
15
|
-
* @param schemaSettings additional settings for specific parameters as unique, required, minlength or maxlength
|
|
16
|
-
* schemaSettings also MUST contain specific types that differs from the listed above (Array, Date)
|
|
17
|
-
*/
|
|
18
|
-
constructor(dataParams) {
|
|
19
|
-
this.dataParams = dataParams;
|
|
20
|
-
this.dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
|
|
21
|
-
this.defaultErrorUserMsg = `We encountered an unhandled DB Error, ` +
|
|
22
|
-
`\nplease contact the responsible development team.`;
|
|
23
|
-
this.lookForDependencyDataSettings();
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* save new data
|
|
27
|
-
* @param data data
|
|
28
|
-
* @returns data
|
|
29
|
-
*/
|
|
30
|
-
createData(data, issuer) {
|
|
31
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
data.__created = new Date();
|
|
33
|
-
data.__lastModified = new Date();
|
|
34
|
-
data.__createdBy = issuer;
|
|
35
|
-
data.__lastModifiedBy = issuer;
|
|
36
|
-
const dataModel = new this.dataModel(data);
|
|
37
|
-
let newData = yield dataModel.save().then(res => {
|
|
38
|
-
if (res) {
|
|
39
|
-
return res === null || res === void 0 ? void 0 : res.toObject();
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
43
|
-
status: 204,
|
|
44
|
-
errorCode: 'NTS-DBS-CD1',
|
|
45
|
-
addECToUserMsg: true,
|
|
46
|
-
message: `save ${this.dataParams.dbName} result not found! (NTS DB)`,
|
|
47
|
-
userMessage: this.defaultErrorUserMsg
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}).catch(error => {
|
|
51
|
-
if ((error === null || error === void 0 ? void 0 : error.flag) == 'DYNAMO ERROR OBJECT') {
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
56
|
-
status: 422,
|
|
57
|
-
errorCode: 'NTS-DBS-CD0',
|
|
58
|
-
addECToUserMsg: true,
|
|
59
|
-
message: `Create new ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
60
|
-
userMessage: this.defaultErrorUserMsg,
|
|
61
|
-
error
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
if (typeof newData._id === 'object') {
|
|
66
|
-
newData._id = `${newData._id}`;
|
|
67
|
-
}
|
|
68
|
-
data._id = newData._id;
|
|
69
|
-
data.__v = newData.__v;
|
|
70
|
-
return data;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Find data by _id and update
|
|
75
|
-
* @param data data
|
|
76
|
-
* @returns data
|
|
77
|
-
*/
|
|
78
|
-
modifyData(data, issuer) {
|
|
79
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
data.__lastModified = new Date();
|
|
81
|
-
data.__lastModifiedBy = issuer;
|
|
82
|
-
const dataModel = new this.dataModel(data);
|
|
83
|
-
let newData = yield this.dataModel.findByIdAndUpdate(data._id, dataModel).then(res => {
|
|
84
|
-
if (res) {
|
|
85
|
-
return res === null || res === void 0 ? void 0 : res.toObject();
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
89
|
-
status: 204,
|
|
90
|
-
errorCode: 'NTS-DBS-FU1',
|
|
91
|
-
addECToUserMsg: true,
|
|
92
|
-
message: `modify ${this.dataParams.dbName} result not found! (NTS DB)`,
|
|
93
|
-
userMessage: this.defaultErrorUserMsg,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}).catch(error => {
|
|
97
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
98
|
-
status: 417,
|
|
99
|
-
errorCode: 'NTS-DBS-FU0',
|
|
100
|
-
addECToUserMsg: true,
|
|
101
|
-
message: `
|
|
102
|
-
userMessage: this.defaultErrorUserMsg,
|
|
103
|
-
error
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
if (typeof newData._id === 'object') {
|
|
107
|
-
newData._id = `${newData._id}`;
|
|
108
|
-
}
|
|
109
|
-
data._id = newData._id;
|
|
110
|
-
data.__v = newData.__v;
|
|
111
|
-
return data;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* returns data by _id,
|
|
116
|
-
* @param id id
|
|
117
|
-
* @returns data
|
|
118
|
-
*/
|
|
119
|
-
getDataById(id) {
|
|
120
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
121
|
-
let data = yield this.dataModel.findById(id).then(res => {
|
|
122
|
-
var _a;
|
|
123
|
-
return (_a = res === null || res === void 0 ? void 0 : res.toObject()) !== null && _a !== void 0 ? _a : null;
|
|
124
|
-
}).catch(error => {
|
|
125
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
126
|
-
status: 417,
|
|
127
|
-
errorCode: 'NTS-DBS-GI0',
|
|
128
|
-
addECToUserMsg: true,
|
|
129
|
-
message: `get ${this.dataParams.dbName} by ID was unsuccessful (NTS DB)`,
|
|
130
|
-
userMessage: this.defaultErrorUserMsg,
|
|
131
|
-
error
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
if (data && typeof data._id === 'object') {
|
|
135
|
-
data._id = `${data._id}`;
|
|
136
|
-
}
|
|
137
|
-
return data;
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* get data by dependency data id,
|
|
142
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GD2)
|
|
143
|
-
*
|
|
144
|
-
* @param dependencyId id
|
|
145
|
-
* @returns data
|
|
146
|
-
*/
|
|
147
|
-
getDataByDependencyId(dependencyId) {
|
|
148
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
149
|
-
if (!this.depDataName) {
|
|
150
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
151
|
-
status: 501,
|
|
152
|
-
errorCode: 'NTS-DBS-GD0',
|
|
153
|
-
addECToUserMsg: true,
|
|
154
|
-
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
155
|
-
userMessage: this.defaultErrorUserMsg
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
let data = yield this.dataModel.findOne({ [this.depDataName]: dependencyId }).then(res => {
|
|
159
|
-
var _a;
|
|
160
|
-
return (_a = res === null || res === void 0 ? void 0 : res.toObject()) !== null && _a !== void 0 ? _a : null;
|
|
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;
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* get data by dependency data id,
|
|
179
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLD2)
|
|
180
|
-
*
|
|
181
|
-
* @param dependencyId id
|
|
182
|
-
* @returns dataList
|
|
183
|
-
*/
|
|
184
|
-
getDataListByDependencyId(dependencyId) {
|
|
185
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
if (!this.depDataName) {
|
|
187
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
188
|
-
status: 501,
|
|
189
|
-
errorCode: 'NTS-DBS-GLD0',
|
|
190
|
-
addECToUserMsg: true,
|
|
191
|
-
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
192
|
-
userMessage: this.defaultErrorUserMsg
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
let dataList = yield this.dataModel.find({ [this.depDataName]: dependencyId }).then(res => {
|
|
196
|
-
var _a;
|
|
197
|
-
return (_a = res) !== null && _a !== void 0 ? _a : [];
|
|
198
|
-
}).catch(error => {
|
|
199
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
200
|
-
status: 417,
|
|
201
|
-
errorCode: 'NTS-DBS-GLD1',
|
|
202
|
-
addECToUserMsg: true,
|
|
203
|
-
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
204
|
-
userMessage: this.defaultErrorUserMsg,
|
|
205
|
-
error
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
if (0 < dataList.length) {
|
|
209
|
-
dataList.forEach((data) => {
|
|
210
|
-
if (data && typeof data._id === 'object') {
|
|
211
|
-
data._id = `${data._id}`;
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
return dataList;
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* get multiple data objects by a list of DependencyIDs,
|
|
220
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLDS2)
|
|
221
|
-
*
|
|
222
|
-
* @param ids ids
|
|
223
|
-
* @returns dataList
|
|
224
|
-
*/
|
|
225
|
-
getDataListByDependencyIds(ids) {
|
|
226
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
227
|
-
if (!this.depDataName) {
|
|
228
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
229
|
-
status: 501,
|
|
230
|
-
errorCode: 'NTS-DBS-GLDS0',
|
|
231
|
-
addECToUserMsg: true,
|
|
232
|
-
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
233
|
-
userMessage: this.defaultErrorUserMsg
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
let dataList = yield this.dataModel.find({ [this.depDataName]: { $in: ids } }).then(res => {
|
|
237
|
-
var _a;
|
|
238
|
-
return (_a = res) !== null && _a !== void 0 ? _a : [];
|
|
239
|
-
}).catch(error => {
|
|
240
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
241
|
-
status: 417,
|
|
242
|
-
errorCode: 'NTS-DBS-GLDS1',
|
|
243
|
-
addECToUserMsg: true,
|
|
244
|
-
message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (NTS DB)`,
|
|
245
|
-
userMessage: this.defaultErrorUserMsg,
|
|
246
|
-
error
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
if (0 < dataList.length) {
|
|
250
|
-
dataList.forEach((data) => {
|
|
251
|
-
if (data && typeof data._id === 'object') {
|
|
252
|
-
data._id = `${data._id}`;
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
return dataList;
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* returns
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* @
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
// ----------------------------------------------------------------------------------
|
|
423
|
-
// ----------------------------------------------------------------------------------
|
|
424
|
-
// ----------------------------------------------------------------------------------
|
|
425
|
-
// DIRECT Basic MONGOOSE FUNCTIONS (with error handlings)
|
|
426
|
-
/**
|
|
427
|
-
* Find the data first by any of its parameters,
|
|
428
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-FO1)
|
|
429
|
-
*
|
|
430
|
-
* @param
|
|
431
|
-
*
|
|
432
|
-
* @example
|
|
433
|
-
* // by email:
|
|
434
|
-
* { email: email }
|
|
435
|
-
* //
|
|
436
|
-
* @example
|
|
437
|
-
* // or by id that is in list:
|
|
438
|
-
* { userIds: { $in: this.userId } }
|
|
439
|
-
* //
|
|
440
|
-
* @example
|
|
441
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
442
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
443
|
-
* // further tools (syntax matches with $gt):
|
|
444
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
445
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
446
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
447
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
448
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
449
|
-
* //
|
|
450
|
-
* @returns {T} data: T
|
|
451
|
-
*/
|
|
452
|
-
findOne(
|
|
453
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
454
|
-
let data = yield this.dataModel.findOne(
|
|
455
|
-
var _a;
|
|
456
|
-
return (_a = res) !== null && _a !== void 0 ? _a : null;
|
|
457
|
-
}).catch(error => {
|
|
458
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
459
|
-
status: 417,
|
|
460
|
-
errorCode: 'NTS-DBS-FO0',
|
|
461
|
-
addECToUserMsg: true,
|
|
462
|
-
message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB) fliter: ${
|
|
463
|
-
userMessage: this.defaultErrorUserMsg,
|
|
464
|
-
error
|
|
465
|
-
});
|
|
466
|
-
});
|
|
467
|
-
if (data && typeof data._id === 'object') {
|
|
468
|
-
data._id = `${data._id}`;
|
|
469
|
-
}
|
|
470
|
-
return data;
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* #MONGOOSE FUNCTION
|
|
475
|
-
* Find the data first by any of its parameters,
|
|
476
|
-
* !!!: throws error if not found (errorCode on not found: NTS-DBS-F1)
|
|
477
|
-
*
|
|
478
|
-
* @param
|
|
479
|
-
*
|
|
480
|
-
* @example
|
|
481
|
-
* // by email:
|
|
482
|
-
* { email: email }
|
|
483
|
-
* //
|
|
484
|
-
* @example
|
|
485
|
-
* // or by id that is in list:
|
|
486
|
-
* { userIds: { $in: this.userId } }
|
|
487
|
-
* //
|
|
488
|
-
* @example
|
|
489
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
490
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
491
|
-
* // further tools (syntax matches with $gt):
|
|
492
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
493
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
494
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
495
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
496
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
497
|
-
* //
|
|
498
|
-
* @returns {T[]} dataList: T[]
|
|
499
|
-
*/
|
|
500
|
-
find(
|
|
501
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
502
|
-
let dataList = yield this.dataModel.find(
|
|
503
|
-
.then(res => {
|
|
504
|
-
var _a;
|
|
505
|
-
return (_a = res) !== null && _a !== void 0 ? _a : [];
|
|
506
|
-
}).catch(error => {
|
|
507
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
508
|
-
status: 417,
|
|
509
|
-
errorCode: 'NTS-DBS-F0',
|
|
510
|
-
addECToUserMsg: true,
|
|
511
|
-
message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
512
|
-
userMessage: this.defaultErrorUserMsg,
|
|
513
|
-
error
|
|
514
|
-
});
|
|
515
|
-
});
|
|
516
|
-
if (0 < dataList.length) {
|
|
517
|
-
dataList.forEach((data) => {
|
|
518
|
-
if (data && typeof data._id === 'object') {
|
|
519
|
-
data._id = `${data._id}`;
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
return dataList;
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
/**
|
|
527
|
-
* #MONGOOSE FUNCTION
|
|
528
|
-
* Find the data first by any of its parameters
|
|
529
|
-
*
|
|
530
|
-
* @param
|
|
531
|
-
*
|
|
532
|
-
* @example
|
|
533
|
-
* // by email:
|
|
534
|
-
* { email: email }
|
|
535
|
-
* //
|
|
536
|
-
* @example
|
|
537
|
-
* // or by id that is in list:
|
|
538
|
-
* { userIds: { $in: this.userId } }
|
|
539
|
-
* //
|
|
540
|
-
* @example
|
|
541
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
542
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
543
|
-
* // further tools (syntax matches with $gt):
|
|
544
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
545
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
546
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
547
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
548
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
549
|
-
* //
|
|
550
|
-
* @param page page
|
|
551
|
-
* @param pageSize pageSize
|
|
552
|
-
* @param sort
|
|
553
|
-
* @example
|
|
554
|
-
* // by dateTime (this uses the basic sort function):
|
|
555
|
-
* { dateTime: -1 }
|
|
556
|
-
* //
|
|
557
|
-
* @returns {T[]} dataList: T[]
|
|
558
|
-
*/
|
|
559
|
-
findWithPaging(
|
|
560
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
561
|
-
let dataList = yield this.dataModel.find(
|
|
562
|
-
.sort(sort)
|
|
563
|
-
.skip(page * pageSize)
|
|
564
|
-
.limit(pageSize)
|
|
565
|
-
.then(res => res !== null && res !== void 0 ? res : [])
|
|
566
|
-
.catch(error => {
|
|
567
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
568
|
-
status: 417,
|
|
569
|
-
errorCode: 'NTS-DBS-WP0',
|
|
570
|
-
addECToUserMsg: true,
|
|
571
|
-
message: `findWithPaging ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
572
|
-
userMessage: this.defaultErrorUserMsg,
|
|
573
|
-
error
|
|
574
|
-
});
|
|
575
|
-
});
|
|
576
|
-
if (0 < dataList.length) {
|
|
577
|
-
dataList.forEach((data) => {
|
|
578
|
-
if (data && typeof data._id === 'object') {
|
|
579
|
-
data._id = `${data._id}`;
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
return dataList;
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* #MONGOOSE FUNCTION
|
|
588
|
-
* Find data by _id and update
|
|
589
|
-
* !!!: throws error if not found (errorCode on not found: )
|
|
590
|
-
*
|
|
591
|
-
* @param id id
|
|
592
|
-
* @param update update
|
|
593
|
-
* @returns data
|
|
594
|
-
*/
|
|
595
|
-
findByIdAndUpdate(id, update, modifier) {
|
|
596
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
597
|
-
update.__lastModified = new Date();
|
|
598
|
-
update.__lastModifiedBy = modifier;
|
|
599
|
-
let newData = yield this.dataModel.findByIdAndUpdate(id, update).then(res => {
|
|
600
|
-
var _a;
|
|
601
|
-
return (_a = res === null || res === void 0 ? void 0 : res.toObject()) !== null && _a !== void 0 ? _a : null;
|
|
602
|
-
}).catch(error => {
|
|
603
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
604
|
-
status: 417,
|
|
605
|
-
errorCode: 'NTS-DBS-FIU0',
|
|
606
|
-
addECToUserMsg: true,
|
|
607
|
-
message: `findByIdAndUpdate ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
608
|
-
userMessage: this.defaultErrorUserMsg,
|
|
609
|
-
error
|
|
610
|
-
});
|
|
611
|
-
});
|
|
612
|
-
if (typeof newData._id === 'object') {
|
|
613
|
-
newData._id = `${newData._id}`;
|
|
614
|
-
}
|
|
615
|
-
return newData;
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* #MONGOOSE FUNCTION
|
|
620
|
-
* Find the data first by any of its parameters
|
|
621
|
-
*
|
|
622
|
-
* @param filter This uses the basic Mongoose updateOne.
|
|
623
|
-
* If you can, use unique parameters for find!
|
|
624
|
-
* @example
|
|
625
|
-
* // by email:
|
|
626
|
-
* { email: email }
|
|
627
|
-
* //
|
|
628
|
-
* @example
|
|
629
|
-
* // or by id that is in list:
|
|
630
|
-
* { userIds: { $in: this.userId } }
|
|
631
|
-
* //
|
|
632
|
-
* @example
|
|
633
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
634
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
635
|
-
* // further tools (syntax matches with $gt):
|
|
636
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
637
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
638
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
639
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
640
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
641
|
-
* //
|
|
642
|
-
*
|
|
643
|
-
* @param update this uses the basic Mongoose updateOne
|
|
644
|
-
* @example
|
|
645
|
-
* // increase a specific value (here by 15):
|
|
646
|
-
* { $inc: { popularity: 15 } }
|
|
647
|
-
* //
|
|
648
|
-
* @example
|
|
649
|
-
* // or add element to a list:
|
|
650
|
-
* { $push: { reactions: this.newReaction }
|
|
651
|
-
* // or add multiple elements to a list
|
|
652
|
-
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
653
|
-
* //
|
|
654
|
-
* @example
|
|
655
|
-
* // or all at once
|
|
656
|
-
* {
|
|
657
|
-
* $inc: { popularity: this.newVote.amount },
|
|
658
|
-
* emailVerified: true,
|
|
659
|
-
* $push: { reactions: this.newReaction }
|
|
660
|
-
* }
|
|
661
|
-
* // further tools (syntax matches with $inc):
|
|
662
|
-
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
663
|
-
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
664
|
-
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
665
|
-
* $mul: // Multiplies the value of the field by the specified amount.
|
|
666
|
-
* $rename: // Renames a field.
|
|
667
|
-
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
668
|
-
* //
|
|
669
|
-
*/
|
|
670
|
-
updateOne(
|
|
671
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
672
|
-
update.__lastModified = new Date();
|
|
673
|
-
update.__lastModifiedBy = issuer;
|
|
674
|
-
yield this.dataModel.updateOne(
|
|
675
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
676
|
-
status: 417,
|
|
677
|
-
errorCode: 'NTS-DBS-UO0',
|
|
678
|
-
addECToUserMsg: true,
|
|
679
|
-
message: `updateOne ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
680
|
-
userMessage: this.defaultErrorUserMsg,
|
|
681
|
-
error
|
|
682
|
-
});
|
|
683
|
-
});
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* #MONGOOSE FUNCTION
|
|
688
|
-
* update one parameter by a specific
|
|
689
|
-
*
|
|
690
|
-
* @param filter This uses the basic Mongoose updateMany.
|
|
691
|
-
* @example
|
|
692
|
-
* // by email:
|
|
693
|
-
* { email: email }
|
|
694
|
-
* //
|
|
695
|
-
* @example
|
|
696
|
-
* // or by id that is in list:
|
|
697
|
-
* { userIds: { $in: this.userId } }
|
|
698
|
-
* //
|
|
699
|
-
* @example
|
|
700
|
-
* // or by number or Date that is Greater Than AND Less Than:
|
|
701
|
-
* { points: { $gt: 2, $lt: 14 } }
|
|
702
|
-
* // further tools (syntax matches with $gt):
|
|
703
|
-
* $eq: // Matches values that are EQual to a specified value.
|
|
704
|
-
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
705
|
-
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
706
|
-
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
707
|
-
* $nin: // Matches None of the values specified IN an array.
|
|
708
|
-
* //
|
|
709
|
-
*
|
|
710
|
-
* @param update this uses the basic Mongoose updateOne
|
|
711
|
-
* @example
|
|
712
|
-
* // increase a specific value (here by 15):
|
|
713
|
-
* { $inc: { popularity: 15 } }
|
|
714
|
-
* //
|
|
715
|
-
* @example
|
|
716
|
-
* // or add element to a list:
|
|
717
|
-
* { $push: { reactions: this.newReaction }
|
|
718
|
-
* // or add multiple elements to a list
|
|
719
|
-
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
720
|
-
* //
|
|
721
|
-
* @example
|
|
722
|
-
* // or all at once
|
|
723
|
-
* {
|
|
724
|
-
* $inc: { popularity: this.newVote.amount },
|
|
725
|
-
* emailVerified: true,
|
|
726
|
-
* $push: { reactions: this.newReaction }
|
|
727
|
-
* }
|
|
728
|
-
* // further tools (syntax matches with $inc):
|
|
729
|
-
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
730
|
-
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
731
|
-
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
732
|
-
* $mul: // Multiplies the value of the field by the specified amount.
|
|
733
|
-
* $rename: // Renames a field.
|
|
734
|
-
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
735
|
-
* //
|
|
736
|
-
*/
|
|
737
|
-
updateMany(
|
|
738
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
739
|
-
update.__lastModified = new Date();
|
|
740
|
-
update.__lastModifiedBy = issuer;
|
|
741
|
-
yield this.dataModel.updateMany(
|
|
742
|
-
throw new fsm_dynamo_1.Dynamo_Error({
|
|
743
|
-
status: 417,
|
|
744
|
-
errorCode: 'NTS-DBS-UM0',
|
|
745
|
-
addECToUserMsg: true,
|
|
746
|
-
message: `updateMany ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
747
|
-
userMessage: this.defaultErrorUserMsg,
|
|
748
|
-
error
|
|
749
|
-
});
|
|
750
|
-
});
|
|
751
|
-
});
|
|
752
|
-
}
|
|
753
|
-
// ----------------------------------------------------------------------------------
|
|
754
|
-
// ----------------------------------------------------------------------------------
|
|
755
|
-
// ----------------------------------------------------------------------------------
|
|
756
|
-
// PRIVATE BUILD FUNCTIONS
|
|
757
|
-
/**
|
|
758
|
-
* builds and returns mongoose schema
|
|
759
|
-
* @returns schema
|
|
760
|
-
*/
|
|
761
|
-
getSchema() {
|
|
762
|
-
let schema = this.buildMongooseSchemaByModelParams();
|
|
763
|
-
schema = this.addDynamo_MetadataToSchema(schema);
|
|
764
|
-
// tslint:disable-next-line: no-string-literal
|
|
765
|
-
if (schema['_id']) {
|
|
766
|
-
// tslint:disable-next-line: no-string-literal
|
|
767
|
-
delete schema['_id'];
|
|
768
|
-
}
|
|
769
|
-
return new mongoose_1.Schema(schema);
|
|
770
|
-
}
|
|
771
|
-
/**
|
|
772
|
-
* builds mongoose schema building settings object by dynamoDataModelParamsList
|
|
773
|
-
* @param params DynamoBEDataPropertyParams
|
|
774
|
-
* @returns mongoose schema object
|
|
775
|
-
*/
|
|
776
|
-
buildMongooseSchemaByModelParams(params) {
|
|
777
|
-
const schemaSettingsObj = {};
|
|
778
|
-
if (!params) {
|
|
779
|
-
params = this.dataParams.modelParams;
|
|
780
|
-
}
|
|
781
|
-
params.forEach((property) => {
|
|
782
|
-
var _a;
|
|
783
|
-
const beType = this.getBEType(property.type);
|
|
784
|
-
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) {
|
|
785
|
-
schemaSettingsObj[property.key] = {
|
|
786
|
-
type: beType
|
|
787
|
-
};
|
|
788
|
-
if (property.index) {
|
|
789
|
-
schemaSettingsObj[property.key].index = true;
|
|
790
|
-
}
|
|
791
|
-
if (property.unique) {
|
|
792
|
-
schemaSettingsObj[property.key].unique = true;
|
|
793
|
-
}
|
|
794
|
-
if (property.required) {
|
|
795
|
-
schemaSettingsObj[property.key].required = true;
|
|
796
|
-
}
|
|
797
|
-
if (property.minlength) {
|
|
798
|
-
schemaSettingsObj[property.key].minlength = property.minlength;
|
|
799
|
-
}
|
|
800
|
-
if (property.maxlength) {
|
|
801
|
-
schemaSettingsObj[property.key].maxlength = property.maxlength;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
else {
|
|
805
|
-
schemaSettingsObj[property.key] = this.buildMongooseSchemaByModelParams(property.subObjectParams);
|
|
806
|
-
}
|
|
807
|
-
});
|
|
808
|
-
return schemaSettingsObj;
|
|
809
|
-
}
|
|
810
|
-
getBEType(type) {
|
|
811
|
-
switch (type) {
|
|
812
|
-
case 'string':
|
|
813
|
-
return String;
|
|
814
|
-
case 'number':
|
|
815
|
-
return Number;
|
|
816
|
-
case 'boolean':
|
|
817
|
-
return Boolean;
|
|
818
|
-
case 'Date':
|
|
819
|
-
return Date;
|
|
820
|
-
case 'object':
|
|
821
|
-
return Object;
|
|
822
|
-
default:
|
|
823
|
-
if (type.includes('[]')) {
|
|
824
|
-
return Array;
|
|
825
|
-
}
|
|
826
|
-
else if (type.includes('=>') || type.includes('function')) {
|
|
827
|
-
return Function;
|
|
828
|
-
}
|
|
829
|
-
else {
|
|
830
|
-
return Object;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
/**
|
|
835
|
-
* adds dynamo metadata settings to any mongoose schema building settings object
|
|
836
|
-
* @param schema schema to update
|
|
837
|
-
* @returns updated schema
|
|
838
|
-
*/
|
|
839
|
-
addDynamo_MetadataToSchema(schema) {
|
|
840
|
-
schema.__created = { type: Date };
|
|
841
|
-
schema.__createdBy = { type: String };
|
|
842
|
-
schema.__lastModified = { type: Date };
|
|
843
|
-
schema.__lastModifiedBy = { type: String };
|
|
844
|
-
return schema;
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* sets depDataKey
|
|
848
|
-
*/
|
|
849
|
-
lookForDependencyDataSettings() {
|
|
850
|
-
const dependencyParam = this.dataParams.modelParams.find((modelParams) => modelParams.isDependencyHook);
|
|
851
|
-
if (dependencyParam) {
|
|
852
|
-
this.depDataName = dependencyParam.key;
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
exports.DynamoNTS_DBService = DynamoNTS_DBService;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DynamoNTS_DBService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const mongoose = tslib_1.__importStar(require("mongoose"));
|
|
6
|
+
const mongoose_1 = require("mongoose");
|
|
7
|
+
const fsm_dynamo_1 = require("@futdevpro/fsm-dynamo");
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
class DynamoNTS_DBService {
|
|
12
|
+
/**
|
|
13
|
+
* @param dataName name the model
|
|
14
|
+
* @param typeSample sample data for scheme creation (dont include Dynamo_Metadata!)
|
|
15
|
+
* @param schemaSettings additional settings for specific parameters as unique, required, minlength or maxlength
|
|
16
|
+
* schemaSettings also MUST contain specific types that differs from the listed above (Array, Date)
|
|
17
|
+
*/
|
|
18
|
+
constructor(dataParams) {
|
|
19
|
+
this.dataParams = dataParams;
|
|
20
|
+
this.dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
|
|
21
|
+
this.defaultErrorUserMsg = `We encountered an unhandled DB Error, ` +
|
|
22
|
+
`\nplease contact the responsible development team.`;
|
|
23
|
+
this.lookForDependencyDataSettings();
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* save new data
|
|
27
|
+
* @param data data
|
|
28
|
+
* @returns data
|
|
29
|
+
*/
|
|
30
|
+
createData(data, issuer) {
|
|
31
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
data.__created = new Date();
|
|
33
|
+
data.__lastModified = new Date();
|
|
34
|
+
data.__createdBy = issuer;
|
|
35
|
+
data.__lastModifiedBy = issuer;
|
|
36
|
+
const dataModel = new this.dataModel(data);
|
|
37
|
+
let newData = yield dataModel.save().then(res => {
|
|
38
|
+
if (res) {
|
|
39
|
+
return res === null || res === void 0 ? void 0 : res.toObject();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
43
|
+
status: 204,
|
|
44
|
+
errorCode: 'NTS-DBS-CD1',
|
|
45
|
+
addECToUserMsg: true,
|
|
46
|
+
message: `createData failed, save ${this.dataParams.dbName} result not found! (NTS DB)`,
|
|
47
|
+
userMessage: this.defaultErrorUserMsg
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}).catch(error => {
|
|
51
|
+
if ((error === null || error === void 0 ? void 0 : error.flag) == 'DYNAMO ERROR OBJECT') {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
56
|
+
status: 422,
|
|
57
|
+
errorCode: 'NTS-DBS-CD0',
|
|
58
|
+
addECToUserMsg: true,
|
|
59
|
+
message: `createData failed, Create new ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
60
|
+
userMessage: this.defaultErrorUserMsg,
|
|
61
|
+
error
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
if (typeof newData._id === 'object') {
|
|
66
|
+
newData._id = `${newData._id}`;
|
|
67
|
+
}
|
|
68
|
+
data._id = newData._id;
|
|
69
|
+
data.__v = newData.__v;
|
|
70
|
+
return data;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Find data by _id and update
|
|
75
|
+
* @param data data
|
|
76
|
+
* @returns data
|
|
77
|
+
*/
|
|
78
|
+
modifyData(data, issuer) {
|
|
79
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
data.__lastModified = new Date();
|
|
81
|
+
data.__lastModifiedBy = issuer;
|
|
82
|
+
const dataModel = new this.dataModel(data);
|
|
83
|
+
let newData = yield this.dataModel.findByIdAndUpdate(data._id, dataModel).then(res => {
|
|
84
|
+
if (res) {
|
|
85
|
+
return res === null || res === void 0 ? void 0 : res.toObject();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
89
|
+
status: 204,
|
|
90
|
+
errorCode: 'NTS-DBS-FU1',
|
|
91
|
+
addECToUserMsg: true,
|
|
92
|
+
message: `modifyData failed, modify ${this.dataParams.dbName} result not found! (NTS DB)`,
|
|
93
|
+
userMessage: this.defaultErrorUserMsg,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}).catch(error => {
|
|
97
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
98
|
+
status: 417,
|
|
99
|
+
errorCode: 'NTS-DBS-FU0',
|
|
100
|
+
addECToUserMsg: true,
|
|
101
|
+
message: `modifyData ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
102
|
+
userMessage: this.defaultErrorUserMsg,
|
|
103
|
+
error
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
if (typeof newData._id === 'object') {
|
|
107
|
+
newData._id = `${newData._id}`;
|
|
108
|
+
}
|
|
109
|
+
data._id = newData._id;
|
|
110
|
+
data.__v = newData.__v;
|
|
111
|
+
return data;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* returns data by _id,
|
|
116
|
+
* @param id id
|
|
117
|
+
* @returns data
|
|
118
|
+
*/
|
|
119
|
+
getDataById(id) {
|
|
120
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
let data = yield this.dataModel.findById(id).then(res => {
|
|
122
|
+
var _a;
|
|
123
|
+
return (_a = res === null || res === void 0 ? void 0 : res.toObject()) !== null && _a !== void 0 ? _a : null;
|
|
124
|
+
}).catch(error => {
|
|
125
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
126
|
+
status: 417,
|
|
127
|
+
errorCode: 'NTS-DBS-GI0',
|
|
128
|
+
addECToUserMsg: true,
|
|
129
|
+
message: `get ${this.dataParams.dbName} by ID was unsuccessful (NTS DB)`,
|
|
130
|
+
userMessage: this.defaultErrorUserMsg,
|
|
131
|
+
error
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
if (data && typeof data._id === 'object') {
|
|
135
|
+
data._id = `${data._id}`;
|
|
136
|
+
}
|
|
137
|
+
return data;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* get data by dependency data id,
|
|
142
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GD2)
|
|
143
|
+
*
|
|
144
|
+
* @param dependencyId id
|
|
145
|
+
* @returns data
|
|
146
|
+
*/
|
|
147
|
+
getDataByDependencyId(dependencyId) {
|
|
148
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
if (!this.depDataName) {
|
|
150
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
151
|
+
status: 501,
|
|
152
|
+
errorCode: 'NTS-DBS-GD0',
|
|
153
|
+
addECToUserMsg: true,
|
|
154
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
155
|
+
userMessage: this.defaultErrorUserMsg
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
let data = yield this.dataModel.findOne({ [this.depDataName]: dependencyId }).then(res => {
|
|
159
|
+
var _a;
|
|
160
|
+
return (_a = res === null || res === void 0 ? void 0 : res.toObject()) !== null && _a !== void 0 ? _a : null;
|
|
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;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* get data by dependency data id,
|
|
179
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLD2)
|
|
180
|
+
*
|
|
181
|
+
* @param dependencyId id
|
|
182
|
+
* @returns dataList
|
|
183
|
+
*/
|
|
184
|
+
getDataListByDependencyId(dependencyId) {
|
|
185
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
if (!this.depDataName) {
|
|
187
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
188
|
+
status: 501,
|
|
189
|
+
errorCode: 'NTS-DBS-GLD0',
|
|
190
|
+
addECToUserMsg: true,
|
|
191
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
192
|
+
userMessage: this.defaultErrorUserMsg
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
let dataList = yield this.dataModel.find({ [this.depDataName]: dependencyId }).then(res => {
|
|
196
|
+
var _a;
|
|
197
|
+
return (_a = res) !== null && _a !== void 0 ? _a : [];
|
|
198
|
+
}).catch(error => {
|
|
199
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
200
|
+
status: 417,
|
|
201
|
+
errorCode: 'NTS-DBS-GLD1',
|
|
202
|
+
addECToUserMsg: true,
|
|
203
|
+
message: `get ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
204
|
+
userMessage: this.defaultErrorUserMsg,
|
|
205
|
+
error
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
if (0 < dataList.length) {
|
|
209
|
+
dataList.forEach((data) => {
|
|
210
|
+
if (data && typeof data._id === 'object') {
|
|
211
|
+
data._id = `${data._id}`;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
return dataList;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* get multiple data objects by a list of DependencyIDs,
|
|
220
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GLDS2)
|
|
221
|
+
*
|
|
222
|
+
* @param ids ids
|
|
223
|
+
* @returns dataList
|
|
224
|
+
*/
|
|
225
|
+
getDataListByDependencyIds(ids) {
|
|
226
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
227
|
+
if (!this.depDataName) {
|
|
228
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
229
|
+
status: 501,
|
|
230
|
+
errorCode: 'NTS-DBS-GLDS0',
|
|
231
|
+
addECToUserMsg: true,
|
|
232
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
233
|
+
userMessage: this.defaultErrorUserMsg
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
let dataList = yield this.dataModel.find({ [this.depDataName]: { $in: ids } }).then(res => {
|
|
237
|
+
var _a;
|
|
238
|
+
return (_a = res) !== null && _a !== void 0 ? _a : [];
|
|
239
|
+
}).catch(error => {
|
|
240
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
241
|
+
status: 417,
|
|
242
|
+
errorCode: 'NTS-DBS-GLDS1',
|
|
243
|
+
addECToUserMsg: true,
|
|
244
|
+
message: `get ${this.dataParams.dbName}s by ${this.depDataName}s was unsuccessful (NTS DB)`,
|
|
245
|
+
userMessage: this.defaultErrorUserMsg,
|
|
246
|
+
error
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
if (0 < dataList.length) {
|
|
250
|
+
dataList.forEach((data) => {
|
|
251
|
+
if (data && typeof data._id === 'object') {
|
|
252
|
+
data._id = `${data._id}`;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
return dataList;
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* returns all data from database,
|
|
261
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-GA1)
|
|
262
|
+
*
|
|
263
|
+
* @returns dataList
|
|
264
|
+
*/
|
|
265
|
+
getAll() {
|
|
266
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
let dataList = yield this.dataModel.find({})
|
|
268
|
+
.then(res => {
|
|
269
|
+
var _a;
|
|
270
|
+
return (_a = res) !== null && _a !== void 0 ? _a : [];
|
|
271
|
+
}).catch(error => {
|
|
272
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
273
|
+
status: 417,
|
|
274
|
+
errorCode: 'NTS-DBS-GA0',
|
|
275
|
+
addECToUserMsg: true,
|
|
276
|
+
message: `get all ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
277
|
+
userMessage: this.defaultErrorUserMsg,
|
|
278
|
+
error
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
if (0 < dataList.length && typeof dataList[0]._id === 'object') {
|
|
282
|
+
dataList.forEach((data) => {
|
|
283
|
+
data._id = `˙${data._id}`;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
return dataList;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* deleted data by id
|
|
291
|
+
* @param id id
|
|
292
|
+
*/
|
|
293
|
+
deleteDataById(id) {
|
|
294
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
yield this.dataModel.findByIdAndDelete(id).catch(error => {
|
|
296
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
297
|
+
status: 417,
|
|
298
|
+
errorCode: 'NTS-DBS-DD0',
|
|
299
|
+
addECToUserMsg: true,
|
|
300
|
+
message: `delete ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
301
|
+
userMessage: this.defaultErrorUserMsg,
|
|
302
|
+
error
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* deleted data by id
|
|
309
|
+
* @param dependencyId id
|
|
310
|
+
*/
|
|
311
|
+
deleteDataByDependencyId(dependencyId) {
|
|
312
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
313
|
+
if (!this.depDataName) {
|
|
314
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
315
|
+
status: 501,
|
|
316
|
+
errorCode: 'NTS-DBS-DDD0',
|
|
317
|
+
addECToUserMsg: true,
|
|
318
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
319
|
+
userMessage: this.defaultErrorUserMsg
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
yield this.dataModel.deleteMany({ [this.depDataName]: dependencyId }).catch(error => {
|
|
323
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
324
|
+
status: 417,
|
|
325
|
+
errorCode: 'NTS-DBS-DDD1',
|
|
326
|
+
addECToUserMsg: true,
|
|
327
|
+
message: `delete ${this.dataParams.dbName} by ${this.depDataName} was unsuccessful (NTS DB)`,
|
|
328
|
+
userMessage: this.defaultErrorUserMsg,
|
|
329
|
+
error
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* returns search result for searchBy object params
|
|
336
|
+
* can use lists or xRange values for searchBy obj properties
|
|
337
|
+
*
|
|
338
|
+
* @param filterBy filter
|
|
339
|
+
* @param narrowByDependencyIds id
|
|
340
|
+
* @returns dataList
|
|
341
|
+
*/
|
|
342
|
+
searchData(filterBy, narrowByDependencyIds) {
|
|
343
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
344
|
+
const filter = {};
|
|
345
|
+
if (0 < narrowByDependencyIds.length) {
|
|
346
|
+
if (!this.depDataName) {
|
|
347
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
348
|
+
status: 501,
|
|
349
|
+
errorCode: 'NTS-DBS-SD0',
|
|
350
|
+
addECToUserMsg: true,
|
|
351
|
+
message: `dependencyDataIdKey not setted up for this db-service (${this.dataParams.dbName}) (NTS DB)`,
|
|
352
|
+
userMessage: this.defaultErrorUserMsg
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
filter[this.depDataName] = { $in: narrowByDependencyIds };
|
|
356
|
+
}
|
|
357
|
+
yield this.dataParams.modelParams.forEach((modelParam) => {
|
|
358
|
+
if ((filterBy[modelParam.key] !== null && filterBy[modelParam.key] !== undefined) ||
|
|
359
|
+
filterBy[modelParam.key + 'Range']) {
|
|
360
|
+
if (modelParam.key.includes('Range') || modelParam.type.includes('[]')) {
|
|
361
|
+
// inverz search filter (for Range and Array functions)
|
|
362
|
+
if (modelParam.key.includes('Range')) {
|
|
363
|
+
const searchParamKeyWithoutRange = modelParam.key.split('Range')[0];
|
|
364
|
+
if (filterBy[searchParamKeyWithoutRange] !== null &&
|
|
365
|
+
filterBy[searchParamKeyWithoutRange] !== undefined) {
|
|
366
|
+
filter[modelParam.key] = {
|
|
367
|
+
from: { $lte: filterBy[searchParamKeyWithoutRange] },
|
|
368
|
+
to: { $gte: filterBy[searchParamKeyWithoutRange] }
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
if (filterBy[modelParam.key] !== null &&
|
|
374
|
+
filterBy[modelParam.key] !== undefined) {
|
|
375
|
+
filter[modelParam.key] = { $in: filterBy[modelParam.key] };
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
// basic search filter
|
|
381
|
+
if (filterBy[modelParam.key + 'Range']) {
|
|
382
|
+
if (filterBy[modelParam.key + 'Range'].from || filterBy[modelParam.key + 'Range'].to) {
|
|
383
|
+
filter[modelParam.key] = {};
|
|
384
|
+
if (filterBy[modelParam.key + 'Range'].from) {
|
|
385
|
+
filter[modelParam.key].$gte = filterBy[modelParam.key + 'Range'].from;
|
|
386
|
+
}
|
|
387
|
+
if (filterBy[modelParam.key + 'Range'].to) {
|
|
388
|
+
filter[modelParam.key].$lte = filterBy[modelParam.key + 'Range'].to;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
else if (filterBy[modelParam.key] !== null && filterBy[modelParam.key] !== undefined) {
|
|
393
|
+
if (filterBy[modelParam.key].lenght > 0) {
|
|
394
|
+
filter[modelParam.key] = { $in: filterBy[modelParam.key] };
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
let dataList = yield this.dataModel.find(filter)
|
|
401
|
+
.then(res => res !== null && res !== void 0 ? res : [])
|
|
402
|
+
.catch(error => {
|
|
403
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
404
|
+
status: 417,
|
|
405
|
+
errorCode: 'NTS-DBS-SD1',
|
|
406
|
+
addECToUserMsg: true,
|
|
407
|
+
message: `search ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
408
|
+
userMessage: this.defaultErrorUserMsg,
|
|
409
|
+
error
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
if (0 < dataList.length) {
|
|
413
|
+
dataList.forEach((data) => {
|
|
414
|
+
if (data && typeof data._id === 'object') {
|
|
415
|
+
data._id = `${data._id}`;
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
return dataList;
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
// ----------------------------------------------------------------------------------
|
|
423
|
+
// ----------------------------------------------------------------------------------
|
|
424
|
+
// ----------------------------------------------------------------------------------
|
|
425
|
+
// DIRECT Basic MONGOOSE FUNCTIONS (with error handlings)
|
|
426
|
+
/**
|
|
427
|
+
* Find the data first by any of its parameters,
|
|
428
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-FO1)
|
|
429
|
+
*
|
|
430
|
+
* @param filterBy if you can, use unique parameters for find!
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* // by email:
|
|
434
|
+
* { email: email }
|
|
435
|
+
* //
|
|
436
|
+
* @example
|
|
437
|
+
* // or by id that is in list:
|
|
438
|
+
* { userIds: { $in: this.userId } }
|
|
439
|
+
* //
|
|
440
|
+
* @example
|
|
441
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
442
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
443
|
+
* // further tools (syntax matches with $gt):
|
|
444
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
445
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
446
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
447
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
448
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
449
|
+
* //
|
|
450
|
+
* @returns {T} data: T
|
|
451
|
+
*/
|
|
452
|
+
findOne(filterBy) {
|
|
453
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
454
|
+
let data = yield this.dataModel.findOne(filterBy).then(res => {
|
|
455
|
+
var _a;
|
|
456
|
+
return (_a = res) !== null && _a !== void 0 ? _a : null;
|
|
457
|
+
}).catch(error => {
|
|
458
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
459
|
+
status: 417,
|
|
460
|
+
errorCode: 'NTS-DBS-FO0',
|
|
461
|
+
addECToUserMsg: true,
|
|
462
|
+
message: `findOne ${this.dataParams.dbName} was unsuccessful (NTS DB) fliter: ${filterBy}`,
|
|
463
|
+
userMessage: this.defaultErrorUserMsg,
|
|
464
|
+
error
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
if (data && typeof data._id === 'object') {
|
|
468
|
+
data._id = `${data._id}`;
|
|
469
|
+
}
|
|
470
|
+
return data;
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* #MONGOOSE FUNCTION
|
|
475
|
+
* Find the data first by any of its parameters,
|
|
476
|
+
* !!!: throws error if not found (errorCode on not found: NTS-DBS-F1)
|
|
477
|
+
*
|
|
478
|
+
* @param filterBy if you can, use unique parameters for find!
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* // by email:
|
|
482
|
+
* { email: email }
|
|
483
|
+
* //
|
|
484
|
+
* @example
|
|
485
|
+
* // or by id that is in list:
|
|
486
|
+
* { userIds: { $in: this.userId } }
|
|
487
|
+
* //
|
|
488
|
+
* @example
|
|
489
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
490
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
491
|
+
* // further tools (syntax matches with $gt):
|
|
492
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
493
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
494
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
495
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
496
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
497
|
+
* //
|
|
498
|
+
* @returns {T[]} dataList: T[]
|
|
499
|
+
*/
|
|
500
|
+
find(filterBy) {
|
|
501
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
502
|
+
let dataList = yield this.dataModel.find(filterBy)
|
|
503
|
+
.then(res => {
|
|
504
|
+
var _a;
|
|
505
|
+
return (_a = res) !== null && _a !== void 0 ? _a : [];
|
|
506
|
+
}).catch(error => {
|
|
507
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
508
|
+
status: 417,
|
|
509
|
+
errorCode: 'NTS-DBS-F0',
|
|
510
|
+
addECToUserMsg: true,
|
|
511
|
+
message: `find ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
512
|
+
userMessage: this.defaultErrorUserMsg,
|
|
513
|
+
error
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
if (0 < dataList.length) {
|
|
517
|
+
dataList.forEach((data) => {
|
|
518
|
+
if (data && typeof data._id === 'object') {
|
|
519
|
+
data._id = `${data._id}`;
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
return dataList;
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* #MONGOOSE FUNCTION
|
|
528
|
+
* Find the data first by any of its parameters
|
|
529
|
+
*
|
|
530
|
+
* @param filterBy if you can, use unique parameters for find!
|
|
531
|
+
*
|
|
532
|
+
* @example
|
|
533
|
+
* // by email:
|
|
534
|
+
* { email: email }
|
|
535
|
+
* //
|
|
536
|
+
* @example
|
|
537
|
+
* // or by id that is in list:
|
|
538
|
+
* { userIds: { $in: this.userId } }
|
|
539
|
+
* //
|
|
540
|
+
* @example
|
|
541
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
542
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
543
|
+
* // further tools (syntax matches with $gt):
|
|
544
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
545
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
546
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
547
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
548
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
549
|
+
* //
|
|
550
|
+
* @param page page
|
|
551
|
+
* @param pageSize pageSize
|
|
552
|
+
* @param sort
|
|
553
|
+
* @example
|
|
554
|
+
* // by dateTime (this uses the basic sort function):
|
|
555
|
+
* { dateTime: -1 }
|
|
556
|
+
* //
|
|
557
|
+
* @returns {T[]} dataList: T[]
|
|
558
|
+
*/
|
|
559
|
+
findWithPaging(filterBy, page, pageSize, sort) {
|
|
560
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
561
|
+
let dataList = yield this.dataModel.find(filterBy)
|
|
562
|
+
.sort(sort)
|
|
563
|
+
.skip(page * pageSize)
|
|
564
|
+
.limit(pageSize)
|
|
565
|
+
.then(res => res !== null && res !== void 0 ? res : [])
|
|
566
|
+
.catch(error => {
|
|
567
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
568
|
+
status: 417,
|
|
569
|
+
errorCode: 'NTS-DBS-WP0',
|
|
570
|
+
addECToUserMsg: true,
|
|
571
|
+
message: `findWithPaging ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
572
|
+
userMessage: this.defaultErrorUserMsg,
|
|
573
|
+
error
|
|
574
|
+
});
|
|
575
|
+
});
|
|
576
|
+
if (0 < dataList.length) {
|
|
577
|
+
dataList.forEach((data) => {
|
|
578
|
+
if (data && typeof data._id === 'object') {
|
|
579
|
+
data._id = `${data._id}`;
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
return dataList;
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* #MONGOOSE FUNCTION
|
|
588
|
+
* Find data by _id and update
|
|
589
|
+
* !!!: throws error if not found (errorCode on not found: )
|
|
590
|
+
*
|
|
591
|
+
* @param id id
|
|
592
|
+
* @param update update
|
|
593
|
+
* @returns data
|
|
594
|
+
*/
|
|
595
|
+
findByIdAndUpdate(id, update, modifier) {
|
|
596
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
597
|
+
update.__lastModified = new Date();
|
|
598
|
+
update.__lastModifiedBy = modifier;
|
|
599
|
+
let newData = yield this.dataModel.findByIdAndUpdate(id, update).then(res => {
|
|
600
|
+
var _a;
|
|
601
|
+
return (_a = res === null || res === void 0 ? void 0 : res.toObject()) !== null && _a !== void 0 ? _a : null;
|
|
602
|
+
}).catch(error => {
|
|
603
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
604
|
+
status: 417,
|
|
605
|
+
errorCode: 'NTS-DBS-FIU0',
|
|
606
|
+
addECToUserMsg: true,
|
|
607
|
+
message: `findByIdAndUpdate ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
608
|
+
userMessage: this.defaultErrorUserMsg,
|
|
609
|
+
error
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
if (typeof newData._id === 'object') {
|
|
613
|
+
newData._id = `${newData._id}`;
|
|
614
|
+
}
|
|
615
|
+
return newData;
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* #MONGOOSE FUNCTION
|
|
620
|
+
* Find the data first by any of its parameters
|
|
621
|
+
*
|
|
622
|
+
* @param filter This uses the basic Mongoose updateOne.
|
|
623
|
+
* If you can, use unique parameters for find!
|
|
624
|
+
* @example
|
|
625
|
+
* // by email:
|
|
626
|
+
* { email: email }
|
|
627
|
+
* //
|
|
628
|
+
* @example
|
|
629
|
+
* // or by id that is in list:
|
|
630
|
+
* { userIds: { $in: this.userId } }
|
|
631
|
+
* //
|
|
632
|
+
* @example
|
|
633
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
634
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
635
|
+
* // further tools (syntax matches with $gt):
|
|
636
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
637
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
638
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
639
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
640
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
641
|
+
* //
|
|
642
|
+
*
|
|
643
|
+
* @param update this uses the basic Mongoose updateOne
|
|
644
|
+
* @example
|
|
645
|
+
* // increase a specific value (here by 15):
|
|
646
|
+
* { $inc: { popularity: 15 } }
|
|
647
|
+
* //
|
|
648
|
+
* @example
|
|
649
|
+
* // or add element to a list:
|
|
650
|
+
* { $push: { reactions: this.newReaction }
|
|
651
|
+
* // or add multiple elements to a list
|
|
652
|
+
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
653
|
+
* //
|
|
654
|
+
* @example
|
|
655
|
+
* // or all at once
|
|
656
|
+
* {
|
|
657
|
+
* $inc: { popularity: this.newVote.amount },
|
|
658
|
+
* emailVerified: true,
|
|
659
|
+
* $push: { reactions: this.newReaction }
|
|
660
|
+
* }
|
|
661
|
+
* // further tools (syntax matches with $inc):
|
|
662
|
+
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
663
|
+
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
664
|
+
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
665
|
+
* $mul: // Multiplies the value of the field by the specified amount.
|
|
666
|
+
* $rename: // Renames a field.
|
|
667
|
+
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
668
|
+
* //
|
|
669
|
+
*/
|
|
670
|
+
updateOne(filterBy, update, issuer) {
|
|
671
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
672
|
+
update.__lastModified = new Date();
|
|
673
|
+
update.__lastModifiedBy = issuer;
|
|
674
|
+
yield this.dataModel.updateOne(filterBy, update).catch(error => {
|
|
675
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
676
|
+
status: 417,
|
|
677
|
+
errorCode: 'NTS-DBS-UO0',
|
|
678
|
+
addECToUserMsg: true,
|
|
679
|
+
message: `updateOne ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
680
|
+
userMessage: this.defaultErrorUserMsg,
|
|
681
|
+
error
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* #MONGOOSE FUNCTION
|
|
688
|
+
* update one parameter by a specific
|
|
689
|
+
*
|
|
690
|
+
* @param filter This uses the basic Mongoose updateMany.
|
|
691
|
+
* @example
|
|
692
|
+
* // by email:
|
|
693
|
+
* { email: email }
|
|
694
|
+
* //
|
|
695
|
+
* @example
|
|
696
|
+
* // or by id that is in list:
|
|
697
|
+
* { userIds: { $in: this.userId } }
|
|
698
|
+
* //
|
|
699
|
+
* @example
|
|
700
|
+
* // or by number or Date that is Greater Than AND Less Than:
|
|
701
|
+
* { points: { $gt: 2, $lt: 14 } }
|
|
702
|
+
* // further tools (syntax matches with $gt):
|
|
703
|
+
* $eq: // Matches values that are EQual to a specified value.
|
|
704
|
+
* $gte: // Matches values that are Greater Than OR Equal to a specified value.
|
|
705
|
+
* $lte: // Matches values that are Less Than or Equal to a specified value.
|
|
706
|
+
* $ne: // Matches all values that are Not Equal to a specified value.
|
|
707
|
+
* $nin: // Matches None of the values specified IN an array.
|
|
708
|
+
* //
|
|
709
|
+
*
|
|
710
|
+
* @param update this uses the basic Mongoose updateOne
|
|
711
|
+
* @example
|
|
712
|
+
* // increase a specific value (here by 15):
|
|
713
|
+
* { $inc: { popularity: 15 } }
|
|
714
|
+
* //
|
|
715
|
+
* @example
|
|
716
|
+
* // or add element to a list:
|
|
717
|
+
* { $push: { reactions: this.newReaction }
|
|
718
|
+
* // or add multiple elements to a list
|
|
719
|
+
* { $push: { schedule: {$each: [ monday, tuesday, wednesday ] } } }
|
|
720
|
+
* //
|
|
721
|
+
* @example
|
|
722
|
+
* // or all at once
|
|
723
|
+
* {
|
|
724
|
+
* $inc: { popularity: this.newVote.amount },
|
|
725
|
+
* emailVerified: true,
|
|
726
|
+
* $push: { reactions: this.newReaction }
|
|
727
|
+
* }
|
|
728
|
+
* // further tools (syntax matches with $inc):
|
|
729
|
+
* $currentDate: // Sets the value of a field to current date, either as a Date or a Timestamp.
|
|
730
|
+
* $min: // Only updates the field if the specified value is less than the existing field value.
|
|
731
|
+
* $max: // Only updates the field if the specified value is greater than the existing field value.
|
|
732
|
+
* $mul: // Multiplies the value of the field by the specified amount.
|
|
733
|
+
* $rename: // Renames a field.
|
|
734
|
+
* $unset: // Removes the specified field from a document. (set: "" to value)
|
|
735
|
+
* //
|
|
736
|
+
*/
|
|
737
|
+
updateMany(filterBy, update, issuer) {
|
|
738
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
739
|
+
update.__lastModified = new Date();
|
|
740
|
+
update.__lastModifiedBy = issuer;
|
|
741
|
+
yield this.dataModel.updateMany(filterBy, update).catch(error => {
|
|
742
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
743
|
+
status: 417,
|
|
744
|
+
errorCode: 'NTS-DBS-UM0',
|
|
745
|
+
addECToUserMsg: true,
|
|
746
|
+
message: `updateMany ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
747
|
+
userMessage: this.defaultErrorUserMsg,
|
|
748
|
+
error
|
|
749
|
+
});
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
// ----------------------------------------------------------------------------------
|
|
754
|
+
// ----------------------------------------------------------------------------------
|
|
755
|
+
// ----------------------------------------------------------------------------------
|
|
756
|
+
// PRIVATE BUILD FUNCTIONS
|
|
757
|
+
/**
|
|
758
|
+
* builds and returns mongoose schema
|
|
759
|
+
* @returns schema
|
|
760
|
+
*/
|
|
761
|
+
getSchema() {
|
|
762
|
+
let schema = this.buildMongooseSchemaByModelParams();
|
|
763
|
+
schema = this.addDynamo_MetadataToSchema(schema);
|
|
764
|
+
// tslint:disable-next-line: no-string-literal
|
|
765
|
+
if (schema['_id']) {
|
|
766
|
+
// tslint:disable-next-line: no-string-literal
|
|
767
|
+
delete schema['_id'];
|
|
768
|
+
}
|
|
769
|
+
return new mongoose_1.Schema(schema);
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* builds mongoose schema building settings object by dynamoDataModelParamsList
|
|
773
|
+
* @param params DynamoBEDataPropertyParams
|
|
774
|
+
* @returns mongoose schema object
|
|
775
|
+
*/
|
|
776
|
+
buildMongooseSchemaByModelParams(params) {
|
|
777
|
+
const schemaSettingsObj = {};
|
|
778
|
+
if (!params) {
|
|
779
|
+
params = this.dataParams.modelParams;
|
|
780
|
+
}
|
|
781
|
+
params.forEach((property) => {
|
|
782
|
+
var _a;
|
|
783
|
+
const beType = this.getBEType(property.type);
|
|
784
|
+
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) {
|
|
785
|
+
schemaSettingsObj[property.key] = {
|
|
786
|
+
type: beType
|
|
787
|
+
};
|
|
788
|
+
if (property.index) {
|
|
789
|
+
schemaSettingsObj[property.key].index = true;
|
|
790
|
+
}
|
|
791
|
+
if (property.unique) {
|
|
792
|
+
schemaSettingsObj[property.key].unique = true;
|
|
793
|
+
}
|
|
794
|
+
if (property.required) {
|
|
795
|
+
schemaSettingsObj[property.key].required = true;
|
|
796
|
+
}
|
|
797
|
+
if (property.minlength) {
|
|
798
|
+
schemaSettingsObj[property.key].minlength = property.minlength;
|
|
799
|
+
}
|
|
800
|
+
if (property.maxlength) {
|
|
801
|
+
schemaSettingsObj[property.key].maxlength = property.maxlength;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
else {
|
|
805
|
+
schemaSettingsObj[property.key] = this.buildMongooseSchemaByModelParams(property.subObjectParams);
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
return schemaSettingsObj;
|
|
809
|
+
}
|
|
810
|
+
getBEType(type) {
|
|
811
|
+
switch (type) {
|
|
812
|
+
case 'string':
|
|
813
|
+
return String;
|
|
814
|
+
case 'number':
|
|
815
|
+
return Number;
|
|
816
|
+
case 'boolean':
|
|
817
|
+
return Boolean;
|
|
818
|
+
case 'Date':
|
|
819
|
+
return Date;
|
|
820
|
+
case 'object':
|
|
821
|
+
return Object;
|
|
822
|
+
default:
|
|
823
|
+
if (type.includes('[]')) {
|
|
824
|
+
return Array;
|
|
825
|
+
}
|
|
826
|
+
else if (type.includes('=>') || type.includes('function')) {
|
|
827
|
+
return Function;
|
|
828
|
+
}
|
|
829
|
+
else {
|
|
830
|
+
return Object;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* adds dynamo metadata settings to any mongoose schema building settings object
|
|
836
|
+
* @param schema schema to update
|
|
837
|
+
* @returns updated schema
|
|
838
|
+
*/
|
|
839
|
+
addDynamo_MetadataToSchema(schema) {
|
|
840
|
+
schema.__created = { type: Date };
|
|
841
|
+
schema.__createdBy = { type: String };
|
|
842
|
+
schema.__lastModified = { type: Date };
|
|
843
|
+
schema.__lastModifiedBy = { type: String };
|
|
844
|
+
return schema;
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* sets depDataKey
|
|
848
|
+
*/
|
|
849
|
+
lookForDependencyDataSettings() {
|
|
850
|
+
const dependencyParam = this.dataParams.modelParams.find((modelParams) => modelParams.isDependencyHook);
|
|
851
|
+
if (dependencyParam) {
|
|
852
|
+
this.depDataName = dependencyParam.key;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
exports.DynamoNTS_DBService = DynamoNTS_DBService;
|
|
857
857
|
//# sourceMappingURL=dynamo-nts-db.service.js.map
|