@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.
Files changed (167) hide show
  1. package/lib/_models/dynamo-nts-endpoint-params.js +3 -2
  2. package/lib/_models/dynamo-nts-endpoint-params.js.map +1 -1
  3. package/lib/_services/dynamo-nts-api.service.d.ts +1 -0
  4. package/lib/_services/dynamo-nts-api.service.d.ts.map +1 -1
  5. package/lib/_services/dynamo-nts-api.service.js +6 -5
  6. package/lib/_services/dynamo-nts-api.service.js.map +1 -1
  7. package/lib/_services/dynamo-nts-app-extended.d.ts +87 -7
  8. package/lib/_services/dynamo-nts-app-extended.d.ts.map +1 -1
  9. package/lib/_services/dynamo-nts-app-extended.js +87 -7
  10. package/lib/_services/dynamo-nts-app-extended.js.map +1 -1
  11. package/lib/_services/dynamo-nts-app.d.ts +131 -22
  12. package/lib/_services/dynamo-nts-app.d.ts.map +1 -1
  13. package/lib/_services/dynamo-nts-app.js +104 -1
  14. package/lib/_services/dynamo-nts-app.js.map +1 -1
  15. package/lib/_services/dynamo-nts-auth.service.d.ts +79 -5
  16. package/lib/_services/dynamo-nts-auth.service.d.ts.map +1 -1
  17. package/lib/_services/dynamo-nts-auth.service.js +3 -2
  18. package/lib/_services/dynamo-nts-auth.service.js.map +1 -1
  19. package/lib/_services/dynamo-nts-data.service.d.ts +25 -1
  20. package/lib/_services/dynamo-nts-data.service.d.ts.map +1 -1
  21. package/lib/_services/dynamo-nts-data.service.js +98 -70
  22. package/lib/_services/dynamo-nts-data.service.js.map +1 -1
  23. package/lib/_services/dynamo-nts-db.service.d.ts +165 -119
  24. package/lib/_services/dynamo-nts-db.service.d.ts.map +1 -1
  25. package/lib/_services/dynamo-nts-db.service.js +348 -293
  26. package/lib/_services/dynamo-nts-db.service.js.map +1 -1
  27. package/lib/_services/dynamo-nts-email.service.d.ts +1 -0
  28. package/lib/_services/dynamo-nts-email.service.d.ts.map +1 -1
  29. package/lib/_services/dynamo-nts-email.service.js +5 -4
  30. package/lib/_services/dynamo-nts-email.service.js.map +1 -1
  31. package/lib/_services/dynamo-nts-routing-module.service.d.ts +40 -0
  32. package/lib/_services/dynamo-nts-routing-module.service.d.ts.map +1 -1
  33. package/lib/_services/dynamo-nts-routing-module.service.js +43 -3
  34. package/lib/_services/dynamo-nts-routing-module.service.js.map +1 -1
  35. package/lib/_services/dynamo-nts-socket.service.d.ts +1 -0
  36. package/lib/_services/dynamo-nts-socket.service.d.ts.map +1 -1
  37. package/lib/_services/dynamo-nts-socket.service.js +6 -2
  38. package/lib/_services/dynamo-nts-socket.service.js.map +1 -1
  39. package/lib/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +16 -12
  41. package/src/_models/dynamo-nts-endpoint-params.ts +2 -2
  42. package/src/_services/dynamo-nts-api.service.ts +7 -5
  43. package/src/_services/dynamo-nts-app-extended.ts +87 -7
  44. package/src/_services/dynamo-nts-app.ts +131 -22
  45. package/src/_services/dynamo-nts-auth.service.ts +83 -7
  46. package/src/_services/dynamo-nts-data.service.ts +100 -71
  47. package/src/_services/dynamo-nts-db.service.ts +377 -297
  48. package/src/_services/dynamo-nts-email.service.ts +6 -4
  49. package/src/_services/dynamo-nts-routing-module.service.ts +44 -3
  50. package/src/_services/dynamo-nts-socket.service.ts +13 -7
  51. package/futdevpro-nts-dynamo-01.05.40.tgz +0 -0
  52. package/futdevpro-nts-dynamo-01.05.41.tgz +0 -0
  53. package/futdevpro-nts-dynamo-01.05.42.tgz +0 -0
  54. package/futdevpro-nts-dynamo-01.05.43.tgz +0 -0
  55. package/futdevpro-nts-dynamo-01.05.44.tgz +0 -0
  56. package/futdevpro-nts-dynamo-01.05.45.tgz +0 -0
  57. package/futdevpro-nts-dynamo-01.05.47.tgz +0 -0
  58. package/futdevpro-nts-dynamo-01.05.49.tgz +0 -0
  59. package/futdevpro-nts-dynamo-01.05.50.tgz +0 -0
  60. package/lib/_constants/dynamo-nts-global.settings.d.ts +0 -3
  61. package/lib/_constants/dynamo-nts-global.settings.d.ts.map +0 -1
  62. package/lib/_constants/dynamo-nts-global.settings.js +0 -18
  63. package/lib/_constants/dynamo-nts-global.settings.js.map +0 -1
  64. package/lib/_constants/dynamobe-global.settings.d.ts +0 -3
  65. package/lib/_constants/dynamobe-global.settings.d.ts.map +0 -1
  66. package/lib/_constants/dynamobe-global.settings.js +0 -13
  67. package/lib/_constants/dynamobe-global.settings.js.map +0 -1
  68. package/lib/_enums/dynamobe-data-service-function.enum.d.ts +0 -8
  69. package/lib/_enums/dynamobe-data-service-function.enum.d.ts.map +0 -1
  70. package/lib/_enums/dynamobe-data-service-function.enum.js +0 -15
  71. package/lib/_enums/dynamobe-data-service-function.enum.js.map +0 -1
  72. package/lib/_enums/dynamobe-route-security.enum.d.ts +0 -6
  73. package/lib/_enums/dynamobe-route-security.enum.d.ts.map +0 -1
  74. package/lib/_enums/dynamobe-route-security.enum.js +0 -10
  75. package/lib/_enums/dynamobe-route-security.enum.js.map +0 -1
  76. package/lib/_enums/log-style.enum.d.ts +0 -26
  77. package/lib/_enums/log-style.enum.d.ts.map +0 -1
  78. package/lib/_enums/log-style.enum.js +0 -30
  79. package/lib/_enums/log-style.enum.js.map +0 -1
  80. package/lib/_models/dynamo-module-settings.d.ts +0 -4
  81. package/lib/_models/dynamo-module-settings.d.ts.map +0 -1
  82. package/lib/_models/dynamo-module-settings.js +0 -10
  83. package/lib/_models/dynamo-module-settings.js.map +0 -1
  84. package/lib/_models/dynamo-nts-socket-module-settings.d.ts +0 -19
  85. package/lib/_models/dynamo-nts-socket-module-settings.d.ts.map +0 -1
  86. package/lib/_models/dynamo-nts-socket-module-settings.js +0 -27
  87. package/lib/_models/dynamo-nts-socket-module-settings.js.map +0 -1
  88. package/lib/_models/dynamobe-api-call-params.d.ts +0 -37
  89. package/lib/_models/dynamobe-api-call-params.d.ts.map +0 -1
  90. package/lib/_models/dynamobe-api-call-params.js +0 -29
  91. package/lib/_models/dynamobe-api-call-params.js.map +0 -1
  92. package/lib/_models/dynamobe-app-params.d.ts +0 -18
  93. package/lib/_models/dynamobe-app-params.d.ts.map +0 -1
  94. package/lib/_models/dynamobe-app-params.js +0 -17
  95. package/lib/_models/dynamobe-app-params.js.map +0 -1
  96. package/lib/_models/dynamobe-data-model-params.d.ts +0 -1
  97. package/lib/_models/dynamobe-data-model-params.d.ts.map +0 -1
  98. package/lib/_models/dynamobe-data-model-params.js +0 -25
  99. package/lib/_models/dynamobe-data-model-params.js.map +0 -1
  100. package/lib/_models/dynamobe-endpoint-params.d.ts +0 -46
  101. package/lib/_models/dynamobe-endpoint-params.d.ts.map +0 -1
  102. package/lib/_models/dynamobe-endpoint-params.js +0 -117
  103. package/lib/_models/dynamobe-endpoint-params.js.map +0 -1
  104. package/lib/_models/dynamobe-global-settings.d.ts +0 -13
  105. package/lib/_models/dynamobe-global-settings.d.ts.map +0 -1
  106. package/lib/_models/dynamobe-global-settings.js +0 -3
  107. package/lib/_models/dynamobe-global-settings.js.map +0 -1
  108. package/lib/_modules/data-models.index.d.ts +0 -3
  109. package/lib/_modules/data-models.index.d.ts.map +0 -1
  110. package/lib/_modules/data-models.index.js +0 -6
  111. package/lib/_modules/data-models.index.js.map +0 -1
  112. package/lib/_services/dynamobe-api.service.d.ts +0 -19
  113. package/lib/_services/dynamobe-api.service.d.ts.map +0 -1
  114. package/lib/_services/dynamobe-api.service.js +0 -167
  115. package/lib/_services/dynamobe-api.service.js.map +0 -1
  116. package/lib/_services/dynamobe-app.d.ts +0 -129
  117. package/lib/_services/dynamobe-app.d.ts.map +0 -1
  118. package/lib/_services/dynamobe-app.js +0 -238
  119. package/lib/_services/dynamobe-app.js.map +0 -1
  120. package/lib/_services/dynamobe-auth.service.d.ts +0 -54
  121. package/lib/_services/dynamobe-auth.service.d.ts.map +0 -1
  122. package/lib/_services/dynamobe-auth.service.js +0 -46
  123. package/lib/_services/dynamobe-auth.service.js.map +0 -1
  124. package/lib/_services/dynamobe-controller.service.d.ts +0 -14
  125. package/lib/_services/dynamobe-controller.service.d.ts.map +0 -1
  126. package/lib/_services/dynamobe-controller.service.js +0 -21
  127. package/lib/_services/dynamobe-controller.service.js.map +0 -1
  128. package/lib/_services/dynamobe-data.service.d.ts +0 -54
  129. package/lib/_services/dynamobe-data.service.d.ts.map +0 -1
  130. package/lib/_services/dynamobe-data.service.js +0 -301
  131. package/lib/_services/dynamobe-data.service.js.map +0 -1
  132. package/lib/_services/dynamobe-db-service-collection.service.d.ts +0 -9
  133. package/lib/_services/dynamobe-db-service-collection.service.d.ts.map +0 -1
  134. package/lib/_services/dynamobe-db-service-collection.service.js +0 -11
  135. package/lib/_services/dynamobe-db-service-collection.service.js.map +0 -1
  136. package/lib/_services/dynamobe-db.service.d.ts +0 -244
  137. package/lib/_services/dynamobe-db.service.d.ts.map +0 -1
  138. package/lib/_services/dynamobe-db.service.js +0 -759
  139. package/lib/_services/dynamobe-db.service.js.map +0 -1
  140. package/lib/_services/dynamobe-email-service-collection.service.d.ts +0 -19
  141. package/lib/_services/dynamobe-email-service-collection.service.d.ts.map +0 -1
  142. package/lib/_services/dynamobe-email-service-collection.service.js +0 -21
  143. package/lib/_services/dynamobe-email-service-collection.service.js.map +0 -1
  144. package/lib/_services/dynamobe-email.service.d.ts +0 -56
  145. package/lib/_services/dynamobe-email.service.d.ts.map +0 -1
  146. package/lib/_services/dynamobe-email.service.js +0 -194
  147. package/lib/_services/dynamobe-email.service.js.map +0 -1
  148. package/lib/_services/dynamobe-global.service.d.ts +0 -62
  149. package/lib/_services/dynamobe-global.service.d.ts.map +0 -1
  150. package/lib/_services/dynamobe-global.service.js +0 -107
  151. package/lib/_services/dynamobe-global.service.js.map +0 -1
  152. package/lib/_services/dynamobe-routing-module.service.d.ts +0 -42
  153. package/lib/_services/dynamobe-routing-module.service.d.ts.map +0 -1
  154. package/lib/_services/dynamobe-routing-module.service.js +0 -146
  155. package/lib/_services/dynamobe-routing-module.service.js.map +0 -1
  156. package/lib/_services/dynamobe-shared-be.service.d.ts +0 -8
  157. package/lib/_services/dynamobe-shared-be.service.d.ts.map +0 -1
  158. package/lib/_services/dynamobe-shared-be.service.js +0 -45
  159. package/lib/_services/dynamobe-shared-be.service.js.map +0 -1
  160. package/lib/_services/dynamobe-shared.service.d.ts +0 -26
  161. package/lib/_services/dynamobe-shared.service.d.ts.map +0 -1
  162. package/lib/_services/dynamobe-shared.service.js +0 -63
  163. package/lib/_services/dynamobe-shared.service.js.map +0 -1
  164. package/lib/_services/dynamobe-singleton.service.d.ts +0 -9
  165. package/lib/_services/dynamobe-singleton.service.d.ts.map +0 -1
  166. package/lib/_services/dynamobe-singleton.service.js +0 -19
  167. 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
- newData = res.toObject() as T;
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: `We encountered an unhandled DB Error, please contact the responsible development team.`
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
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
- newData = res.toObject() as T;
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: `We encountered an unhandled DB Error, please contact the responsible development team.`
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
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
- data = res.toObject() as T;
122
+ return res.toObject() as T;
123
123
  } else {
124
- data = null;
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
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: `We encountered an unhandled DB Error, please contact the responsible development team.`
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: `We encountered an unhandled DB Error, please contact the responsible development team.`
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: `We encountered an unhandled DB Error, please contact the responsible development team.`
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 > 0) {
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: `We encountered an unhandled DB Error, please contact the responsible development team.`
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 ((searchBy[modelParam.key] !== null && searchBy[modelParam.key] !== undefined) || searchBy[modelParam.key + 'Range']) {
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 (searchBy[searchParamKeyWithoutRange] !== null && searchBy[searchParamKeyWithoutRange] !== undefined) {
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 (searchBy[modelParam.key] !== null && searchBy[modelParam.key] !== undefined) {
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
- await this.dataModel.find(filter).then(res => {
320
- if (res) {
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
343
+ userMessage: this.defaultErrorUserMsg,
330
344
  error
331
345
  });
332
346
  });
333
347
 
334
- if (0 < dataList.length && typeof dataList[0]._id === 'object') {
348
+ if (0 < dataList.length) {
335
349
  dataList.forEach((data: T) => {
336
- data._id = `˙${data._id}`;
350
+ if (data && typeof data._id === 'object') {
351
+ data._id = `${data._id}`;
352
+ }
337
353
  });
338
354
  }
339
355
 
340
- return dataList as T[];
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
- await this.dataModel.find({}).then(res => {
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
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: `We encountered an unhandled DB Error, please contact the responsible development team.`
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 CALLS (with error handlings)
434
+ // DIRECT Basic MONGOOSE FUNCTIONS (with error handlings)
450
435
 
451
436
  /**
452
- * find the data first by any of its parameters, throws error if not found
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
- * @returns data
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
- data = res.toObject() as T;
463
+ return res.toObject() as T;
475
464
  } else {
476
- data = null;
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
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
- * find all data by any of its parameters, throws error if not found
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
- * @returns dataList
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
- await this.dataModel.find(filter).then(res => {
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
518
+ userMessage: this.defaultErrorUserMsg,
526
519
  error
527
520
  });
528
521
  });
529
522
 
530
- if (0 < dataList.length && typeof dataList[0]._id === 'object') {
523
+ if (0 < dataList.length) {
531
524
  dataList.forEach((data: T) => {
532
- data._id = `˙${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
- * find all data by any of its parameters, throws error if not found
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 etc. by dateTime: { dateTime: -1 }
558
- * @returns dataList
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
- if (res) {
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
577
+ userMessage: this.defaultErrorUserMsg,
577
578
  error
578
579
  });
579
580
  });
580
581
 
581
- if (0 < dataList.length && typeof dataList[0]._id === 'object') {
582
+ if (0 < dataList.length) {
582
583
  dataList.forEach((data: T) => {
583
- data._id = `˙${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
- data = res.toObject() as T;
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: `We encountered an unhandled DB Error, please contact the responsible development team.`
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
621
+ userMessage: this.defaultErrorUserMsg,
620
622
  error
621
623
  });
622
624
  });
623
- update.__v = data.__v;
624
- return update;
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
- * update one parameter by a specific
629
- * @param updateBy
630
- * (always use unique parameters for find!)
631
- * etc.: by email:
632
- * @example { email: email }
633
- * or by id that is in list:
634
- * @example { userIds: { $in: this.userId } }
635
- * or by number or Date that is GREATER THAN OR LESS THAN:
636
- * @example { points: { $gt: 2, $lt: 14 } }
637
- * further tools (syntax matches with $gt):
638
- * $eq: Matches values that are EQUAL to a specified value.
639
- * $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
640
- * $lte: Matches values that are LESS THAN or EQUAL to a specified value.
641
- * $ne: Matches all values that are NOT EQUAL to a specified value.
642
- * $nin: Matches NONE of the values specified IN an array.
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
- * etc.: increase a specific value:
646
- * @example { $inc: { popularity: 15 } }
647
- * or add element to a list:
648
- * @example { $push: { reactions: this.newReaction }
649
- * or all at once
650
- * @example { $inc: { popularity: this.newVote.amount }, emailVerified: true, $push: { reactions: this.newReaction } }
651
- * further tools (syntax matches with $inc):
652
- * $currentDate: Sets the value of a field to current date, either as a Date or a Timestamp.
653
- * $min: Only updates the field if the specified value is less than the existing field value.
654
- * $max: Only updates the field if the specified value is greater than the existing field value.
655
- * $mul: Multiplies the value of the field by the specified amount.
656
- * $rename: Renames a field.
657
- * $unset: Removes the specified field from a document. (set: "" to value)
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<void> {
685
+ async updateOne(updateBy: any, update: any, modifier: string): Promise<T> {
660
686
  update.__lastModified = new Date();
661
687
  update.__lastModifiedBy = modifier;
662
- await this.dataModel.updateOne(updateBy, update).catch(error => {
663
- throw new Dynamo_Error({
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
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 updateBy
677
- * etc.: by email:
678
- * @example { email: email }
679
- * or by id that is in list:
680
- * @example { userIds: { $in: this.userId } }
681
- * or by number or Date that is GREATER THAN OR LESS THAN:
682
- * @example { points: { $gt: 2, $lt: 14 } }
683
- * further tools (syntax matches with $gt):
684
- * $eq: Matches values that are EQUAL to a specified value.
685
- * $gte: Matches values that are GREATER THAN or EQUAL to a specified value.
686
- * $lte: Matches values that are LESS THAN or EQUAL to a specified value.
687
- * $ne: Matches all values that are NOT EQUAL to a specified value.
688
- * $nin: Matches NONE of the values specified IN an array.
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
- * etc.: increase a specific value:
692
- * @example { $inc: { popularity: 15 } }
693
- * or add element to a list:
694
- * @example { $push: { reactions: this.newReaction }
695
- * or all at once
696
- * @example { $inc: { popularity: this.newVote.amount }, emailVerified: true, $push: { reactions: this.newReaction } }
697
- * further tools (syntax matches with $inc):
698
- * $currentDate: Sets the value of a field to current date, either as a Date or a Timestamp.
699
- * $min: Only updates the field if the specified value is less than the existing field value.
700
- * $max: Only updates the field if the specified value is greater than the existing field value.
701
- * $mul: Multiplies the value of the field by the specified amount.
702
- * $rename: Renames a field.
703
- * $unset: Removes the specified field from a document. (set: "" to value)
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<void> {
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).catch(error => {
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: `We encountered an unhandled DB Error, please contact the responsible development team.`,
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.subObjectParams) {
837
+ if (beType !== Object || !property?.subObjectParams || property?.subObjectParams?.length == 0) {
758
838
  schemaSettingsObj[property.key] = {
759
839
  type: beType
760
840
  };