@futdevpro/nts-dynamo 1.6.54 → 1.6.55
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/control-models/endpoint-params.control-model.js +6 -6
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +16 -59
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/core/email.service.d.ts +2 -1
- package/lib/_services/core/email.service.d.ts.map +1 -1
- package/lib/_services/core/email.service.js +24 -31
- package/lib/_services/core/email.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +1 -1
- package/src/_services/base/data.service.ts +1 -1
- package/src/_services/base/db.service.ts +32 -67
- package/src/_services/core/email.service.ts +59 -31
|
@@ -698,7 +698,7 @@ export class DynamoNTS_DataService<T extends Dynamo_Metadata> {
|
|
|
698
698
|
}
|
|
699
699
|
}
|
|
700
700
|
|
|
701
|
-
private _getDefaultErrorSettings(fnName: string, error
|
|
701
|
+
private _getDefaultErrorSettings(fnName: string, error: Error | Dynamo_Error) {
|
|
702
702
|
return {
|
|
703
703
|
status: (error as Dynamo_Error)?.___status ?? 500,
|
|
704
704
|
message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS; ${this.dataParams.dataName})`,
|
|
@@ -100,7 +100,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
-
data = this.stringifyDataId(
|
|
103
|
+
data = this.stringifyDataId(newData, 'createData');
|
|
104
104
|
|
|
105
105
|
return data;
|
|
106
106
|
}
|
|
@@ -141,14 +141,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
141
141
|
});
|
|
142
142
|
});
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
newData._id = `${newData._id}`;
|
|
146
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
147
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.modifyData)')
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
data._id = newData._id;
|
|
151
|
-
data.__v = newData.__v;
|
|
144
|
+
data = this.stringifyDataId(newData, 'modifyData');
|
|
152
145
|
|
|
153
146
|
return data;
|
|
154
147
|
}
|
|
@@ -159,6 +152,15 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
159
152
|
* @returns data
|
|
160
153
|
*/
|
|
161
154
|
async getDataById(id: string): Promise<T> {
|
|
155
|
+
if (!id) {
|
|
156
|
+
throw new Dynamo_Error({
|
|
157
|
+
...this._getDefaultErrorSettings('getDataById', new Error(`No ID provided! (NTS DB)`)),
|
|
158
|
+
|
|
159
|
+
errorCode: 'NTS-DBS-GI1',
|
|
160
|
+
message: `get ${this.dataParams.dbName} by ID was unsuccessful (NTS DB)`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
162
164
|
let data: T = await this.dataModel.findById(id).then(res => {
|
|
163
165
|
return res?.toObject() as T ?? null;
|
|
164
166
|
}).catch(error => {
|
|
@@ -170,12 +172,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
170
172
|
});
|
|
171
173
|
});
|
|
172
174
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
176
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataById)')
|
|
177
|
-
}
|
|
178
|
-
}
|
|
175
|
+
data = this.stringifyDataId(data, 'getDataById');
|
|
176
|
+
|
|
179
177
|
return data;
|
|
180
178
|
}
|
|
181
179
|
|
|
@@ -210,12 +208,8 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
210
208
|
});
|
|
211
209
|
});
|
|
212
210
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
216
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataByDependencyId)')
|
|
217
|
-
}
|
|
218
|
-
}
|
|
211
|
+
data = this.stringifyDataId(data, 'getDataByDependencyId');
|
|
212
|
+
|
|
219
213
|
return data;
|
|
220
214
|
}
|
|
221
215
|
|
|
@@ -252,12 +246,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
252
246
|
|
|
253
247
|
if (0 < dataList.length) {
|
|
254
248
|
dataList.forEach((data: T) => {
|
|
255
|
-
|
|
256
|
-
data._id = `${data._id}`;
|
|
257
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
258
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataListByDependencyId)')
|
|
259
|
-
}
|
|
260
|
-
}
|
|
249
|
+
data = this.stringifyDataId(data, 'getDataListByDependencyId');
|
|
261
250
|
});
|
|
262
251
|
}
|
|
263
252
|
|
|
@@ -297,12 +286,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
297
286
|
|
|
298
287
|
if (0 < dataList.length) {
|
|
299
288
|
dataList.forEach((data: T) => {
|
|
300
|
-
|
|
301
|
-
data._id = `${data._id}`;
|
|
302
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
303
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.getDataListByDependencyIds)')
|
|
304
|
-
}
|
|
305
|
-
}
|
|
289
|
+
data = this.stringifyDataId(data, 'getDataListByDependencyIds');
|
|
306
290
|
});
|
|
307
291
|
}
|
|
308
292
|
|
|
@@ -453,25 +437,21 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
453
437
|
}
|
|
454
438
|
});
|
|
455
439
|
|
|
456
|
-
let dataList: T[] = await this.dataModel
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
440
|
+
let dataList: T[] = await this.dataModel
|
|
441
|
+
.find(filter)
|
|
442
|
+
.then(res => res ?? [])
|
|
443
|
+
.catch(error => {
|
|
444
|
+
throw new Dynamo_Error({
|
|
445
|
+
...this._getDefaultErrorSettings('searchData', error),
|
|
446
|
+
|
|
447
|
+
errorCode: 'NTS-DBS-SD1',
|
|
448
|
+
message: `search ${this.dataParams.dbName} was unsuccessful (NTS DB)`,
|
|
449
|
+
});
|
|
464
450
|
});
|
|
465
|
-
});
|
|
466
451
|
|
|
467
452
|
if (0 < dataList.length) {
|
|
468
453
|
dataList.forEach((data: T) => {
|
|
469
|
-
|
|
470
|
-
data._id = `${data._id}`;
|
|
471
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
472
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.searchData)')
|
|
473
|
-
}
|
|
474
|
-
}
|
|
454
|
+
data = this.stringifyDataId(data, 'searchData');
|
|
475
455
|
});
|
|
476
456
|
}
|
|
477
457
|
|
|
@@ -568,12 +548,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
568
548
|
|
|
569
549
|
if (0 < dataList.length) {
|
|
570
550
|
dataList.forEach((data: T) => {
|
|
571
|
-
|
|
572
|
-
data._id = `${data._id}`;
|
|
573
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
574
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.find)')
|
|
575
|
-
}
|
|
576
|
-
}
|
|
551
|
+
data = this.stringifyDataId(data, 'find');
|
|
577
552
|
});
|
|
578
553
|
}
|
|
579
554
|
|
|
@@ -630,12 +605,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
630
605
|
|
|
631
606
|
if (0 < dataList.length) {
|
|
632
607
|
dataList.forEach((data: T) => {
|
|
633
|
-
|
|
634
|
-
data._id = `${data._id}`;
|
|
635
|
-
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
636
|
-
Dynamo_Log.error('data._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findWithPaging)')
|
|
637
|
-
}
|
|
638
|
-
}
|
|
608
|
+
data = this.stringifyDataId(data, 'findWithPaging');
|
|
639
609
|
});
|
|
640
610
|
}
|
|
641
611
|
|
|
@@ -667,12 +637,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
667
637
|
});
|
|
668
638
|
});
|
|
669
639
|
|
|
670
|
-
|
|
671
|
-
newData._id = `${newData._id}`;
|
|
672
|
-
if (typeof newData._id !== 'string' || typeof newData._id === 'object') {
|
|
673
|
-
Dynamo_Log.error('newData._id stringifying failed! Please notfiy the developer! (DynamoNTS_DBService.findByIdAndUpdate)')
|
|
674
|
-
}
|
|
675
|
-
}
|
|
640
|
+
newData = this.stringifyDataId(newData, 'findByIdAndUpdate');
|
|
676
641
|
|
|
677
642
|
return newData;
|
|
678
643
|
}
|
|
@@ -816,7 +781,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
|
|
|
816
781
|
// PRIVATE FUNCTIONS
|
|
817
782
|
|
|
818
783
|
private stringifyDataId(data: T, fnName: string): T {
|
|
819
|
-
if (data && (typeof data._id !== 'string' || typeof data._id === 'object')) {
|
|
784
|
+
if (data?._id && (typeof data._id !== 'string' || typeof data._id === 'object')) {
|
|
820
785
|
data._id = `${data._id}`;
|
|
821
786
|
|
|
822
787
|
if (typeof data._id !== 'string' || typeof data._id === 'object') {
|
|
@@ -41,7 +41,7 @@ export class DynamoNTS_EmailService {
|
|
|
41
41
|
}
|
|
42
42
|
) {
|
|
43
43
|
try {
|
|
44
|
-
|
|
44
|
+
this.serviceName = this.constructor?.name;
|
|
45
45
|
// console.log('\n\n\n\n\nNEW CONSTRUCT STARTED', set.email);
|
|
46
46
|
this.senderName = set.senderName;
|
|
47
47
|
this.senderNEmail = `${set.senderName} <${set.email}>`;
|
|
@@ -77,16 +77,19 @@ export class DynamoNTS_EmailService {
|
|
|
77
77
|
*
|
|
78
78
|
* @param set
|
|
79
79
|
*/
|
|
80
|
-
public async sendEmail(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
80
|
+
public async sendEmail(
|
|
81
|
+
set: {
|
|
82
|
+
to: string,
|
|
83
|
+
subject: string,
|
|
84
|
+
content?: string,
|
|
85
|
+
useTemplate?: string,
|
|
86
|
+
templateProperties?: {
|
|
87
|
+
[propertyKey: string]: string
|
|
88
|
+
},
|
|
89
|
+
attachments?: Attachment[]
|
|
90
|
+
},
|
|
91
|
+
issuer?: string,
|
|
92
|
+
): Promise<void> {
|
|
90
93
|
try {
|
|
91
94
|
let content: string;
|
|
92
95
|
|
|
@@ -95,21 +98,25 @@ export class DynamoNTS_EmailService {
|
|
|
95
98
|
} else {
|
|
96
99
|
if (!set.useTemplate) {
|
|
97
100
|
throw new Dynamo_Error({
|
|
101
|
+
...this._getDefaultErrorSettings(
|
|
102
|
+
'sendEmail',
|
|
103
|
+
new Error(`No content setting passsed to emailSending!`),
|
|
104
|
+
issuer
|
|
105
|
+
),
|
|
106
|
+
|
|
98
107
|
errorCode: 'NTS-ES4-101',
|
|
99
|
-
addECToUserMsg: true,
|
|
100
|
-
message: 'No content setting passsed to emailSending!',
|
|
101
|
-
userMessage: this.defaultErrorUserMsg,
|
|
102
|
-
issuerService: this.serviceName,
|
|
103
108
|
});
|
|
104
109
|
}
|
|
105
110
|
|
|
106
111
|
if (!this.templates[set.useTemplate]) {
|
|
107
112
|
throw new Dynamo_Error({
|
|
113
|
+
...this._getDefaultErrorSettings(
|
|
114
|
+
'sendEmail',
|
|
115
|
+
new Error(`No email template found with this parameter! (${set.useTemplate})`),
|
|
116
|
+
issuer
|
|
117
|
+
),
|
|
118
|
+
|
|
108
119
|
errorCode: 'NTS-ES4-102',
|
|
109
|
-
addECToUserMsg: true,
|
|
110
|
-
message: `No email template found with this parameter! (${set.useTemplate})`,
|
|
111
|
-
userMessage: this.defaultErrorUserMsg,
|
|
112
|
-
issuerService: this.serviceName,
|
|
113
120
|
});
|
|
114
121
|
}
|
|
115
122
|
|
|
@@ -124,11 +131,13 @@ export class DynamoNTS_EmailService {
|
|
|
124
131
|
Dynamo_Log.error('\nDynamoBEEmailService ERROR: INVALID sendEmail settings', set);
|
|
125
132
|
|
|
126
133
|
throw new Dynamo_Error({
|
|
134
|
+
...this._getDefaultErrorSettings(
|
|
135
|
+
'sendEmail',
|
|
136
|
+
new Error(`TemplateProperties missing! properties needed: ${props}`),
|
|
137
|
+
issuer
|
|
138
|
+
),
|
|
139
|
+
|
|
127
140
|
errorCode: 'NTS-ES4-103',
|
|
128
|
-
addECToUserMsg: true,
|
|
129
|
-
message: `TemplateProperties missing! properties needed: ${props}`,
|
|
130
|
-
userMessage: this.defaultErrorUserMsg,
|
|
131
|
-
issuerService: this.serviceName,
|
|
132
141
|
});
|
|
133
142
|
}
|
|
134
143
|
this.templatePropertyKeys[set.useTemplate].forEach((propertyKey: string) => {
|
|
@@ -159,14 +168,21 @@ export class DynamoNTS_EmailService {
|
|
|
159
168
|
});
|
|
160
169
|
});
|
|
161
170
|
} catch (error) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
171
|
+
if (error.includes('all recipients were rejected')) {
|
|
172
|
+
throw new Dynamo_Error({
|
|
173
|
+
...this._getDefaultErrorSettings('sendEmail', error, issuer),
|
|
174
|
+
|
|
175
|
+
errorCode: 'NTS-ES4-104',
|
|
176
|
+
userMessage: `Can't send mail to ${set.to}`,
|
|
177
|
+
})
|
|
178
|
+
} else {
|
|
179
|
+
throw new Dynamo_Error({
|
|
180
|
+
...this._getDefaultErrorSettings('sendEmail', error, issuer),
|
|
181
|
+
|
|
182
|
+
errorCode: 'NTS-ES4-100',
|
|
183
|
+
message: `SendEmail failed!`,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
170
186
|
}
|
|
171
187
|
}
|
|
172
188
|
|
|
@@ -240,4 +256,16 @@ export class DynamoNTS_EmailService {
|
|
|
240
256
|
Dynamo_Log.error(`\nDynamoBEEmailService ERROR, getTemplatePropertyKeys ERROR`, new Error(), '\ntemplate:\n', template);
|
|
241
257
|
}
|
|
242
258
|
}
|
|
259
|
+
|
|
260
|
+
private _getDefaultErrorSettings(fnName: string, error: Error | Dynamo_Error, issuer: string) {
|
|
261
|
+
return {
|
|
262
|
+
status: (error as Dynamo_Error)?.___status ?? 500,
|
|
263
|
+
message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS; ${this.serviceName})`,
|
|
264
|
+
addECToUserMsg: true,
|
|
265
|
+
userMessage: this.defaultErrorUserMsg,
|
|
266
|
+
issuer: issuer,
|
|
267
|
+
issuerService: this.serviceName,
|
|
268
|
+
error: error,
|
|
269
|
+
}
|
|
270
|
+
}
|
|
243
271
|
}
|