@futdevpro/nts-dynamo 1.5.30 → 1.5.31

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