@lenne.tech/nest-server 8.0.2 → 8.3.0

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 (166) hide show
  1. package/dist/config.env.js +3 -2
  2. package/dist/config.env.js.map +1 -1
  3. package/dist/core/common/args/pagination.args.js +1 -1
  4. package/dist/core/common/args/pagination.args.js.map +1 -1
  5. package/dist/core/common/decorators/restricted.decorator.d.ts +3 -0
  6. package/dist/core/common/decorators/restricted.decorator.js +14 -8
  7. package/dist/core/common/decorators/restricted.decorator.js.map +1 -1
  8. package/dist/core/common/enums/role.enum.d.ts +3 -2
  9. package/dist/core/common/enums/role.enum.js +3 -2
  10. package/dist/core/common/enums/role.enum.js.map +1 -1
  11. package/dist/core/common/helpers/config.helper.d.ts +2 -1
  12. package/dist/core/common/helpers/config.helper.js +11 -7
  13. package/dist/core/common/helpers/config.helper.js.map +1 -1
  14. package/dist/core/common/helpers/context.helper.d.ts +7 -1
  15. package/dist/core/common/helpers/context.helper.js +33 -29
  16. package/dist/core/common/helpers/context.helper.js.map +1 -1
  17. package/dist/core/common/helpers/db.helper.d.ts +37 -0
  18. package/dist/core/common/helpers/db.helper.js +356 -0
  19. package/dist/core/common/helpers/db.helper.js.map +1 -0
  20. package/dist/core/common/helpers/file.helper.d.ts +8 -1
  21. package/dist/core/common/helpers/file.helper.js +43 -31
  22. package/dist/core/common/helpers/file.helper.js.map +1 -1
  23. package/dist/core/common/helpers/filter.helper.d.ts +3 -0
  24. package/dist/core/common/helpers/filter.helper.js +93 -81
  25. package/dist/core/common/helpers/filter.helper.js.map +1 -1
  26. package/dist/core/common/helpers/graphql.helper.d.ts +24 -1
  27. package/dist/core/common/helpers/graphql.helper.js +144 -96
  28. package/dist/core/common/helpers/graphql.helper.js.map +1 -1
  29. package/dist/core/common/helpers/input.helper.d.ts +42 -4
  30. package/dist/core/common/helpers/input.helper.js +256 -97
  31. package/dist/core/common/helpers/input.helper.js.map +1 -1
  32. package/dist/core/common/helpers/model.helper.d.ts +11 -0
  33. package/dist/core/common/helpers/model.helper.js +41 -29
  34. package/dist/core/common/helpers/model.helper.js.map +1 -1
  35. package/dist/core/common/helpers/service.helper.d.ts +21 -1
  36. package/dist/core/common/helpers/service.helper.js +80 -72
  37. package/dist/core/common/helpers/service.helper.js.map +1 -1
  38. package/dist/core/common/inputs/combined-filter.input.js +1 -1
  39. package/dist/core/common/inputs/combined-filter.input.js.map +1 -1
  40. package/dist/core/common/inputs/core-input.input.js +1 -1
  41. package/dist/core/common/inputs/core-input.input.js.map +1 -1
  42. package/dist/core/common/interceptors/check-response.interceptor.js +1 -1
  43. package/dist/core/common/interceptors/check-response.interceptor.js.map +1 -1
  44. package/dist/core/common/interfaces/resolve-selector.interface.d.ts +5 -0
  45. package/dist/core/common/interfaces/resolve-selector.interface.js +3 -0
  46. package/dist/core/common/interfaces/resolve-selector.interface.js.map +1 -0
  47. package/dist/core/common/interfaces/service-options.interface.d.ts +36 -0
  48. package/dist/core/common/interfaces/service-options.interface.js +3 -0
  49. package/dist/core/common/interfaces/service-options.interface.js.map +1 -0
  50. package/dist/core/common/models/core-model.model.d.ts +5 -1
  51. package/dist/core/common/models/core-model.model.js +1 -1
  52. package/dist/core/common/models/core-model.model.js.map +1 -1
  53. package/dist/core/common/pipes/check-input.pipe.js +2 -2
  54. package/dist/core/common/pipes/check-input.pipe.js.map +1 -1
  55. package/dist/core/common/pipes/map-and-validate.pipe.js +1 -1
  56. package/dist/core/common/pipes/map-and-validate.pipe.js.map +1 -1
  57. package/dist/core/common/services/crud.service.d.ts +13 -0
  58. package/dist/core/common/services/crud.service.js +57 -0
  59. package/dist/core/common/services/crud.service.js.map +1 -0
  60. package/dist/core/common/services/email.service.js +8 -8
  61. package/dist/core/common/services/email.service.js.map +1 -1
  62. package/dist/core/common/services/module.service.d.ts +40 -0
  63. package/dist/core/common/services/module.service.js +80 -0
  64. package/dist/core/common/services/module.service.js.map +1 -0
  65. package/dist/core/common/types/core-model-constructor.type.d.ts +21 -0
  66. package/dist/core/common/types/core-model-constructor.type.js +3 -0
  67. package/dist/core/common/types/core-model-constructor.type.js.map +1 -0
  68. package/dist/core/common/types/field-selection.type.d.ts +4 -0
  69. package/dist/core/common/types/field-selection.type.js +3 -0
  70. package/dist/core/common/types/field-selection.type.js.map +1 -0
  71. package/dist/core/common/types/ids.type.d.ts +8 -0
  72. package/dist/core/common/types/ids.type.js +3 -0
  73. package/dist/core/common/types/ids.type.js.map +1 -0
  74. package/dist/core/common/types/string-or-object-id.type.d.ts +2 -0
  75. package/dist/core/common/types/string-or-object-id.type.js +3 -0
  76. package/dist/core/common/types/string-or-object-id.type.js.map +1 -0
  77. package/dist/core/modules/auth/core-auth.resolver.d.ts +2 -1
  78. package/dist/core/modules/auth/core-auth.resolver.js +4 -3
  79. package/dist/core/modules/auth/core-auth.resolver.js.map +1 -1
  80. package/dist/core/modules/auth/guards/roles.guard.js +1 -2
  81. package/dist/core/modules/auth/guards/roles.guard.js.map +1 -1
  82. package/dist/core/modules/auth/services/core-auth-user.service.d.ts +3 -1
  83. package/dist/core/modules/auth/services/core-auth-user.service.js.map +1 -1
  84. package/dist/core/modules/auth/services/core-auth.service.d.ts +2 -1
  85. package/dist/core/modules/auth/services/core-auth.service.js +6 -4
  86. package/dist/core/modules/auth/services/core-auth.service.js.map +1 -1
  87. package/dist/core/modules/user/core-user.model.js +1 -1
  88. package/dist/core/modules/user/core-user.model.js.map +1 -1
  89. package/dist/core/modules/user/core-user.service.d.ts +16 -25
  90. package/dist/core/modules/user/core-user.service.js +69 -90
  91. package/dist/core/modules/user/core-user.service.js.map +1 -1
  92. package/dist/core.module.js +1 -1
  93. package/dist/core.module.js.map +1 -1
  94. package/dist/index.d.ts +9 -1
  95. package/dist/index.js +9 -1
  96. package/dist/index.js.map +1 -1
  97. package/dist/server/modules/auth/auth.resolver.d.ts +2 -1
  98. package/dist/server/modules/auth/auth.resolver.js +4 -3
  99. package/dist/server/modules/auth/auth.resolver.js.map +1 -1
  100. package/dist/server/modules/file/file.controller.js +1 -1
  101. package/dist/server/modules/file/file.controller.js.map +1 -1
  102. package/dist/server/modules/user/avatar.controller.js +2 -2
  103. package/dist/server/modules/user/avatar.controller.js.map +1 -1
  104. package/dist/server/modules/user/user.model.d.ts +2 -1
  105. package/dist/server/modules/user/user.module.js +7 -3
  106. package/dist/server/modules/user/user.module.js.map +1 -1
  107. package/dist/server/modules/user/user.resolver.d.ts +8 -7
  108. package/dist/server/modules/user/user.resolver.js +85 -49
  109. package/dist/server/modules/user/user.resolver.js.map +1 -1
  110. package/dist/server/modules/user/user.service.d.ts +9 -18
  111. package/dist/server/modules/user/user.service.js +23 -30
  112. package/dist/server/modules/user/user.service.js.map +1 -1
  113. package/dist/test/test.helper.d.ts +1 -2
  114. package/dist/test/test.helper.js +1 -16
  115. package/dist/test/test.helper.js.map +1 -1
  116. package/dist/tsconfig.build.tsbuildinfo +1 -1
  117. package/package.json +58 -59
  118. package/src/config.env.ts +3 -2
  119. package/src/core/common/args/pagination.args.ts +2 -2
  120. package/src/core/common/decorators/restricted.decorator.ts +24 -12
  121. package/src/core/common/enums/role.enum.ts +23 -5
  122. package/src/core/common/helpers/config.helper.ts +26 -6
  123. package/src/core/common/helpers/context.helper.ts +42 -33
  124. package/src/core/common/helpers/db.helper.ts +595 -0
  125. package/src/core/common/helpers/file.helper.ts +76 -49
  126. package/src/core/common/helpers/filter.helper.ts +119 -96
  127. package/src/core/common/helpers/graphql.helper.ts +219 -117
  128. package/src/core/common/helpers/input.helper.ts +349 -108
  129. package/src/core/common/helpers/model.helper.ts +102 -57
  130. package/src/core/common/helpers/service.helper.ts +149 -117
  131. package/src/core/common/inputs/combined-filter.input.ts +2 -2
  132. package/src/core/common/inputs/core-input.input.ts +2 -2
  133. package/src/core/common/interceptors/check-response.interceptor.ts +2 -2
  134. package/src/core/common/interfaces/resolve-selector.interface.ts +9 -0
  135. package/src/core/common/interfaces/service-options.interface.ts +71 -0
  136. package/src/core/common/models/core-model.model.ts +7 -3
  137. package/src/core/common/pipes/check-input.pipe.ts +4 -4
  138. package/src/core/common/pipes/map-and-validate.pipe.ts +2 -2
  139. package/src/core/common/services/crud.service.ts +100 -0
  140. package/src/core/common/services/email.service.ts +9 -9
  141. package/src/core/common/services/module.service.ts +188 -0
  142. package/src/core/common/types/core-model-constructor.type.ts +30 -0
  143. package/src/core/common/types/field-selection.type.ts +8 -0
  144. package/src/core/common/types/ids.type.ts +7 -0
  145. package/src/core/common/types/string-or-object-id.type.ts +3 -0
  146. package/src/core/modules/auth/core-auth.module.ts +1 -1
  147. package/src/core/modules/auth/core-auth.resolver.ts +8 -3
  148. package/src/core/modules/auth/guards/roles.guard.ts +5 -7
  149. package/src/core/modules/auth/services/core-auth-user.service.ts +7 -1
  150. package/src/core/modules/auth/services/core-auth.service.ts +14 -4
  151. package/src/core/modules/user/core-user.model.ts +2 -1
  152. package/src/core/modules/user/core-user.service.ts +115 -185
  153. package/src/core.module.ts +2 -2
  154. package/src/index.ts +9 -1
  155. package/src/main.ts +1 -1
  156. package/src/server/modules/auth/auth.resolver.ts +8 -3
  157. package/src/server/modules/file/file.controller.ts +2 -2
  158. package/src/server/modules/user/avatar.controller.ts +3 -3
  159. package/src/server/modules/user/user.module.ts +7 -3
  160. package/src/server/modules/user/user.resolver.ts +74 -43
  161. package/src/server/modules/user/user.service.ts +30 -53
  162. package/src/test/test.helper.ts +31 -30
  163. package/dist/core/modules/user/core-basic-user.service.d.ts +0 -17
  164. package/dist/core/modules/user/core-basic-user.service.js +0 -73
  165. package/dist/core/modules/user/core-basic-user.service.js.map +0 -1
  166. package/src/core/modules/user/core-basic-user.service.ts +0 -138
@@ -0,0 +1,356 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setPopulates = exports.removeIds = exports.popAndMap = exports.removeUnresolvedReferences = exports.objectIdsToStrings = exports.includesIds = exports.getJSONClone = exports.getPopulatOptionsFromSelections = exports.getPopulateOptions = exports.getElementsViaIds = exports.getObjectIds = exports.getStringIds = exports.getIndexesViaIds = exports.equalIds = exports.addIds = void 0;
4
+ const _ = require("lodash");
5
+ const mongoose_1 = require("mongoose");
6
+ function addIds(target, ids, convert = 'auto', options) {
7
+ const config = Object.assign({ unique: true }, options);
8
+ let result = target;
9
+ if (!Array.isArray(result)) {
10
+ result = [];
11
+ }
12
+ if (!Array.isArray(ids)) {
13
+ ids = [ids];
14
+ }
15
+ if (config.unique) {
16
+ removeIds(ids, target);
17
+ }
18
+ if (ids.length) {
19
+ if (result.length &&
20
+ convert === 'auto' &&
21
+ ((result[0] instanceof mongoose_1.Types.ObjectId && !(ids instanceof mongoose_1.Types.ObjectId)) ||
22
+ (typeof result[0] === 'string' && typeof ids !== 'string'))) {
23
+ const converted = result[0] instanceof mongoose_1.Types.ObjectId ? getObjectIds(ids) : getStringIds(ids);
24
+ result.push(...converted);
25
+ }
26
+ else {
27
+ result.push(...ids);
28
+ }
29
+ }
30
+ if (['string', 'object'].includes(convert)) {
31
+ for (let i = 0; i < result.length; i++) {
32
+ result[i] = convert === 'string' ? getStringId(result[i]) : getObjectIds(result[i]);
33
+ }
34
+ }
35
+ return result;
36
+ }
37
+ exports.addIds = addIds;
38
+ function equalIds(...ids) {
39
+ if (!ids) {
40
+ return true;
41
+ }
42
+ const compare = getStringIds(ids[0]);
43
+ if (!compare) {
44
+ return false;
45
+ }
46
+ return ids.every((id) => getStringIds(id) === compare);
47
+ }
48
+ exports.equalIds = equalIds;
49
+ function getIndexesViaIds(ids, array) {
50
+ if (!ids) {
51
+ return [];
52
+ }
53
+ if (!Array.isArray(ids)) {
54
+ ids = [ids];
55
+ }
56
+ if (!Array.isArray(array)) {
57
+ return [];
58
+ }
59
+ const indexes = [];
60
+ ids.forEach((id) => {
61
+ array.forEach((element, index) => {
62
+ if (equalIds(id, element)) {
63
+ indexes.push(index);
64
+ }
65
+ });
66
+ });
67
+ return indexes;
68
+ }
69
+ exports.getIndexesViaIds = getIndexesViaIds;
70
+ function getStringIds(elements, options) {
71
+ const { deep, unique } = Object.assign({ deep: false, unique: false }, options);
72
+ if (!elements) {
73
+ return elements;
74
+ }
75
+ let ids = [];
76
+ if (!Array.isArray(elements)) {
77
+ return getStringId(elements);
78
+ }
79
+ for (const element of elements) {
80
+ if (Array.isArray(element)) {
81
+ if (deep) {
82
+ ids = ids.concat(getStringIds(element, { deep }));
83
+ }
84
+ }
85
+ else {
86
+ const id = getStringId(element);
87
+ if (id) {
88
+ ids.push(id);
89
+ }
90
+ }
91
+ }
92
+ return unique ? _.uniq(ids) : ids;
93
+ }
94
+ exports.getStringIds = getStringIds;
95
+ function getObjectIds(ids) {
96
+ if (Array.isArray(ids)) {
97
+ return ids.map((id) => new mongoose_1.Types.ObjectId(getStringId(id)));
98
+ }
99
+ return new mongoose_1.Types.ObjectId(getStringId(ids));
100
+ }
101
+ exports.getObjectIds = getObjectIds;
102
+ function getElementsViaIds(ids, array, options = {}) {
103
+ const config = Object.assign({ splice: false, unique: false }, options);
104
+ const indexes = getIndexesViaIds(ids, array);
105
+ if (!(indexes === null || indexes === void 0 ? void 0 : indexes.length)) {
106
+ return [];
107
+ }
108
+ const elements = [];
109
+ indexes.forEach((index) => {
110
+ if (config.splice) {
111
+ elements.push(array.splice(index, 1)[0]);
112
+ }
113
+ else {
114
+ elements.push(array[index]);
115
+ }
116
+ });
117
+ if (config.unique) {
118
+ return elements.filter((value, index, self) => {
119
+ return self.findIndex((e) => getStringIds(e)) === index;
120
+ });
121
+ }
122
+ return elements;
123
+ }
124
+ exports.getElementsViaIds = getElementsViaIds;
125
+ function getPopulateOptions(info, select) {
126
+ var _a, _b, _c, _d;
127
+ const result = [];
128
+ if (!((_a = info === null || info === void 0 ? void 0 : info.fieldNodes) === null || _a === void 0 ? void 0 : _a.length)) {
129
+ return result;
130
+ }
131
+ for (const fieldNode of info.fieldNodes) {
132
+ if ((select || ((_b = fieldNode === null || fieldNode === void 0 ? void 0 : fieldNode.name) === null || _b === void 0 ? void 0 : _b.value) === select) && ((_d = (_c = fieldNode === null || fieldNode === void 0 ? void 0 : fieldNode.selectionSet) === null || _c === void 0 ? void 0 : _c.selections) === null || _d === void 0 ? void 0 : _d.length)) {
133
+ return getPopulatOptionsFromSelections(fieldNode.selectionSet.selections);
134
+ }
135
+ }
136
+ return result;
137
+ }
138
+ exports.getPopulateOptions = getPopulateOptions;
139
+ function getPopulatOptionsFromSelections(selectionNodes) {
140
+ var _a, _b, _c, _d;
141
+ const populateOptions = [];
142
+ if (!selectionNodes || !selectionNodes.length) {
143
+ return populateOptions;
144
+ }
145
+ for (const node of selectionNodes) {
146
+ const option = {
147
+ path: node.name.value,
148
+ };
149
+ if ((_b = (_a = node.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length) {
150
+ for (const innerNode of node.selectionSet.selections) {
151
+ if (!((_d = (_c = innerNode.selectionSet) === null || _c === void 0 ? void 0 : _c.selections) === null || _d === void 0 ? void 0 : _d.length)) {
152
+ option.select ? option.select.push(innerNode.name.value) : (option.select = [innerNode.name.value]);
153
+ }
154
+ else {
155
+ const innerPopulate = getPopulatOptionsFromSelections([innerNode]);
156
+ option.populate = option.populate
157
+ ? option.populate.concat(innerPopulate)
158
+ : innerPopulate;
159
+ }
160
+ }
161
+ }
162
+ if (option.select || option.populate) {
163
+ populateOptions.push(option);
164
+ }
165
+ }
166
+ return populateOptions;
167
+ }
168
+ exports.getPopulatOptionsFromSelections = getPopulatOptionsFromSelections;
169
+ function getJSONClone(obj) {
170
+ return JSON.parse(JSON.stringify(obj));
171
+ }
172
+ exports.getJSONClone = getJSONClone;
173
+ function includesIds(includes, ids, convert) {
174
+ if (!includes || !ids) {
175
+ return null;
176
+ }
177
+ if (!Array.isArray(includes)) {
178
+ includes = [includes];
179
+ }
180
+ if (!Array.isArray(ids)) {
181
+ ids = [ids];
182
+ }
183
+ let result = [];
184
+ const includesStrings = getStringIds(includes);
185
+ for (const id of ids) {
186
+ if (includesStrings.includes(getStringIds(id))) {
187
+ result.push(id);
188
+ }
189
+ }
190
+ if (convert) {
191
+ result = convert === 'string' ? getStringIds(result) : getObjectIds(result);
192
+ }
193
+ return result.length ? result : null;
194
+ }
195
+ exports.includesIds = includesIds;
196
+ function objectIdsToStrings(element, prepared = new WeakMap()) {
197
+ if (!element) {
198
+ return element;
199
+ }
200
+ if (element instanceof mongoose_1.Types.ObjectId) {
201
+ return element.toHexString();
202
+ }
203
+ if (Array.isArray(element)) {
204
+ return element.map((e) => objectIdsToStrings(e, prepared));
205
+ }
206
+ if (typeof element === 'object') {
207
+ if (prepared.has(element)) {
208
+ return prepared.get(element);
209
+ }
210
+ const preparedObject = element;
211
+ prepared.set(element, preparedObject);
212
+ for (const [key, val] of Object.entries(element)) {
213
+ preparedObject[key] = objectIdsToStrings(val, prepared);
214
+ }
215
+ }
216
+ return element;
217
+ }
218
+ exports.objectIdsToStrings = objectIdsToStrings;
219
+ function removeUnresolvedReferences(populated, populatedOptions, ignoreFirst = true) {
220
+ if (!populated || !populatedOptions) {
221
+ return populated;
222
+ }
223
+ if (Array.isArray(populated)) {
224
+ populated.forEach((p) => removeUnresolvedReferences(p, populatedOptions, false));
225
+ return populated;
226
+ }
227
+ if (typeof populated === 'object') {
228
+ if (Array.isArray(populatedOptions)) {
229
+ populatedOptions.forEach((po) => removeUnresolvedReferences(populated, ignoreFirst ? po.populate : po, false));
230
+ return populated;
231
+ }
232
+ if (typeof populatedOptions === 'string') {
233
+ if (!['id', '_id'].includes(populatedOptions) && populated[populatedOptions] instanceof mongoose_1.Types.ObjectId) {
234
+ populated[populatedOptions] = null;
235
+ }
236
+ return populated;
237
+ }
238
+ if (populatedOptions.path) {
239
+ const key = populatedOptions.path;
240
+ if (!['id', '_id'].includes(key) && populated[key] instanceof mongoose_1.Types.ObjectId) {
241
+ populated[key] = null;
242
+ }
243
+ else if (populatedOptions.populate) {
244
+ removeUnresolvedReferences(populated[key], populatedOptions.populate, false);
245
+ }
246
+ }
247
+ }
248
+ return populated;
249
+ }
250
+ exports.removeUnresolvedReferences = removeUnresolvedReferences;
251
+ async function popAndMap(queryOrDocument, populate, modelClass, mongooseModel) {
252
+ var _a, _b, _c, _d, _e;
253
+ let result;
254
+ let populateOptions = [];
255
+ if (populate) {
256
+ if (Array.isArray(populate) && typeof ((_a = populate[0]) === null || _a === void 0 ? void 0 : _a.path) === 'string') {
257
+ populateOptions = populate;
258
+ }
259
+ else if (Array.isArray(populate) && typeof ((_b = populate[0]) === null || _b === void 0 ? void 0 : _b.kind) === 'string') {
260
+ populateOptions = getPopulatOptionsFromSelections(populate);
261
+ }
262
+ else if (populate.info) {
263
+ populateOptions = getPopulateOptions(populate.info, populate.select);
264
+ }
265
+ }
266
+ if (queryOrDocument instanceof mongoose_1.Query) {
267
+ result = await setPopulates(queryOrDocument, populateOptions, (_c = mongooseModel === null || mongooseModel === void 0 ? void 0 : mongooseModel.schema) === null || _c === void 0 ? void 0 : _c.paths);
268
+ if (result instanceof mongoose_1.Query) {
269
+ result = await result.exec();
270
+ }
271
+ if (Array.isArray(result)) {
272
+ result = result.map((item) => modelClass.map(item));
273
+ }
274
+ else {
275
+ result = modelClass.map(result);
276
+ }
277
+ }
278
+ else {
279
+ if (Array.isArray(queryOrDocument)) {
280
+ await setPopulates(queryOrDocument, populateOptions, (_d = mongooseModel === null || mongooseModel === void 0 ? void 0 : mongooseModel.schema) === null || _d === void 0 ? void 0 : _d.paths);
281
+ result = queryOrDocument.map((item) => modelClass.map(item));
282
+ }
283
+ else {
284
+ await setPopulates(queryOrDocument, populateOptions, (_e = mongooseModel === null || mongooseModel === void 0 ? void 0 : mongooseModel.schema) === null || _e === void 0 ? void 0 : _e.paths);
285
+ result = modelClass.map(queryOrDocument);
286
+ }
287
+ }
288
+ return removeUnresolvedReferences(result, populateOptions);
289
+ }
290
+ exports.popAndMap = popAndMap;
291
+ function removeIds(source, ids) {
292
+ if (!ids) {
293
+ return source;
294
+ }
295
+ if (!Array.isArray(ids)) {
296
+ ids = [ids];
297
+ }
298
+ if (!Array.isArray(source)) {
299
+ return [];
300
+ }
301
+ const stringIds = getStringIds(source);
302
+ ids.forEach((id) => {
303
+ const position = stringIds.indexOf(getStringIds(id));
304
+ if (position !== -1) {
305
+ source.splice(position, 1);
306
+ }
307
+ });
308
+ return source;
309
+ }
310
+ exports.removeIds = removeIds;
311
+ async function setPopulates(queryOrDocument, populateOptions, modelSchemaPaths) {
312
+ if (!(populateOptions === null || populateOptions === void 0 ? void 0 : populateOptions.length) || !queryOrDocument) {
313
+ return queryOrDocument;
314
+ }
315
+ if (modelSchemaPaths) {
316
+ populateOptions = populateOptions.filter((options) => {
317
+ return Object.keys(modelSchemaPaths).includes(options.path);
318
+ });
319
+ }
320
+ if (queryOrDocument instanceof mongoose_1.Query) {
321
+ for (const options of populateOptions) {
322
+ queryOrDocument = queryOrDocument.populate(options);
323
+ }
324
+ }
325
+ else if (Array.isArray(queryOrDocument)) {
326
+ const promises = [];
327
+ queryOrDocument.forEach((item) => promises.push(item.populate(populateOptions)));
328
+ await Promise.all(promises);
329
+ }
330
+ else {
331
+ await queryOrDocument.populate(populateOptions);
332
+ }
333
+ return queryOrDocument;
334
+ }
335
+ exports.setPopulates = setPopulates;
336
+ function getStringId(element) {
337
+ if (!element) {
338
+ return element;
339
+ }
340
+ if (typeof element === 'string') {
341
+ return element;
342
+ }
343
+ if (typeof element === 'object') {
344
+ if (element instanceof mongoose_1.Types.ObjectId) {
345
+ return element.toHexString();
346
+ }
347
+ if (element.id) {
348
+ return getStringId(element.id);
349
+ }
350
+ else if (element._id) {
351
+ return getStringId(element._id);
352
+ }
353
+ }
354
+ return element.toString();
355
+ }
356
+ //# sourceMappingURL=db.helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/db.helper.ts"],"names":[],"mappings":";;;AACA,4BAA4B;AAC5B,uCAAsF;AAuBtF,SAAgB,MAAM,CACpB,MAAW,EACX,GAA0C,EAC1C,UAAgD,MA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OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,IAAI,OAAO,YAAY,gBAAK,CAAC,QAAQ,EAAE;YACrC,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;SAC9B;QAED,IAAI,OAAO,CAAC,EAAE,EAAE;YACd,OAAO,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;SAChC;aAAM,IAAI,OAAO,CAAC,GAAG,EAAE;YACtB,OAAO,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;SACjC;KACF;IAGD,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { MulterOptions } from '@nestjs/platform-express/multer/interfaces/multer-options.interface';
2
- export declare class FileHelper {
2
+ export default class FileHelper {
3
3
  static multerRandomFileName(numberOfDigits?: number): (req: any, file: any, cb: any) => void;
4
4
  static multerFileFilter(fileTypeRegex?: RegExp): (req: any, file: any, cb: any) => any;
5
5
  static multerOptionsForImageUpload(options: {
@@ -8,3 +8,10 @@ export declare class FileHelper {
8
8
  fileTypeRegex?: RegExp;
9
9
  }): MulterOptions;
10
10
  }
11
+ export declare function multerRandomFileName(numberOfDigits?: number): (req: any, file: any, cb: any) => void;
12
+ export declare function multerFileFilter(fileTypeRegex?: RegExp): (req: any, file: any, cb: any) => any;
13
+ export declare function multerOptionsForImageUpload(options: {
14
+ destination?: string;
15
+ fileSize?: number;
16
+ fileTypeRegex?: RegExp;
17
+ }): MulterOptions;
@@ -1,44 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileHelper = void 0;
3
+ exports.multerOptionsForImageUpload = exports.multerFileFilter = exports.multerRandomFileName = void 0;
4
4
  const multer_1 = require("multer");
5
5
  const path_1 = require("path");
6
6
  class FileHelper {
7
7
  static multerRandomFileName(numberOfDigits = 32) {
8
- return (req, file, cb) => {
9
- const randomName = Array(numberOfDigits)
10
- .fill(null)
11
- .map(() => Math.round(Math.random() * 16).toString(16))
12
- .join('');
13
- cb(null, `${randomName}${(0, path_1.extname)(file.originalname)}`);
14
- };
8
+ return multerRandomFileName(numberOfDigits);
15
9
  }
16
10
  static multerFileFilter(fileTypeRegex = /jpeg|jpg|png/) {
17
- return (req, file, cb) => {
18
- const mimetype = fileTypeRegex.test(file.mimetype);
19
- const extName = fileTypeRegex.test((0, path_1.extname)(file.originalname).toLowerCase());
20
- if (mimetype && extName) {
21
- return cb(null, true);
22
- }
23
- cb('Error: File upload only supports the following filetypes - ' + fileTypeRegex);
24
- };
11
+ return multerFileFilter(fileTypeRegex);
25
12
  }
26
13
  static multerOptionsForImageUpload(options) {
27
- options = Object.assign({
28
- fileSize: 1024 * 1024,
29
- fileTypeRegex: /jpeg|jpg|png/,
30
- }, options);
31
- return {
32
- fileFilter: options.fileTypeRegex ? FileHelper.multerFileFilter(options.fileTypeRegex) : undefined,
33
- limits: {
34
- fileSize: options.fileSize ? options.fileSize : undefined,
35
- },
36
- storage: (0, multer_1.diskStorage)({
37
- destination: options.destination ? options.destination : undefined,
38
- filename: FileHelper.multerRandomFileName(),
39
- }),
40
- };
14
+ return multerOptionsForImageUpload(options);
41
15
  }
42
16
  }
43
- exports.FileHelper = FileHelper;
17
+ exports.default = FileHelper;
18
+ function multerRandomFileName(numberOfDigits = 32) {
19
+ return (req, file, cb) => {
20
+ const randomName = Array(numberOfDigits)
21
+ .fill(null)
22
+ .map(() => Math.round(Math.random() * 16).toString(16))
23
+ .join('');
24
+ cb(null, `${randomName}${(0, path_1.extname)(file.originalname)}`);
25
+ };
26
+ }
27
+ exports.multerRandomFileName = multerRandomFileName;
28
+ function multerFileFilter(fileTypeRegex = /jpeg|jpg|png/) {
29
+ return (req, file, cb) => {
30
+ const mimetype = fileTypeRegex.test(file.mimetype);
31
+ const extName = fileTypeRegex.test((0, path_1.extname)(file.originalname).toLowerCase());
32
+ if (mimetype && extName) {
33
+ return cb(null, true);
34
+ }
35
+ cb('Error: File upload only supports the following filetypes - ' + fileTypeRegex);
36
+ };
37
+ }
38
+ exports.multerFileFilter = multerFileFilter;
39
+ function multerOptionsForImageUpload(options) {
40
+ options = Object.assign({
41
+ fileSize: 1024 * 1024,
42
+ fileTypeRegex: /jpeg|jpg|png/,
43
+ }, options);
44
+ return {
45
+ fileFilter: options.fileTypeRegex ? multerFileFilter(options.fileTypeRegex) : undefined,
46
+ limits: {
47
+ fileSize: options.fileSize ? options.fileSize : undefined,
48
+ },
49
+ storage: (0, multer_1.diskStorage)({
50
+ destination: options.destination ? options.destination : undefined,
51
+ filename: multerRandomFileName(),
52
+ }),
53
+ };
54
+ }
55
+ exports.multerOptionsForImageUpload = multerOptionsForImageUpload;
44
56
  //# sourceMappingURL=file.helper.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"file.helper.js","sourceRoot":"","sources":["../../../../src/core/common/helpers/file.helper.ts"],"names":[],"mappings":";;;AACA,mCAAqC;AACrC,+BAA+B;AAK/B,MAAa,UAAU;IAKd,MAAM,CAAC,oBAAoB,CAAC,cAAc,GAAG,EAAE;QACpD,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE;YAEvB,MAAM,UAAU,GAAG,KAAK,CAAC,cAAc,CAAC;iBACrC,IAAI,CAAC,IAAI,CAAC;iBACV,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;iBACtD,IAAI,CAAC,EAAE,CAAC,CAAC;YAIZ,EAAE,CAAC,IAAI,EAAE,GAAG,UAAU,GAAG,IAAA,cAAO,EAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;QACzD,CAAC,CAAC;IACJ,CAAC;IAKM,MAAM,CAAC,gBAAgB,CAAC,aAAa,GAAG,cAAc;QAC3D,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE;YACvB,MAAM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G,aAAa,CAAC,CAAC;IACpF,CAAC,CAAC;AACJ,CAAC;AAVD,4CAUC;AAKD,SAAgB,2BAA2B,CAAC,OAI3C;IAEC,OAAO,GAAG,MAAM,CAAC,MAAM,CACrB;QACE,QAAQ,EAAE,IAAI,GAAG,IAAI;QACrB,aAAa,EAAE,cAAc;KAC9B,EACD,OAAO,CACR,CAAC;IAEF,OAAO;QAEL,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS;QAGvF,MAAM,EAAE;YAEN,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SAC1D;QAID,OAAO,EAAE,IAAA,oBAAW,EAAC;YAInB,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;YAGlE,QAAQ,EAAE,oBAAoB,EAAE;SACjC,CAAC;KACH,CAAC;AACJ,CAAC;AApCD,kEAoCC"}
@@ -6,3 +6,6 @@ export declare class Filter {
6
6
  static generateFilterQuery<T = any>(filter?: Partial<FilterInput>): FilterQuery<T> | any;
7
7
  static generateFindOptions<T = any>(filterArgs: Partial<FilterArgs>): QueryOptions;
8
8
  }
9
+ export declare function convertFilterArgsToQuery<T = any>(filterArgs: Partial<FilterArgs>): [FilterQuery<T>, QueryOptions];
10
+ export declare function generateFilterQuery<T = any>(filter?: Partial<FilterInput>): FilterQuery<T> | any;
11
+ export declare function generateFindOptions<T = any>(filterArgs: Partial<FilterArgs>): QueryOptions;