@knovator/pagecreator-node 1.1.8 → 1.2.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 (128) hide show
  1. package/package.json +3 -6
  2. package/src/constants/index.ts +30 -0
  3. package/src/controllers/PageController.ts +88 -0
  4. package/src/controllers/TabController.ts +47 -0
  5. package/src/controllers/UserController.ts +69 -0
  6. package/src/controllers/WidgetController.ts +420 -0
  7. package/src/index.ts +59 -0
  8. package/src/models/Item.ts +53 -0
  9. package/src/models/Page.ts +22 -0
  10. package/src/models/SrcSet.ts +16 -0
  11. package/src/models/Tab.ts +28 -0
  12. package/src/models/Widget.ts +65 -0
  13. package/src/models/{index.d.ts → index.ts} +13 -1
  14. package/src/plugins/softDelete.ts +84 -0
  15. package/src/routes/PageRoute.ts +30 -0
  16. package/src/routes/UserRoute.ts +32 -0
  17. package/src/routes/WidgetRoute.ts +77 -0
  18. package/src/services/dataService.ts +475 -0
  19. package/src/services/dbService.ts +102 -0
  20. package/src/types/{IRequest.d.ts → IRequest.ts} +4 -3
  21. package/src/types/{IResponse.d.ts → IResponse.ts} +4 -3
  22. package/src/types/{Router.d.ts → Router.ts} +2 -1
  23. package/src/types/common.ts +172 -0
  24. package/src/types/enums.ts +16 -0
  25. package/src/utils/defaults.ts +41 -0
  26. package/src/utils/helper.ts +285 -0
  27. package/src/utils/redis.ts +57 -0
  28. package/src/utils/responseHandlers.ts +60 -0
  29. package/src/utils/validate.ts +22 -0
  30. package/src/utils/validations/page.ts +52 -0
  31. package/src/utils/validations/tab.ts +26 -0
  32. package/src/utils/validations/user.ts +10 -0
  33. package/src/utils/validations/widget.ts +169 -0
  34. package/src/constants/index.d.ts +0 -20
  35. package/src/constants/index.js +0 -34
  36. package/src/constants/index.js.map +0 -1
  37. package/src/controllers/PageController.d.ts +0 -4
  38. package/src/controllers/PageController.js +0 -84
  39. package/src/controllers/PageController.js.map +0 -1
  40. package/src/controllers/TabController.d.ts +0 -4
  41. package/src/controllers/TabController.js +0 -46
  42. package/src/controllers/TabController.js.map +0 -1
  43. package/src/controllers/UserController.d.ts +0 -2
  44. package/src/controllers/UserController.js +0 -65
  45. package/src/controllers/UserController.js.map +0 -1
  46. package/src/controllers/WidgetController.d.ts +0 -10
  47. package/src/controllers/WidgetController.js +0 -329
  48. package/src/controllers/WidgetController.js.map +0 -1
  49. package/src/index.d.ts +0 -8
  50. package/src/index.js +0 -48
  51. package/src/index.js.map +0 -1
  52. package/src/models/Item.d.ts +0 -30
  53. package/src/models/Item.js +0 -50
  54. package/src/models/Item.js.map +0 -1
  55. package/src/models/Page.d.ts +0 -30
  56. package/src/models/Page.js +0 -19
  57. package/src/models/Page.js.map +0 -1
  58. package/src/models/SrcSet.d.ts +0 -30
  59. package/src/models/SrcSet.js +0 -17
  60. package/src/models/SrcSet.js.map +0 -1
  61. package/src/models/Tab.d.ts +0 -30
  62. package/src/models/Tab.js +0 -28
  63. package/src/models/Tab.js.map +0 -1
  64. package/src/models/Widget.d.ts +0 -30
  65. package/src/models/Widget.js +0 -58
  66. package/src/models/Widget.js.map +0 -1
  67. package/src/models/index.js +0 -19
  68. package/src/models/index.js.map +0 -1
  69. package/src/plugins/softDelete.d.ts +0 -7
  70. package/src/plugins/softDelete.js +0 -64
  71. package/src/plugins/softDelete.js.map +0 -1
  72. package/src/routes/PageRoute.d.ts +0 -3
  73. package/src/routes/PageRoute.js +0 -30
  74. package/src/routes/PageRoute.js.map +0 -1
  75. package/src/routes/UserRoute.d.ts +0 -3
  76. package/src/routes/UserRoute.js +0 -23
  77. package/src/routes/UserRoute.js.map +0 -1
  78. package/src/routes/WidgetRoute.d.ts +0 -3
  79. package/src/routes/WidgetRoute.js +0 -68
  80. package/src/routes/WidgetRoute.js.map +0 -1
  81. package/src/services/dataService.d.ts +0 -9
  82. package/src/services/dataService.js +0 -403
  83. package/src/services/dataService.js.map +0 -1
  84. package/src/services/dbService.d.ts +0 -16
  85. package/src/services/dbService.js +0 -88
  86. package/src/services/dbService.js.map +0 -1
  87. package/src/types/IRequest.js +0 -3
  88. package/src/types/IRequest.js.map +0 -1
  89. package/src/types/IResponse.js +0 -3
  90. package/src/types/IResponse.js.map +0 -1
  91. package/src/types/Router.js +0 -3
  92. package/src/types/Router.js.map +0 -1
  93. package/src/types/common.d.ts +0 -138
  94. package/src/types/common.js +0 -3
  95. package/src/types/common.js.map +0 -1
  96. package/src/types/enums.d.ts +0 -13
  97. package/src/types/enums.js +0 -20
  98. package/src/types/enums.js.map +0 -1
  99. package/src/types/index.js +0 -9
  100. package/src/types/index.js.map +0 -1
  101. package/src/utils/defaults.d.ts +0 -7
  102. package/src/utils/defaults.js +0 -41
  103. package/src/utils/defaults.js.map +0 -1
  104. package/src/utils/helper.d.ts +0 -7
  105. package/src/utils/helper.js +0 -225
  106. package/src/utils/helper.js.map +0 -1
  107. package/src/utils/redis.d.ts +0 -3
  108. package/src/utils/redis.js +0 -59
  109. package/src/utils/redis.js.map +0 -1
  110. package/src/utils/responseHandlers.d.ts +0 -6
  111. package/src/utils/responseHandlers.js +0 -57
  112. package/src/utils/responseHandlers.js.map +0 -1
  113. package/src/utils/validate.d.ts +0 -4
  114. package/src/utils/validate.js +0 -24
  115. package/src/utils/validate.js.map +0 -1
  116. package/src/utils/validations/page.d.ts +0 -7
  117. package/src/utils/validations/page.js +0 -51
  118. package/src/utils/validations/page.js.map +0 -1
  119. package/src/utils/validations/tab.d.ts +0 -6
  120. package/src/utils/validations/tab.js +0 -26
  121. package/src/utils/validations/tab.js.map +0 -1
  122. package/src/utils/validations/user.d.ts +0 -3
  123. package/src/utils/validations/user.js +0 -13
  124. package/src/utils/validations/user.js.map +0 -1
  125. package/src/utils/validations/widget.d.ts +0 -9
  126. package/src/utils/validations/widget.js +0 -151
  127. package/src/utils/validations/widget.js.map +0 -1
  128. /package/src/types/{index.d.ts → index.ts} +0 -0
@@ -0,0 +1,475 @@
1
+ import { AggregateOptions, Models } from 'mongoose';
2
+ import {
3
+ AddSrcSetsToItems,
4
+ appendCollectionData,
5
+ getCollectionModal,
6
+ } from '../utils/helper';
7
+ import { setRedisValue, deleteRedisValue } from '../utils/redis';
8
+ import { defaults, commonExcludedFields } from '../utils/defaults';
9
+ import { IPageSchema, IWidgetSchema } from '../types';
10
+
11
+ const getAggregationQuery = ({
12
+ collectionName,
13
+ ids,
14
+ }: {
15
+ collectionName: string;
16
+ ids: string[];
17
+ }) => {
18
+ const collectionConfig = defaults.collections.find(
19
+ (c) => c.collectionName === collectionName
20
+ );
21
+ const aggregateQueryItem: AggregateOptions[] = [];
22
+ if (
23
+ Array.isArray(collectionConfig?.aggregations) &&
24
+ collectionConfig?.aggregations.length
25
+ ) {
26
+ aggregateQueryItem.push(...collectionConfig.aggregations);
27
+ }
28
+ aggregateQueryItem.push(
29
+ {
30
+ $match: {
31
+ _id: {
32
+ $in: ids,
33
+ },
34
+ ...(collectionConfig?.match || {}),
35
+ },
36
+ },
37
+ { $addFields: { __order: { $indexOfArray: [ids, '$_id'] } } },
38
+ { $sort: { __order: 1 } }
39
+ );
40
+ return aggregateQueryItem;
41
+ };
42
+
43
+ export const getWidgetDataDB = async (code: string, models: Models) => {
44
+ const { Widget } = models;
45
+ const widgetDataArr = (await Widget.aggregate([
46
+ {
47
+ $match: {
48
+ isDeleted: false,
49
+ isActive: true,
50
+ code,
51
+ },
52
+ },
53
+ {
54
+ // Get only the fields that are not excluded
55
+ $project: {
56
+ ...commonExcludedFields,
57
+ },
58
+ },
59
+ {
60
+ // Get Items data
61
+ $lookup: {
62
+ from: 'items',
63
+ let: { widget: '$_id' },
64
+ pipeline: [
65
+ {
66
+ $match: {
67
+ $expr: {
68
+ $eq: ['$widgetId', '$$widget'],
69
+ },
70
+ isDeleted: false,
71
+ },
72
+ },
73
+ ...(defaults.languages && defaults.languages?.length > 0
74
+ ? defaults.languages.reduce((arr: any[], lng) => {
75
+ arr.push(
76
+ {
77
+ $lookup: {
78
+ from: 'file',
79
+ let: { img: { $toObjectId: `$imgs.${lng.code}` } },
80
+ as: `images.${lng.code}`,
81
+ pipeline: [
82
+ {
83
+ $match: {
84
+ $expr: {
85
+ $eq: ['$_id', '$$img'],
86
+ },
87
+ },
88
+ },
89
+ {
90
+ $project: {
91
+ _id: 1,
92
+ uri: 1,
93
+ },
94
+ },
95
+ ],
96
+ },
97
+ },
98
+ {
99
+ $unwind: {
100
+ path: `$images.${lng.code}`,
101
+ preserveNullAndEmptyArrays: true,
102
+ },
103
+ }
104
+ );
105
+ return arr;
106
+ }, [])
107
+ : [
108
+ {
109
+ $lookup: {
110
+ from: 'file',
111
+ let: { img: '$img' },
112
+ as: 'image',
113
+ pipeline: [
114
+ {
115
+ $match: {
116
+ $expr: {
117
+ $eq: ['$_id', '$$img'],
118
+ },
119
+ },
120
+ },
121
+ {
122
+ $project: {
123
+ _id: 1,
124
+ uri: 1,
125
+ },
126
+ },
127
+ ],
128
+ },
129
+ },
130
+ {
131
+ $unwind: {
132
+ path: '$image',
133
+ preserveNullAndEmptyArrays: true,
134
+ },
135
+ },
136
+ ]),
137
+ {
138
+ $project: {
139
+ sequence: 0,
140
+ imgs: 0,
141
+ ...commonExcludedFields,
142
+ },
143
+ },
144
+ // {
145
+ // $lookup: {
146
+ // from: 'srcsets',
147
+ // let: { item: '$_id' },
148
+ // as: 'srcset',
149
+ // pipeline: [
150
+ // {
151
+ // $match: {
152
+ // $expr: {
153
+ // $eq: ['$itemId', '$$item'],
154
+ // },
155
+ // },
156
+ // },
157
+ // {
158
+ // $project: {
159
+ // ...commonExcludedFields,
160
+ // _id: 0,
161
+ // itemId: 0,
162
+ // },
163
+ // },
164
+ // ],
165
+ // },
166
+ // },
167
+ ],
168
+ as: 'items',
169
+ },
170
+ },
171
+ ])) as Array<IWidgetSchema>;
172
+
173
+ if (!widgetDataArr.length) {
174
+ return null;
175
+ }
176
+ const widgetData = widgetDataArr[0];
177
+
178
+ if (
179
+ widgetData.collectionName &&
180
+ widgetData.collectionItems &&
181
+ widgetData.collectionItems.length > 0
182
+ ) {
183
+ const aggregateQueryItem = getAggregationQuery({
184
+ collectionName: widgetData.collectionName,
185
+ ids: widgetData.collectionItems,
186
+ });
187
+ const collectionModal: any = getCollectionModal(widgetData.collectionName, models);
188
+ const collectionItems = await collectionModal.aggregate(aggregateQueryItem);
189
+ widgetData.collectionItems = collectionItems;
190
+ }
191
+ if (
192
+ widgetData.collectionName &&
193
+ widgetData.tabs &&
194
+ widgetData.tabs.length > 0
195
+ ) {
196
+ const tabCollectionItemIds = widgetData.tabs.reduce(
197
+ (acc: string[], tabItem: any) => {
198
+ acc.push(...tabItem.collectionItems);
199
+ return acc;
200
+ },
201
+ []
202
+ );
203
+ const aggregateQueryItem = getAggregationQuery({
204
+ collectionName: widgetData.collectionName,
205
+ ids: tabCollectionItemIds,
206
+ });
207
+
208
+ const collectionModal: any = getCollectionModal(widgetData.collectionName, models);
209
+ const collectionItems: any = await collectionModal.aggregate(
210
+ aggregateQueryItem
211
+ );
212
+ // converting colleciton items to obj to better access them
213
+ const collectionItemsObj = collectionItems.reduce((acc: any, item: any) => {
214
+ acc[item._id] = item;
215
+ return acc;
216
+ }, {});
217
+ widgetData.tabs = widgetData.tabs.map((tabItem) => {
218
+ return {
219
+ name: tabItem.name,
220
+ names: tabItem.names,
221
+ collectionItems: tabItem.collectionItems.map(
222
+ (collectionId) => collectionItemsObj[collectionId]
223
+ ),
224
+ };
225
+ });
226
+ }
227
+ AddSrcSetsToItems(widgetData);
228
+ return widgetData;
229
+ };
230
+
231
+ export const updateRedisWidget = async (code: string, models: Models) => {
232
+ const widgetData = await getWidgetDataDB(code, models);
233
+ if (widgetData) {
234
+ await setRedisValue(`widgetData_${code}`, widgetData as unknown as JSON);
235
+ }
236
+ };
237
+
238
+ export const updateWidgetPagesData = async (
239
+ widgetIds: string[],
240
+ models: Models
241
+ ) => {
242
+ const { Page } = models;
243
+ const pageCodes = await Page.find(
244
+ {
245
+ widgets: {
246
+ $in: widgetIds,
247
+ },
248
+ },
249
+ 'code'
250
+ ).distinct('code');
251
+ if (pageCodes.length) {
252
+ pageCodes.forEach((code) => {
253
+ deleteRedisValue(`pageData_${code}`);
254
+ });
255
+ }
256
+ };
257
+
258
+ export const getPageDataDB = async (code: string, models: Models) => {
259
+ const { Page } = models;
260
+ const pageData: any = (await Page.aggregate([
261
+ {
262
+ $match: {
263
+ isDeleted: false,
264
+ code: code,
265
+ },
266
+ },
267
+ {
268
+ $project: {
269
+ isDeleted: 0,
270
+ deletedAt: 0,
271
+ __v: 0,
272
+ },
273
+ },
274
+ {
275
+ $lookup: {
276
+ from: 'widgets',
277
+ let: { widgets: '$widgets' },
278
+ pipeline: [
279
+ {
280
+ $match: {
281
+ $expr: {
282
+ $in: ['$_id', '$$widgets'],
283
+ },
284
+ isDeleted: false,
285
+ isActive: true,
286
+ },
287
+ },
288
+ {
289
+ $project: {
290
+ widgetId: 0,
291
+ sequence: 0,
292
+ ...commonExcludedFields,
293
+ },
294
+ },
295
+ {
296
+ $lookup: {
297
+ from: 'items',
298
+ let: { widget: '$_id' },
299
+ pipeline: [
300
+ {
301
+ $match: {
302
+ $expr: {
303
+ $eq: ['$widgetId', '$$widget'],
304
+ },
305
+ isDeleted: false,
306
+ },
307
+ },
308
+ ...(defaults.languages && defaults.languages?.length > 0
309
+ ? defaults.languages.reduce((arr: any[], lng) => {
310
+ arr.push(
311
+ {
312
+ $lookup: {
313
+ from: 'file',
314
+ let: { img: { $toObjectId: `$imgs.${lng.code}` } },
315
+ as: `images.${lng.code}`,
316
+ pipeline: [
317
+ {
318
+ $match: {
319
+ $expr: {
320
+ $eq: ['$_id', '$$img'],
321
+ },
322
+ },
323
+ },
324
+ {
325
+ $project: {
326
+ _id: 1,
327
+ uri: 1,
328
+ },
329
+ },
330
+ ],
331
+ },
332
+ },
333
+ {
334
+ $unwind: {
335
+ path: `$images.${lng.code}`,
336
+ preserveNullAndEmptyArrays: true,
337
+ },
338
+ }
339
+ );
340
+ return arr;
341
+ }, [])
342
+ : [
343
+ {
344
+ $lookup: {
345
+ from: 'file',
346
+ let: { img: '$img' },
347
+ as: 'image',
348
+ pipeline: [
349
+ {
350
+ $match: {
351
+ $expr: {
352
+ $eq: ['$_id', '$$img'],
353
+ },
354
+ },
355
+ },
356
+ {
357
+ $project: {
358
+ _id: 1,
359
+ uri: 1,
360
+ },
361
+ },
362
+ ],
363
+ },
364
+ },
365
+ {
366
+ $unwind: {
367
+ path: '$image',
368
+ preserveNullAndEmptyArrays: true,
369
+ },
370
+ },
371
+ ]),
372
+ {
373
+ $project: {
374
+ sequence: 0,
375
+ imgs: 0,
376
+ ...commonExcludedFields,
377
+ },
378
+ },
379
+ // {
380
+ // $lookup: {
381
+ // from: 'srcsets',
382
+ // let: { item: '$_id' },
383
+ // as: 'srcset',
384
+ // pipeline: [
385
+ // {
386
+ // $match: {
387
+ // $expr: {
388
+ // $eq: ['$itemId', '$$item'],
389
+ // },
390
+ // },
391
+ // },
392
+ // {
393
+ // $project: {
394
+ // ...commonExcludedFields,
395
+ // _id: 0,
396
+ // itemId: 0,
397
+ // },
398
+ // },
399
+ // ],
400
+ // },
401
+ // },
402
+ ],
403
+ as: 'items',
404
+ },
405
+ },
406
+ ],
407
+ as: 'widgetsData',
408
+ },
409
+ },
410
+ ])) as Array<IPageSchema>;
411
+
412
+ if (!pageData.length) {
413
+ return null;
414
+ }
415
+ pageData[0].widgetsData = await appendCollectionData(pageData[0].widgetsData, models);
416
+ if (
417
+ Array.isArray(pageData[0].widgetsData) &&
418
+ pageData[0].widgetsData.length > 0
419
+ ) {
420
+ pageData[0].widgetsData.forEach((widget: IWidgetSchema) => {
421
+ AddSrcSetsToItems(widget);
422
+ });
423
+ }
424
+ pageData[0].widgetsData = pageData[0].widgetsData.reduce(
425
+ (acc: any, widgetItem: any) => {
426
+ acc[widgetItem._id] = widgetItem;
427
+ return acc;
428
+ },
429
+ []
430
+ );
431
+ pageData[0].widgets = pageData[0].widgets
432
+ .map((widgetId: string) => pageData[0].widgetsData[widgetId])
433
+ .filter(Boolean);
434
+ delete pageData[0].widgetsData;
435
+ return pageData[0];
436
+ };
437
+
438
+ export const updateRedisPage = async (code: string, models: Models) => {
439
+ const pageData = await getPageDataDB(code, models);
440
+ if (pageData) {
441
+ await setRedisValue(`pageData_${code}`, pageData);
442
+ }
443
+ };
444
+
445
+ export const handleUpdateData = async (
446
+ collectionName: string,
447
+ itemId: string | string[],
448
+ models: Models
449
+ ) => {
450
+ if (!models) throw new Error('models is required');
451
+ const { Widget } = models;
452
+ const widgets = await Widget.find(
453
+ {
454
+ collectionName: collectionName,
455
+ collectionItems: {
456
+ $in: Array.isArray(itemId) ? itemId : [itemId],
457
+ },
458
+ },
459
+ 'code _id'
460
+ ).lean();
461
+ if (widgets.length) {
462
+ updateWidgetPagesData(
463
+ widgets.map((widget: any) => widget._id),
464
+ models
465
+ );
466
+ widgets.forEach((widget) => {
467
+ deleteRedisValue(`widgetData_${widget['code']}`);
468
+ });
469
+ }
470
+ };
471
+
472
+ export const handleResetData = (type: 'widget' | 'page', code: string) => {
473
+ if ((type === 'widget' || type === 'page') && code)
474
+ deleteRedisValue(`${type}_${code}`);
475
+ };
@@ -0,0 +1,102 @@
1
+ import {
2
+ Model,
3
+ FilterQuery,
4
+ QueryOptions,
5
+ ProjectionType,
6
+ HydratedDocument,
7
+ QueryWithHelpers,
8
+ } from 'mongoose';
9
+ import { EntityType, IModel, ReturnDocument } from '../types';
10
+
11
+ // create
12
+ export async function create<T extends EntityType>(
13
+ Modal: Model<T>,
14
+ data: Partial<T>
15
+ ): Promise<ReturnDocument> {
16
+ const modalInstance = new Modal(data);
17
+ return await modalInstance.save();
18
+ }
19
+ // update
20
+ export async function update<T extends EntityType>(
21
+ Modal: Model<T>,
22
+ query: FilterQuery<EntityType>,
23
+ data: Partial<T>
24
+ ): Promise<T | undefined> {
25
+ await getOne(Modal, query);
26
+ const result = await Modal.findOneAndUpdate(query, data, { new: true });
27
+ return result || undefined;
28
+ }
29
+ // soft-delete
30
+ export async function remove<T extends EntityType>(
31
+ Modal: Model<T>,
32
+ query: FilterQuery<EntityType>
33
+ ): Promise<T | undefined> {
34
+ const modalInstance = await getOne(Modal, query);
35
+ await modalInstance.remove();
36
+ return modalInstance;
37
+ }
38
+ // delete-all
39
+ export async function deleteAll<T extends EntityType>(Modal: Model<T>, query: FilterQuery<T>) {
40
+ return Modal.deleteMany(query);
41
+ }
42
+ // get-all
43
+ export function getAll<T extends EntityType>(
44
+ Modal: Model<T>,
45
+ query: FilterQuery<EntityType> = {},
46
+ options?: QueryOptions<EntityType>,
47
+ projection?: ProjectionType<EntityType>
48
+ // eslint-disable-next-line @typescript-eslint/ban-types
49
+ ): QueryWithHelpers<Array<T>, T, {}, T> {
50
+ return Modal.find(query, projection, options);
51
+ }
52
+ // list
53
+ export async function list<T extends EntityType>(
54
+ Modal: IModel<T>,
55
+ where: FilterQuery<T>,
56
+ options: QueryOptions<T>
57
+ ): Promise<ReturnDocument[]> {
58
+ try {
59
+ const documents = Modal.paginate(where, options);
60
+ return documents;
61
+ } catch (error) {
62
+ throw new Error((error as Error).message);
63
+ }
64
+ }
65
+ // get-one
66
+ export async function getOne<T extends EntityType>(
67
+ Modal: Model<T>,
68
+ query: FilterQuery<EntityType>,
69
+ projection?: ProjectionType<EntityType>
70
+ ): Promise<HydratedDocument<T>> {
71
+ const modalInstance: HydratedDocument<T> | null = await Modal.findOne(
72
+ query,
73
+ projection
74
+ );
75
+ if (!modalInstance)
76
+ throw new Error(`Record not found ${Modal.name ? `in ${Modal.name}` : ''}`);
77
+
78
+ return modalInstance;
79
+ }
80
+ // bulk-insert
81
+ export async function bulkInsert<T extends EntityType>(Modal: Model<T>, docs: T[]): Promise<ReturnDocument[]> {
82
+ return await Modal.insertMany(docs);
83
+ }
84
+
85
+ export async function checkUnique<T extends EntityType>({
86
+ Modal,
87
+ uniqueField,
88
+ errorMessage,
89
+ value
90
+ }: {
91
+ Modal: Model<T>,
92
+ uniqueField: keyof T,
93
+ value: any,
94
+ errorMessage: string
95
+ }): Promise<void> {
96
+ const query: FilterQuery<T> = { [uniqueField]: value } as FilterQuery<T>;
97
+ let result;
98
+ try {
99
+ result = await getOne(Modal, query);
100
+ } catch (error) {}
101
+ if(result) throw new Error(errorMessage)
102
+ }
@@ -1,6 +1,7 @@
1
1
  import { Request } from 'express';
2
+
2
3
  export interface IRequest extends Request {
3
- i18n?: {
4
- t: (key: string) => string;
5
- };
4
+ i18n?: {
5
+ t: (key: string) => string;
6
+ };
6
7
  }
@@ -1,6 +1,7 @@
1
1
  import { Response } from 'express';
2
+
2
3
  export interface IResponse extends Response {
3
- message?: string;
4
- data?: unknown;
5
- code?: number;
4
+ message?: string;
5
+ data?: unknown;
6
+ code?: number;
6
7
  }
@@ -1,4 +1,5 @@
1
1
  import { Router } from 'express';
2
+
2
3
  export interface IRouter extends Router {
3
- descriptor: (text: string) => void;
4
+ descriptor: (text: string) => void;
4
5
  }