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