@lyxa.ai/core 1.0.263 → 1.0.265

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 (54) hide show
  1. package/dist/libraries/mongo/models/banner.model.js +3 -72
  2. package/dist/libraries/mongo/models/banner.model.js.map +1 -1
  3. package/dist/libraries/mongo/models/cancellation-reason.model.d.ts +2 -2
  4. package/dist/libraries/mongo/models/cancellation-reason.model.js +12 -60
  5. package/dist/libraries/mongo/models/cancellation-reason.model.js.map +1 -1
  6. package/dist/libraries/mongo/models/dish.model.js +4 -22
  7. package/dist/libraries/mongo/models/dish.model.js.map +1 -1
  8. package/dist/libraries/mongo/models/faq.model.js +2 -21
  9. package/dist/libraries/mongo/models/faq.model.js.map +1 -1
  10. package/dist/libraries/mongo/models/filter-container.model.d.ts +1 -1
  11. package/dist/libraries/mongo/models/filter-container.model.js +11 -27
  12. package/dist/libraries/mongo/models/filter-container.model.js.map +1 -1
  13. package/dist/libraries/mongo/models/list-container.model.d.ts +5 -3
  14. package/dist/libraries/mongo/models/list-container.model.js +25 -34
  15. package/dist/libraries/mongo/models/list-container.model.js.map +1 -1
  16. package/dist/libraries/mongo/models/product.model.js +5 -23
  17. package/dist/libraries/mongo/models/product.model.js.map +1 -1
  18. package/dist/libraries/mongo/models/service-promotion.model.d.ts +1 -1
  19. package/dist/libraries/mongo/models/service-promotion.model.js +2 -2
  20. package/dist/libraries/mongo/models/service-promotion.model.js.map +1 -1
  21. package/dist/libraries/mongo/models/shop-category.model.js +4 -22
  22. package/dist/libraries/mongo/models/shop-category.model.js.map +1 -1
  23. package/dist/libraries/mongo/models/shop.model.js +2 -32
  24. package/dist/libraries/mongo/models/shop.model.js.map +1 -1
  25. package/dist/libraries/mongo/models/support-reason.model.d.ts +2 -2
  26. package/dist/libraries/mongo/models/support-reason.model.js +10 -58
  27. package/dist/libraries/mongo/models/support-reason.model.js.map +1 -1
  28. package/dist/libraries/mongo/models/tag.model.js +3 -72
  29. package/dist/libraries/mongo/models/tag.model.js.map +1 -1
  30. package/dist/libraries/mongo/models/user-app-section-setting.model.js +6 -21
  31. package/dist/libraries/mongo/models/user-app-section-setting.model.js.map +1 -1
  32. package/dist/libraries/mongo/utilities/shopHooks.d.ts +9 -0
  33. package/dist/libraries/mongo/utilities/shopHooks.js +16 -0
  34. package/dist/libraries/mongo/utilities/shopHooks.js.map +1 -0
  35. package/dist/libraries/mongo/utilities/sortingOrderHooks.d.ts +14 -0
  36. package/dist/libraries/mongo/utilities/sortingOrderHooks.js +58 -0
  37. package/dist/libraries/mongo/utilities/sortingOrderHooks.js.map +1 -0
  38. package/dist/types/README.md +1 -1
  39. package/dist/types/package.json +1 -1
  40. package/dist/types/utilities/enum.d.ts +1 -1
  41. package/dist/types/utilities/enum.js +1 -1
  42. package/dist/types/utilities/enum.js.map +1 -1
  43. package/dist/types/utilities/validation/common-validation.js +1 -1
  44. package/dist/types/utilities/validation/common-validation.js.map +1 -1
  45. package/dist/utilities/enum.d.ts +1 -1
  46. package/dist/utilities/enum.js +1 -1
  47. package/dist/utilities/enum.js.map +1 -1
  48. package/dist/utilities/map.js +1 -1
  49. package/dist/utilities/map.js.map +1 -1
  50. package/dist/utilities/sorting.js +5 -1
  51. package/dist/utilities/sorting.js.map +1 -1
  52. package/dist/utilities/validation/common-validation.js +1 -1
  53. package/dist/utilities/validation/common-validation.js.map +1 -1
  54. package/package.json +1 -1
@@ -18,6 +18,7 @@ const product_model_1 = require("./product.model");
18
18
  const zone_model_1 = require("./zone.model");
19
19
  const list_container_model_1 = require("./list-container.model");
20
20
  const _1 = require(".");
21
+ const sortingOrderHooks_1 = require("../utilities/sortingOrderHooks");
21
22
  let Banner = class Banner extends defaultClasses_1.TimeStamps {
22
23
  title;
23
24
  image;
@@ -94,81 +95,11 @@ __decorate([
94
95
  exports.Banner = Banner = __decorate([
95
96
  (0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'banners' } }),
96
97
  (0, typegoose_1.pre)('save', async function (next) {
97
- if (this.isNew || typeof this.sortingOrder === 'undefined') {
98
- try {
99
- const maxSortingOrder = await _1.BannerModel.aggregate([
100
- {
101
- $match: {
102
- itemType: this.itemType,
103
- status: enum_1.Status.ACTIVE,
104
- deletedAt: null,
105
- },
106
- },
107
- {
108
- $group: {
109
- _id: null,
110
- maxSortingOrder: { $max: '$sortingOrder' },
111
- },
112
- },
113
- ]).exec();
114
- this.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;
115
- }
116
- catch (error) {
117
- return next(error);
118
- }
119
- }
120
- if (this.isModified('status') && this.status === enum_1.Status.ACTIVE) {
121
- const original = await _1.BannerModel.findById(this._id);
122
- if (original && original.status !== enum_1.Status.ACTIVE) {
123
- try {
124
- const maxSortingOrder = await _1.BannerModel.aggregate([
125
- {
126
- $match: {
127
- itemType: this.itemType,
128
- status: enum_1.Status.ACTIVE,
129
- deletedAt: null,
130
- },
131
- },
132
- {
133
- $group: {
134
- _id: null,
135
- maxSortingOrder: { $max: '$sortingOrder' },
136
- },
137
- },
138
- ]).exec();
139
- this.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;
140
- }
141
- catch (error) {
142
- return next(error);
143
- }
144
- }
145
- }
98
+ await sortingOrderHooks_1.handlePreSaveForSortingWithStatus.call(this, _1.BannerModel, { itemType: this.itemType });
146
99
  next();
147
100
  }),
148
101
  (0, typegoose_1.pre)('findOneAndUpdate', async function (next) {
149
- const update = this.getUpdate();
150
- if (update?.status === enum_1.Status.ACTIVE) {
151
- const banner = await this.model.findOne(this.getQuery());
152
- if (banner && banner.status !== enum_1.Status.ACTIVE) {
153
- const maxSortingOrder = await _1.BannerModel.aggregate([
154
- {
155
- $match: {
156
- itemType: banner.itemType,
157
- status: enum_1.Status.ACTIVE,
158
- deletedAt: null,
159
- },
160
- },
161
- {
162
- $group: {
163
- _id: null,
164
- maxSortingOrder: { $max: '$sortingOrder' },
165
- },
166
- },
167
- ]).exec();
168
- update.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;
169
- this.setUpdate(update);
170
- }
171
- }
102
+ await sortingOrderHooks_1.handlePreUpdateForSortingWithStatus.call(this, _1.BannerModel, ['itemType']);
172
103
  next();
173
104
  }),
174
105
  (0, typegoose_1.index)({ title: 1 }, { unique: true, partialFilterExpression: { deletedAt: null } })
@@ -1 +1 @@
1
- {"version":3,"file":"banner.model.js","sourceRoot":"/","sources":["libraries/mongo/models/banner.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA2E;AAC3E,4EAAqE;AACrE,kDAOiC;AACjC,6CAAoC;AACpC,mDAA0C;AAC1C,6CAAoC;AACpC,iEAAuD;AACvD,wBAAgC;AAqGzB,IAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,2BAAU;IAE9B,KAAK,CAAU;IAGf,KAAK,CAAU;IAGf,QAAQ,CAA0B;IAGlC,MAAM,CAAU;IAGhB,UAAU,CAAkB;IAG5B,KAAK,CAAe;IAGpB,WAAW,CAAW;IAGtB,SAAS,CAAmB;IAG5B,QAAQ,CAAkB;IAG1B,IAAI,CAAU;IAGd,IAAI,CAAa;IAGjB,OAAO,CAAgB;IAGvB,aAAa,CAAsB;IAGnC,YAAY,CAAU;CAC7B,CAAA;AA1CY,wBAAM;AAEX;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;;qCAC5C;AAGf;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;qCACjB;AAGf;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,6BAAsB,EAAE,CAAC;;wCAC5B;AAGlC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAA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,CAAC,CAAC;YACxB,CAAC;QACF,CAAC;QAED,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;IACD,IAAA,iBAAK,EAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;GACvE,MAAM,CA0ClB","sourcesContent":["import { index, modelOptions, pre, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport {\n\tBannerClickType,\n\tBannerLinkType,\n\tBannerUserType,\n\tItemType,\n\tStatus,\n\tUserAppSectionItemType,\n} from '../../../utilities/enum';\nimport { Shop } from './shop.model';\nimport { Product } from './product.model';\nimport { Zone } from './zone.model';\nimport { ListContainer } from './list-container.model';\nimport { BannerModel } from '.';\nimport { Query } from 'mongoose';\n\n@modelOptions({ schemaOptions: { collection: 'banners' } })\n@pre<Banner>('save', async function (next) {\n\t// Only set sortingOrder if it's a new document or sortingOrder is not set\n\tif (this.isNew || typeof this.sortingOrder === 'undefined') {\n\t\ttry {\n\t\t\t// Find the maximum sortingOrder that aren't deleted\n\t\t\tconst maxSortingOrder = await BannerModel.aggregate<{ maxSortingOrder: number }>([\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\titemType: this.itemType,\n\t\t\t\t\t\tstatus: Status.ACTIVE,\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: null,\n\t\t\t\t\t\tmaxSortingOrder: { $max: '$sortingOrder' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]).exec();\n\n\t\t\t// Set the new sortingOrder to max + 1 (or 0 if no items found)\n\t\t\tthis.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;\n\t\t} catch (error) {\n\t\t\treturn next(error as Error);\n\t\t}\n\t}\n\n\t// Add this code to handle status change from inactive to active\n\tif (this.isModified('status') && this.status === Status.ACTIVE) {\n\t\t// Check if status was previously inactive\n\t\tconst original = await BannerModel.findById(this._id);\n\t\tif (original && original.status !== Status.ACTIVE) {\n\t\t\ttry {\n\t\t\t\t// Find the maximum sortingOrder for active tags with the same itemType\n\t\t\t\tconst maxSortingOrder = await BannerModel.aggregate<{ maxSortingOrder: number }>([\n\t\t\t\t\t{\n\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\titemType: this.itemType,\n\t\t\t\t\t\t\tstatus: Status.ACTIVE,\n\t\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t$group: {\n\t\t\t\t\t\t\t_id: null,\n\t\t\t\t\t\t\tmaxSortingOrder: { $max: '$sortingOrder' },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t]).exec();\n\n\t\t\t\t// Set the sortingOrder to max + 1 (or 0 if no items found)\n\t\t\t\tthis.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;\n\t\t\t} catch (error) {\n\t\t\t\treturn next(error as Error);\n\t\t\t}\n\t\t}\n\t}\n\n\tnext();\n})\n@pre<Banner>('findOneAndUpdate', async function (this: Query<any, Banner>, next) {\n\tconst update = this.getUpdate() as any;\n\n\tif (update?.status === Status.ACTIVE) {\n\t\t// Get current document (before update)\n\t\tconst banner = await this.model.findOne(this.getQuery());\n\n\t\tif (banner && banner.status !== Status.ACTIVE) {\n\t\t\t// Find the maximum sortingOrder for active tags with the same itemType\n\t\t\tconst maxSortingOrder = await BannerModel.aggregate<{ maxSortingOrder: number }>([\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\titemType: banner.itemType,\n\t\t\t\t\t\tstatus: Status.ACTIVE,\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: null,\n\t\t\t\t\t\tmaxSortingOrder: { $max: '$sortingOrder' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]).exec();\n\n\t\t\t// Set the sortingOrder to max + 1 (or 0 if no items found)\n\t\t\tupdate.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;\n\n\t\t\t// Inject the new sortingOrder into the update\n\t\t\tthis.setUpdate(update);\n\t\t}\n\t}\n\n\tnext();\n})\n@index({ title: 1 }, { unique: true, partialFilterExpression: { deletedAt: null } })\nexport class Banner extends TimeStamps {\n\t@prop({ required: true, type: String, trim: true, maxlength: 50 })\n\tpublic title!: string;\n\n\t@prop({ required: true, type: String })\n\tpublic image!: string;\n\n\t@prop({ required: true, type: String, enum: UserAppSectionItemType })\n\tpublic itemType!: UserAppSectionItemType;\n\n\t@prop({ type: String, enum: Status, default: Status.ACTIVE })\n\tpublic status?: Status;\n\n\t@prop({ type: String, enum: BannerUserType, default: BannerUserType.ALL })\n\tpublic visibility?: BannerUserType;\n\n\t@prop({ ref: () => Zone, default: [] })\n\tpublic zones?: Ref<Zone>[];\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isClickable?: boolean;\n\n\t@prop({ type: String, enum: BannerClickType })\n\tpublic clickType?: BannerClickType;\n\n\t@prop({ type: String, enum: BannerLinkType })\n\tpublic linkType?: BannerLinkType;\n\n\t@prop({ type: String, trim: true })\n\tpublic link?: string;\n\n\t@prop({ ref: () => Shop })\n\tpublic shop?: Ref<Shop>;\n\n\t@prop({ ref: () => Product })\n\tpublic product?: Ref<Product>;\n\n\t@prop({ ref: () => ListContainer })\n\tpublic listContainer?: Ref<ListContainer>;\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n}\n"]}
1
+ {"version":3,"file":"banner.model.js","sourceRoot":"/","sources":["libraries/mongo/models/banner.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA2E;AAC3E,4EAAqE;AACrE,kDAO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C;IACR,CAAC,CAAC;IACD,IAAA,iBAAK,EAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;GACvE,MAAM,CA0ClB","sourcesContent":["import { index, modelOptions, pre, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport {\n\tBannerClickType,\n\tBannerLinkType,\n\tBannerUserType,\n\tItemType,\n\tStatus,\n\tUserAppSectionItemType,\n} from '../../../utilities/enum';\nimport { Shop } from './shop.model';\nimport { Product } from './product.model';\nimport { Zone } from './zone.model';\nimport { ListContainer } from './list-container.model';\nimport { BannerModel } from '.';\nimport { Query } from 'mongoose';\nimport {\n\thandlePreSaveForSortingWithStatus,\n\thandlePreUpdateForSortingWithStatus,\n} from '../utilities/sortingOrderHooks';\n\n@modelOptions({ schemaOptions: { collection: 'banners' } })\n@pre<Banner>('save', async function (next) {\n\tawait handlePreSaveForSortingWithStatus.call(this, BannerModel, { itemType: this.itemType });\n\n\tnext();\n})\n@pre<Banner>('findOneAndUpdate', async function (this: Query<any, Banner>, next) {\n\tawait handlePreUpdateForSortingWithStatus.call(this, BannerModel, ['itemType']);\n\n\tnext();\n})\n@index({ title: 1 }, { unique: true, partialFilterExpression: { deletedAt: null } })\nexport class Banner extends TimeStamps {\n\t@prop({ required: true, type: String, trim: true, maxlength: 50 })\n\tpublic title!: string;\n\n\t@prop({ required: true, type: String })\n\tpublic image!: string;\n\n\t@prop({ required: true, type: String, enum: UserAppSectionItemType })\n\tpublic itemType!: UserAppSectionItemType;\n\n\t@prop({ type: String, enum: Status, default: Status.ACTIVE })\n\tpublic status?: Status;\n\n\t@prop({ type: String, enum: BannerUserType, default: BannerUserType.ALL })\n\tpublic visibility?: BannerUserType;\n\n\t@prop({ ref: () => Zone, default: [] })\n\tpublic zones?: Ref<Zone>[];\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isClickable?: boolean;\n\n\t@prop({ type: String, enum: BannerClickType })\n\tpublic clickType?: BannerClickType;\n\n\t@prop({ type: String, enum: BannerLinkType })\n\tpublic linkType?: BannerLinkType;\n\n\t@prop({ type: String, trim: true })\n\tpublic link?: string;\n\n\t@prop({ ref: () => Shop })\n\tpublic shop?: Ref<Shop>;\n\n\t@prop({ ref: () => Product })\n\tpublic product?: Ref<Product>;\n\n\t@prop({ ref: () => ListContainer })\n\tpublic listContainer?: Ref<ListContainer>;\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
2
- import { SettingsReasonStatus, CancellationReasonTypeEnum } from '../../../utilities/enum';
2
+ import { CancellationReasonTypeEnum, Status } from '../../../utilities/enum';
3
3
  export declare class CancellationReason extends TimeStamps {
4
4
  reason: string;
5
5
  reasonType: CancellationReasonTypeEnum;
6
- status: SettingsReasonStatus;
6
+ status: Status;
7
7
  sortingOrder?: number;
8
8
  }
@@ -1,43 +1,10 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
2
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
23
7
  };
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
8
  var __metadata = (this && this.__metadata) || function (k, v) {
42
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
10
  };
@@ -46,6 +13,8 @@ exports.CancellationReason = void 0;
46
13
  const typegoose_1 = require("@typegoose/typegoose");
47
14
  const defaultClasses_1 = require("@typegoose/typegoose/lib/defaultClasses");
48
15
  const enum_1 = require("../../../utilities/enum");
16
+ const _1 = require(".");
17
+ const sortingOrderHooks_1 = require("../utilities/sortingOrderHooks");
49
18
  let CancellationReason = class CancellationReason extends defaultClasses_1.TimeStamps {
50
19
  reason;
51
20
  reasonType;
@@ -62,41 +31,24 @@ __decorate([
62
31
  __metadata("design:type", String)
63
32
  ], CancellationReason.prototype, "reasonType", void 0);
64
33
  __decorate([
65
- (0, typegoose_1.prop)({ required: true, enum: enum_1.SettingsReasonStatus }),
34
+ (0, typegoose_1.prop)({ required: true, enum: enum_1.Status }),
66
35
  __metadata("design:type", String)
67
36
  ], CancellationReason.prototype, "status", void 0);
68
37
  __decorate([
69
- (0, typegoose_1.prop)(),
38
+ (0, typegoose_1.prop)({ type: Number }),
70
39
  __metadata("design:type", Number)
71
40
  ], CancellationReason.prototype, "sortingOrder", void 0);
72
41
  exports.CancellationReason = CancellationReason = __decorate([
73
42
  (0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'cancellationReasons' } }),
74
43
  (0, typegoose_1.pre)('save', async function (next) {
75
- try {
76
- const { CancellationReasonModel } = await Promise.resolve().then(() => __importStar(require('.')));
77
- if (this.isNew || typeof this.sortingOrder === 'undefined') {
78
- const [result] = await CancellationReasonModel.aggregate([
79
- {
80
- $match: {
81
- reasonType: this.reasonType,
82
- status: enum_1.SettingsReasonStatus.ACTIVE,
83
- deletedAt: null,
84
- },
85
- },
86
- {
87
- $group: {
88
- _id: null,
89
- maxSortingOrder: { $max: '$sortingOrder' },
90
- },
91
- },
92
- ]).exec();
93
- this.sortingOrder = (result?.maxSortingOrder ?? -1) + 1;
94
- }
95
- next();
96
- }
97
- catch (error) {
98
- next(error);
99
- }
44
+ await sortingOrderHooks_1.handlePreSaveForSortingWithStatus.call(this, _1.CancellationReasonModel, {
45
+ reasonType: this.reasonType,
46
+ });
47
+ next();
48
+ }),
49
+ (0, typegoose_1.pre)('findOneAndUpdate', async function (next) {
50
+ await sortingOrderHooks_1.handlePreUpdateForSortingWithStatus.call(this, _1.CancellationReasonModel, ['reasonType']);
51
+ next();
100
52
  })
101
53
  ], CancellationReason);
102
54
  //# sourceMappingURL=cancellation-reason.model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cancellation-reason.model.js","sourceRoot":"/","sources":["libraries/mongo/models/cancellation-reason.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA+D;AAC/D,4EAAqE;AACrE,kDAGiC;AAiC1B,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,2BAAU;IAEvC,MAAM,CAAU;IAGhB,UAAU,CAA8B;IAGxC,MAA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,EAAE,CAAC;YACb,IAAI,CAAC,KAAc,CAAC,CAAC;QACzB,CAAC;IACL,CAAC,CAAC;GACW,kBAAkB,CAY9B","sourcesContent":["import { modelOptions, prop, pre } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport {\n SettingsReasonStatus,\n CancellationReasonTypeEnum\n} from '../../../utilities/enum';\n\n@modelOptions({ schemaOptions: { collection: 'cancellationReasons' } })\n@pre<CancellationReason>('save', async function (next) {\n try {\n\n const { CancellationReasonModel } = await import('.');\n\n if (this.isNew || typeof this.sortingOrder === 'undefined') {\n const [result] = await CancellationReasonModel.aggregate<{ maxSortingOrder: number }>([\n {\n $match: {\n reasonType: this.reasonType,\n status: SettingsReasonStatus.ACTIVE,\n deletedAt: null,\n },\n },\n {\n $group: {\n _id: null,\n maxSortingOrder: { $max: '$sortingOrder' },\n },\n },\n ]).exec();\n\n this.sortingOrder = (result?.maxSortingOrder ?? -1) + 1;\n }\n\n next();\n } catch (error) {\n next(error as Error);\n }\n})\nexport class CancellationReason extends TimeStamps {\n @prop({ required: true })\n public reason!: string;\n\n @prop({ required: true, enum: CancellationReasonTypeEnum })\n public reasonType!: CancellationReasonTypeEnum;\n\n @prop({ required: true, enum: SettingsReasonStatus })\n public status!: SettingsReasonStatus;\n\n @prop()\n public sortingOrder?: number;\n}\n"]}
1
+ {"version":3,"file":"cancellation-reason.model.js","sourceRoot":"/","sources":["libraries/mongo/models/cancellation-reason.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA+D;AAC/D,4EAAqE;AACrE,kDAA6E;AAE7E,wBAA4C;AAC5C,sEAGwC;AAejC,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,2BAAU;IAE1C,MAAM,CAAU;IAGhB,UAAU,CAA8B;IAGxC,MAAM,CAAU;IAGhB,YAAY,CAAU;CAC7B,CAAA;AAZY,gDAAkB;AAEvB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;kDACF;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,iCAA0B,EAAE,CAAC;;sDACZ;AAGxC;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,aAAM,EAAE,CAAC;;kDAChB;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;wDACM;6BAXjB,kBAAkB;IAb9B,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,qBAAqB,EAAE,EAAE,CAAC;IACtE,IAAA,eAAG,EAAqB,MAAM,EAAE,KAAK,WAAW,IAAI;QACpD,MAAM,qDAAiC,CAAC,IAAI,CAAC,IAAI,EAAE,0BAAuB,EAAE;YAC3E,UAAU,EAAE,IAAI,CAAC,UAAU;SAC3B,CAAC,CAAC;QAEH,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;IACD,IAAA,eAAG,EAAqB,kBAAkB,EAAE,KAAK,WAAiD,IAAI;QACtG,MAAM,uDAAmC,CAAC,IAAI,CAAC,IAAI,EAAE,0BAAuB,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;QAE9F,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;GACW,kBAAkB,CAY9B","sourcesContent":["import { modelOptions, prop, pre } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { CancellationReasonTypeEnum, Status } from '../../../utilities/enum';\nimport { Query } from 'mongoose';\nimport { CancellationReasonModel } from '.';\nimport {\n\thandlePreSaveForSortingWithStatus,\n\thandlePreUpdateForSortingWithStatus,\n} from '../utilities/sortingOrderHooks';\n\n@modelOptions({ schemaOptions: { collection: 'cancellationReasons' } })\n@pre<CancellationReason>('save', async function (next) {\n\tawait handlePreSaveForSortingWithStatus.call(this, CancellationReasonModel, {\n\t\treasonType: this.reasonType,\n\t});\n\n\tnext();\n})\n@pre<CancellationReason>('findOneAndUpdate', async function (this: Query<any, CancellationReason>, next) {\n\tawait handlePreUpdateForSortingWithStatus.call(this, CancellationReasonModel, ['reasonType']);\n\n\tnext();\n})\nexport class CancellationReason extends TimeStamps {\n\t@prop({ required: true })\n\tpublic reason!: string;\n\n\t@prop({ required: true, enum: CancellationReasonTypeEnum })\n\tpublic reasonType!: CancellationReasonTypeEnum;\n\n\t@prop({ required: true, enum: Status })\n\tpublic status!: Status;\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n}\n"]}
@@ -15,6 +15,7 @@ const defaultClasses_1 = require("@typegoose/typegoose/lib/defaultClasses");
15
15
  const enum_1 = require("../../../utilities/enum");
16
16
  const shop_model_1 = require("./shop.model");
17
17
  const _1 = require(".");
18
+ const sortingOrderHooks_1 = require("../utilities/sortingOrderHooks");
18
19
  let Dish = class Dish extends defaultClasses_1.TimeStamps {
19
20
  shop;
20
21
  name;
@@ -82,28 +83,9 @@ exports.Dish = Dish = __decorate([
82
83
  (0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'dishes' } }),
83
84
  (0, typegoose_1.Index)({ shop: 1, deletedAt: 1 }),
84
85
  (0, typegoose_1.pre)('save', async function (next) {
85
- if (this.isNew || typeof this.sortingOrder === 'undefined') {
86
- try {
87
- const maxSortingOrder = await _1.DishModel.aggregate([
88
- {
89
- $match: {
90
- shop: this.shop,
91
- deletedAt: null,
92
- },
93
- },
94
- {
95
- $group: {
96
- _id: null,
97
- maxSortingOrder: { $max: '$sortingOrder' },
98
- },
99
- },
100
- ]).exec();
101
- this.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;
102
- }
103
- catch (error) {
104
- return next(error);
105
- }
106
- }
86
+ await sortingOrderHooks_1.handlePreSaveForSorting.call(this, _1.DishModel, {
87
+ shop: this.shop,
88
+ });
107
89
  next();
108
90
  })
109
91
  ], Dish);
@@ -1 +1 @@
1
- {"version":3,"file":"dish.model.js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,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,IAAI,CAAC,KAAc,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC;QACD,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;GACW,IAAI,CAoChB","sourcesContent":["import { Index, modelOptions, pre, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { DishCategory } from '../../../utilities/enum';\nimport { Shop } from './shop.model';\nimport { DishModel } from '.';\n\n@modelOptions({ schemaOptions: { collection: 'dishes' } })\n@Index({ shop: 1, deletedAt: 1 })\n@pre<Dish>('save', async function (next) {\n\t// Only set sortingOrder if it's a new document or sortingOrder is not set\n\tif (this.isNew || typeof this.sortingOrder === 'undefined') {\n\t\ttry {\n\t\t\t// Find the maximum sortingOrder for products with the same shop that aren't deleted\n\t\t\tconst maxSortingOrder = await DishModel.aggregate<{ maxSortingOrder: number }>([\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\tshop: this.shop,\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: null,\n\t\t\t\t\t\tmaxSortingOrder: { $max: '$sortingOrder' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]).exec();\n\n\t\t\t// Set the new sortingOrder to max + 1 (or 0 if no items found)\n\t\t\tthis.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;\n\t\t} catch (error) {\n\t\t\treturn next(error as Error);\n\t\t}\n\t}\n\tnext();\n})\nexport class Dish extends TimeStamps {\n\t@prop({ required: true, ref: () => Shop })\n\tpublic shop!: Ref<Shop>;\n\n\t@prop({ required: true, type: String })\n\tpublic name!: string;\n\n\t@prop({ type: String })\n\tpublic image?: string;\n\n\t@prop({ type: String })\n\tpublic description?: string;\n\n\t@prop({ required: true, type: String, enum: DishCategory })\n\tpublic category!: DishCategory;\n\n\t@prop({ type: () => [String], default: [] })\n\tpublic ingredients?: string[];\n\n\t@prop({ required: true, type: Number })\n\tpublic calories!: number;\n\n\t@prop({ required: true, type: Number })\n\tpublic fat!: number;\n\n\t@prop({ required: true, type: Number })\n\tpublic fibers!: number;\n\n\t@prop({ required: true, type: Number })\n\tpublic protein!: number;\n\n\t@prop({ required: true, type: () => [Number] })\n\tpublic portionPercentage!: number[];\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n}\n"]}
1
+ {"version":3,"file":"dish.model.js","sourceRoot":"/","sources":["libraries/mongo/models/dish.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA2E;AAC3E,4EAAqE;AACrE,kDAAuD;AACvD,6CAAoC;AACpC,wBAA8B;AAC9B,sEAAyE;AAYlE,IAAM,IAAI,GAAV,MAAM,IAAK,SAAQ,2BAAU;IAE5B,IAAI,CAAa;IAGjB,IAAI,CAAU;IAGd,KAAK,CAAU;IAGf,WAAW,CAAU;IAGrB,QAAQ,CAAgB;IAGxB,WAAW,CAAY;IAGvB,QAAQ,CAAU;IAGlB,GAAG,CAAU;IAGb,MAAM,CAAU;IAGhB,OAAO,CAAU;IAGjB,iBAAiB,CAAY;IAG7B,YAAY,CAAU;CAC7B,CAAA;AApCY,oBAAI;AAET;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;kCAClB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;kCAClB;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mCACD;AAGf;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCACK;AAGrB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,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, pre, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { DishCategory } from '../../../utilities/enum';\nimport { Shop } from './shop.model';\nimport { DishModel } from '.';\nimport { handlePreSaveForSorting } from '../utilities/sortingOrderHooks';\n\n@modelOptions({ schemaOptions: { collection: 'dishes' } })\n@Index({ shop: 1, deletedAt: 1 })\n@pre<Dish>('save', async function (next) {\n\t// Set sortingOrder\n\tawait handlePreSaveForSorting.call(this, DishModel, {\n\t\tshop: this.shop,\n\t});\n\n\tnext();\n})\nexport class Dish extends TimeStamps {\n\t@prop({ required: true, ref: () => Shop })\n\tpublic shop!: Ref<Shop>;\n\n\t@prop({ required: true, type: String })\n\tpublic name!: string;\n\n\t@prop({ type: String })\n\tpublic image?: string;\n\n\t@prop({ type: String })\n\tpublic description?: string;\n\n\t@prop({ required: true, type: String, enum: DishCategory })\n\tpublic category!: DishCategory;\n\n\t@prop({ type: () => [String], default: [] })\n\tpublic ingredients?: string[];\n\n\t@prop({ required: true, type: Number })\n\tpublic calories!: number;\n\n\t@prop({ required: true, type: Number })\n\tpublic fat!: number;\n\n\t@prop({ required: true, type: Number })\n\tpublic fibers!: number;\n\n\t@prop({ required: true, type: Number })\n\tpublic protein!: number;\n\n\t@prop({ required: true, type: () => [Number] })\n\tpublic portionPercentage!: number[];\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n}\n"]}
@@ -14,6 +14,7 @@ const typegoose_1 = require("@typegoose/typegoose");
14
14
  const defaultClasses_1 = require("@typegoose/typegoose/lib/defaultClasses");
15
15
  const enum_1 = require("../../../utilities/enum");
16
16
  const _1 = require(".");
17
+ const sortingOrderHooks_1 = require("../utilities/sortingOrderHooks");
17
18
  let Faq = class Faq extends defaultClasses_1.TimeStamps {
18
19
  question;
19
20
  answer;
@@ -45,27 +46,7 @@ __decorate([
45
46
  exports.Faq = Faq = __decorate([
46
47
  (0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'faqs' } }),
47
48
  (0, typegoose_1.pre)('save', async function (next) {
48
- if (this.isNew || typeof this.sortingOrder === 'undefined') {
49
- try {
50
- const maxSortingOrder = await _1.FaqModel.aggregate([
51
- {
52
- $match: {
53
- deletedAt: null,
54
- },
55
- },
56
- {
57
- $group: {
58
- _id: null,
59
- maxSortingOrder: { $max: '$sortingOrder' },
60
- },
61
- },
62
- ]).exec();
63
- this.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;
64
- }
65
- catch (error) {
66
- return next(error);
67
- }
68
- }
49
+ await sortingOrderHooks_1.handlePreSaveForSorting.call(this, _1.FaqModel);
69
50
  next();
70
51
  })
71
52
  ], Faq);
@@ -1 +1 @@
1
- {"version":3,"file":"faq.model.js","sourceRoot":"/","sources":["libraries/mongo/models/faq.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA+D;AAC/D,4EAAqE;AACrE,kDAAiE;AACjE,wBAA6B;AA8BtB,IAAM,GAAG,GAAT,MAAM,GAAI,SAAQ,2BAAU;IAE3B,QAAQ,CAAU;IAGlB,MAAM,CAAU;IAGhB,WAAW,CAAkB;IAG7B,MAAM,CAAU;IAGhB,YAAY,CAAU;CAC7B,CAAA;AAfY,kBAAG;AAER;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;qCACd;AAGlB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mCAChB;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,qBAAc,EAAE,CAAC;;wCACX;AAG7B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,aAAM,EAAE,OAAO,EAAE,aAAM,CAAC,MAAM,EAAE,CAAC;;mCACxB;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCACM;cAdjB,GAAG;IA5Bf,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC;IACvD,IAAA,eAAG,EAAM,MAAM,EAAE,KAAK,WAAW,IAAI;QAErC,IAAI,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,YAAY,KAAK,WAAW,EAAE,CAAC;YAC5D,IAAI,CAAC;gBAEJ,MAAM,eAAe,GAAG,MAAM,WAAQ,CAAC,SAAS,CAA8B;oBAC7E;wBACC,MAAM,EAAE;4BACP,SAAS,EAAE,IAAI;yBACf;qBACD;oBACD;wBACC,MAAM,EAAE;4BACP,GAAG,EAAE,IAAI;4BACT,eAAe,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE;yBAC1C;qBACD;iBACD,CAAC,CAAC,IAAI,EAAE,CAAC;gBAGV,IAAI,CAAC,YAAY,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACrE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,IAAI,CAAC,KAAc,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC;QACD,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;GACW,GAAG,CAef","sourcesContent":["import { modelOptions, pre, prop } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { FaqAccountType, Status } from '../../../utilities/enum';\nimport { FaqModel } from '.';\n\n@modelOptions({ schemaOptions: { collection: 'faqs' } })\n@pre<Faq>('save', async function (next) {\n\t// Only set sortingOrder if it's a new document or sortingOrder is not set\n\tif (this.isNew || typeof this.sortingOrder === 'undefined') {\n\t\ttry {\n\t\t\t// Find the maximum sortingOrder that aren't deleted\n\t\t\tconst maxSortingOrder = await FaqModel.aggregate<{ maxSortingOrder: number }>([\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: null,\n\t\t\t\t\t\tmaxSortingOrder: { $max: '$sortingOrder' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]).exec();\n\n\t\t\t// Set the new sortingOrder to max + 1 (or 0 if no items found)\n\t\t\tthis.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;\n\t\t} catch (error) {\n\t\t\treturn next(error as Error);\n\t\t}\n\t}\n\tnext();\n})\nexport class Faq extends TimeStamps {\n\t@prop({ required: true, type: String })\n\tpublic question!: string;\n\n\t@prop({ required: true, type: String })\n\tpublic answer!: string;\n\n\t@prop({ required: true, enum: FaqAccountType })\n\tpublic accountType!: FaqAccountType;\n\n\t@prop({ enum: Status, default: Status.ACTIVE })\n\tpublic status?: Status;\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n}\n"]}
1
+ {"version":3,"file":"faq.model.js","sourceRoot":"/","sources":["libraries/mongo/models/faq.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA+D;AAC/D,4EAAqE;AACrE,kDAAiE;AACjE,wBAA6B;AAC7B,sEAAyE;AASlE,IAAM,GAAG,GAAT,MAAM,GAAI,SAAQ,2BAAU;IAE3B,QAAQ,CAAU;IAGlB,MAAM,CAAU;IAGhB,WAAW,CAAkB;IAG7B,MAAM,CAAU;IAGhB,YAAY,CAAU;CAC7B,CAAA;AAfY,kBAAG;AAER;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;qCACd;AAGlB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mCAChB;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,qBAAc,EAAE,CAAC;;wCACX;AAG7B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,aAAM,EAAE,OAAO,EAAE,aAAM,CAAC,MAAM,EAAE,CAAC;;mCACxB;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;yCACM;cAdjB,GAAG;IAPf,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC;IACvD,IAAA,eAAG,EAAM,MAAM,EAAE,KAAK,WAAW,IAAI;QAErC,MAAM,2CAAuB,CAAC,IAAI,CAAC,IAAI,EAAE,WAAQ,CAAC,CAAC;QAEnD,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;GACW,GAAG,CAef","sourcesContent":["import { modelOptions, pre, prop } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { FaqAccountType, Status } from '../../../utilities/enum';\nimport { FaqModel } from '.';\nimport { handlePreSaveForSorting } from '../utilities/sortingOrderHooks';\n\n@modelOptions({ schemaOptions: { collection: 'faqs' } })\n@pre<Faq>('save', async function (next) {\n\t// Set sortingOrder\n\tawait handlePreSaveForSorting.call(this, FaqModel);\n\n\tnext();\n})\nexport class Faq extends TimeStamps {\n\t@prop({ required: true, type: String })\n\tpublic question!: string;\n\n\t@prop({ required: true, type: String })\n\tpublic answer!: string;\n\n\t@prop({ required: true, enum: FaqAccountType })\n\tpublic accountType!: FaqAccountType;\n\n\t@prop({ enum: Status, default: Status.ACTIVE })\n\tpublic status?: Status;\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n}\n"]}
@@ -5,6 +5,6 @@ export declare class FilterContainer extends TimeStamps {
5
5
  deals: string[];
6
6
  itemType?: UserAppSectionItemType;
7
7
  status?: Status;
8
- sortingOrder?: number;
9
8
  isVisible: boolean;
9
+ sortingOrder?: number;
10
10
  }
@@ -14,13 +14,14 @@ const typegoose_1 = require("@typegoose/typegoose");
14
14
  const defaultClasses_1 = require("@typegoose/typegoose/lib/defaultClasses");
15
15
  const enum_1 = require("../../../utilities/enum");
16
16
  const _1 = require(".");
17
+ const sortingOrderHooks_1 = require("../utilities/sortingOrderHooks");
17
18
  let FilterContainer = class FilterContainer extends defaultClasses_1.TimeStamps {
18
19
  name;
19
20
  deals;
20
21
  itemType;
21
22
  status;
22
- sortingOrder;
23
23
  isVisible;
24
+ sortingOrder;
24
25
  };
25
26
  exports.FilterContainer = FilterContainer;
26
27
  __decorate([
@@ -39,40 +40,23 @@ __decorate([
39
40
  (0, typegoose_1.prop)({ type: String, enum: enum_1.Status, default: enum_1.Status.ACTIVE }),
40
41
  __metadata("design:type", String)
41
42
  ], FilterContainer.prototype, "status", void 0);
42
- __decorate([
43
- (0, typegoose_1.prop)({ type: Number }),
44
- __metadata("design:type", Number)
45
- ], FilterContainer.prototype, "sortingOrder", void 0);
46
43
  __decorate([
47
44
  (0, typegoose_1.prop)({ type: Boolean, default: true }),
48
45
  __metadata("design:type", Boolean)
49
46
  ], FilterContainer.prototype, "isVisible", void 0);
47
+ __decorate([
48
+ (0, typegoose_1.prop)({ type: Number }),
49
+ __metadata("design:type", Number)
50
+ ], FilterContainer.prototype, "sortingOrder", void 0);
50
51
  exports.FilterContainer = FilterContainer = __decorate([
51
52
  (0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'filterContainers' } }),
52
53
  (0, typegoose_1.Index)({ itemType: 1, deletedAt: 1 }),
53
54
  (0, typegoose_1.pre)('save', async function (next) {
54
- if (this.isNew || typeof this.sortingOrder === 'undefined') {
55
- try {
56
- const maxSortingOrder = await _1.FilterContainerModel.aggregate([
57
- {
58
- $match: {
59
- itemType: this.itemType,
60
- deletedAt: null,
61
- },
62
- },
63
- {
64
- $group: {
65
- _id: null,
66
- maxSortingOrder: { $max: '$sortingOrder' },
67
- },
68
- },
69
- ]).exec();
70
- this.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;
71
- }
72
- catch (error) {
73
- return next(error);
74
- }
75
- }
55
+ await sortingOrderHooks_1.handlePreSaveForSortingWithStatus.call(this, _1.FilterContainerModel, { itemType: this.itemType });
56
+ next();
57
+ }),
58
+ (0, typegoose_1.pre)('findOneAndUpdate', async function (next) {
59
+ await sortingOrderHooks_1.handlePreUpdateForSortingWithStatus.call(this, _1.FilterContainerModel, ['itemType']);
76
60
  next();
77
61
  })
78
62
  ], FilterContainer);
@@ -1 +1 @@
1
- {"version":3,"file":"filter-container.model.js","sourceRoot":"/","sources":["libraries/mongo/models/filter-container.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAsE;AACtE,4EAAqE;AACrE,kDAAmF;AACnF,wBAAyC;AAgClC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,2BAAU;IAEvC,IAAI,CAAU;IAGd,KAAK,CAAY;IAGjB,QAAQ,CAA0B;IAGlC,MAAM,CAAU;IAGhB,YAAY,CAAU;IAGtB,SAAS,CAAU;CAC1B,CAAA;AAlBY,0CAAe;AAEpB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;6CAClB;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;;8CACjB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,6BAAsB,EAAE,CAAC;;iDACZ;AAGlC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAM,EAAE,OAAO,EAAE,aAAM,CAAC,MAAM,EAAE,CAAC;;+CACtC;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;qDACM;AAGtB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;kDACb;0BAjBd,eAAe;IA9B3B,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,kBAAkB,EAAE,EAAE,CAAC;IACnE,IAAA,iBAAK,EAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;IACpC,IAAA,eAAG,EAAkB,MAAM,EAAE,KAAK,WAAW,IAAI;QAEjD,IAAI,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,YAAY,KAAK,WAAW,EAAE,CAAC;YAC5D,IAAI,CAAC;gBAEJ,MAAM,eAAe,GAAG,MAAM,uBAAoB,CAAC,SAAS,CAA8B;oBACzF;wBACC,MAAM,EAAE;4BACP,QAAQ,EAAE,IAAI,CAAC,QAAQ;4BACvB,SAAS,EAAE,IAAI;yBACf;qBACD;oBACD;wBACC,MAAM,EAAE;4BACP,GAAG,EAAE,IAAI;4BACT,eAAe,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE;yBAC1C;qBACD;iBACD,CAAC,CAAC,IAAI,EAAE,CAAC;gBAGV,IAAI,CAAC,YAAY,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YACrE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,OAAO,IAAI,CAAC,KAAc,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC;QACD,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;GACW,eAAe,CAkB3B","sourcesContent":["import { Index, modelOptions, pre, prop } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { ItemType, Status, UserAppSectionItemType } from '../../../utilities/enum';\nimport { FilterContainerModel } from '.';\n\n@modelOptions({ schemaOptions: { collection: 'filterContainers' } })\n@Index({ itemType: 1, deletedAt: 1 })\n@pre<FilterContainer>('save', async function (next) {\n\t// Only set sortingOrder if it's a new document or sortingOrder is not set\n\tif (this.isNew || typeof this.sortingOrder === 'undefined') {\n\t\ttry {\n\t\t\t// Find the maximum sortingOrder for filterContainers with the same itemType that aren't deleted\n\t\t\tconst maxSortingOrder = await FilterContainerModel.aggregate<{ maxSortingOrder: number }>([\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\titemType: this.itemType,\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: null,\n\t\t\t\t\t\tmaxSortingOrder: { $max: '$sortingOrder' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]).exec();\n\n\t\t\t// Set the new sortingOrder to max + 1 (or 0 if no items found)\n\t\t\tthis.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;\n\t\t} catch (error) {\n\t\t\treturn next(error as Error);\n\t\t}\n\t}\n\tnext();\n})\nexport class FilterContainer extends TimeStamps {\n\t@prop({ required: true, type: String })\n\tpublic name!: string;\n\n\t@prop({ required: true, type: [String] })\n\tpublic deals!: string[]; // e.g., \"5\", \"10\", \"20\", \"30\", \"double_menu\"\n\n\t@prop({ type: String, enum: UserAppSectionItemType })\n\tpublic itemType?: UserAppSectionItemType;\n\n\t@prop({ type: String, enum: Status, default: Status.ACTIVE })\n\tpublic status?: Status;\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n\n\t@prop({ type: Boolean, default: true })\n\tpublic isVisible!: boolean\n}\n"]}
1
+ {"version":3,"file":"filter-container.model.js","sourceRoot":"/","sources":["libraries/mongo/models/filter-container.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAsE;AACtE,4EAAqE;AACrE,kDAAyE;AACzE,wBAAyC;AAEzC,sEAGwC;AAcjC,IAAM,eAAe,GAArB,MAAM,eAAgB,SAAQ,2BAAU;IAEvC,IAAI,CAAU;IAGd,KAAK,C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,IAAI,CAAC,IAAI,EAAE,uBAAoB,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;QAEzF,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;GACW,eAAe,CAkB3B","sourcesContent":["import { Index, modelOptions, pre, prop } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { Status, UserAppSectionItemType } from '../../../utilities/enum';\nimport { FilterContainerModel } from '.';\nimport { Query } from 'mongoose';\nimport {\n\thandlePreSaveForSortingWithStatus,\n\thandlePreUpdateForSortingWithStatus,\n} from '../utilities/sortingOrderHooks';\n\n@modelOptions({ schemaOptions: { collection: 'filterContainers' } })\n@Index({ itemType: 1, deletedAt: 1 })\n@pre<FilterContainer>('save', async function (next) {\n\tawait handlePreSaveForSortingWithStatus.call(this, FilterContainerModel, { itemType: this.itemType });\n\n\tnext();\n})\n@pre<FilterContainer>('findOneAndUpdate', async function (this: Query<any, FilterContainer>, next) {\n\tawait handlePreUpdateForSortingWithStatus.call(this, FilterContainerModel, ['itemType']);\n\n\tnext();\n})\nexport class FilterContainer extends TimeStamps {\n\t@prop({ required: true, type: String })\n\tpublic name!: string;\n\n\t@prop({ required: true, type: [String] })\n\tpublic deals!: string[]; // e.g., \"5\", \"10\", \"20\", \"30\", \"double_menu\"\n\n\t@prop({ type: String, enum: UserAppSectionItemType })\n\tpublic itemType?: UserAppSectionItemType;\n\n\t@prop({ type: String, enum: Status, default: Status.ACTIVE })\n\tpublic status?: Status;\n\n\t@prop({ type: Boolean, default: true })\n\tpublic isVisible!: boolean;\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n}\n"]}
@@ -1,17 +1,19 @@
1
1
  import { Ref } from '@typegoose/typegoose';
2
2
  import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
3
- import { Status, UserAppSectionItemType } from '../../../utilities/enum';
3
+ import { ItemType, Status } from '../../../utilities/enum';
4
4
  import { Shop } from './shop.model';
5
5
  import { Tag } from './tag.model';
6
+ import { Zone } from './zone.model';
6
7
  export declare class ListContainer extends TimeStamps {
7
8
  name: string;
9
+ itemType: ItemType;
8
10
  image: string;
9
11
  banner: string;
12
+ zones?: Ref<Zone>[];
10
13
  deals?: string[];
11
14
  tags?: Ref<Tag>[];
12
15
  shops?: Ref<Shop>[];
13
- itemType?: UserAppSectionItemType;
14
16
  status?: Status;
15
- sortingOrder?: number;
16
17
  isVisible: boolean;
18
+ sortingOrder?: number;
17
19
  }
@@ -15,24 +15,31 @@ const defaultClasses_1 = require("@typegoose/typegoose/lib/defaultClasses");
15
15
  const enum_1 = require("../../../utilities/enum");
16
16
  const shop_model_1 = require("./shop.model");
17
17
  const tag_model_1 = require("./tag.model");
18
+ const zone_model_1 = require("./zone.model");
19
+ const sortingOrderHooks_1 = require("../utilities/sortingOrderHooks");
18
20
  const _1 = require(".");
19
21
  let ListContainer = class ListContainer extends defaultClasses_1.TimeStamps {
20
22
  name;
23
+ itemType;
21
24
  image;
22
25
  banner;
26
+ zones;
23
27
  deals;
24
28
  tags;
25
29
  shops;
26
- itemType;
27
30
  status;
28
- sortingOrder;
29
31
  isVisible;
32
+ sortingOrder;
30
33
  };
31
34
  exports.ListContainer = ListContainer;
32
35
  __decorate([
33
- (0, typegoose_1.prop)({ required: true, type: String }),
36
+ (0, typegoose_1.prop)({ required: true, type: String, maxlength: 30 }),
34
37
  __metadata("design:type", String)
35
38
  ], ListContainer.prototype, "name", void 0);
39
+ __decorate([
40
+ (0, typegoose_1.prop)({ required: true, type: String, enum: enum_1.ItemType }),
41
+ __metadata("design:type", String)
42
+ ], ListContainer.prototype, "itemType", void 0);
36
43
  __decorate([
37
44
  (0, typegoose_1.prop)({ required: true, type: String }),
38
45
  __metadata("design:type", String)
@@ -41,6 +48,10 @@ __decorate([
41
48
  (0, typegoose_1.prop)({ required: true, type: String }),
42
49
  __metadata("design:type", String)
43
50
  ], ListContainer.prototype, "banner", void 0);
51
+ __decorate([
52
+ (0, typegoose_1.prop)({ ref: () => zone_model_1.Zone, default: [] }),
53
+ __metadata("design:type", Array)
54
+ ], ListContainer.prototype, "zones", void 0);
44
55
  __decorate([
45
56
  (0, typegoose_1.prop)({ type: () => [String], default: [] }),
46
57
  __metadata("design:type", Array)
@@ -53,48 +64,28 @@ __decorate([
53
64
  (0, typegoose_1.prop)({ ref: () => shop_model_1.Shop, default: [] }),
54
65
  __metadata("design:type", Array)
55
66
  ], ListContainer.prototype, "shops", void 0);
56
- __decorate([
57
- (0, typegoose_1.prop)({ type: String, enum: enum_1.UserAppSectionItemType }),
58
- __metadata("design:type", String)
59
- ], ListContainer.prototype, "itemType", void 0);
60
67
  __decorate([
61
68
  (0, typegoose_1.prop)({ enum: enum_1.Status, default: enum_1.Status.ACTIVE }),
62
69
  __metadata("design:type", String)
63
70
  ], ListContainer.prototype, "status", void 0);
64
- __decorate([
65
- (0, typegoose_1.prop)({ type: Number }),
66
- __metadata("design:type", Number)
67
- ], ListContainer.prototype, "sortingOrder", void 0);
68
71
  __decorate([
69
72
  (0, typegoose_1.prop)({ type: Boolean, default: true }),
70
73
  __metadata("design:type", Boolean)
71
74
  ], ListContainer.prototype, "isVisible", void 0);
75
+ __decorate([
76
+ (0, typegoose_1.prop)({ type: Number }),
77
+ __metadata("design:type", Number)
78
+ ], ListContainer.prototype, "sortingOrder", void 0);
72
79
  exports.ListContainer = ListContainer = __decorate([
73
80
  (0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'listContainers' } }),
74
- (0, typegoose_1.Index)({ itemType: 1, deletedAt: 1 }),
81
+ (0, typegoose_1.index)({ name: 1, itemType: 1 }, { unique: true, partialFilterExpression: { deletedAt: null } }),
82
+ (0, typegoose_1.index)({ itemType: 1, deletedAt: 1 }),
75
83
  (0, typegoose_1.pre)('save', async function (next) {
76
- if (this.isNew || typeof this.sortingOrder === 'undefined') {
77
- try {
78
- const maxSortingOrder = await _1.ListContainerModel.aggregate([
79
- {
80
- $match: {
81
- itemType: this.itemType,
82
- deletedAt: null,
83
- },
84
- },
85
- {
86
- $group: {
87
- _id: null,
88
- maxSortingOrder: { $max: '$sortingOrder' },
89
- },
90
- },
91
- ]).exec();
92
- this.sortingOrder = (maxSortingOrder[0]?.maxSortingOrder ?? -1) + 1;
93
- }
94
- catch (error) {
95
- return next(error);
96
- }
97
- }
84
+ await sortingOrderHooks_1.handlePreSaveForSortingWithStatus.call(this, _1.ListContainerModel, { itemType: this.itemType });
85
+ next();
86
+ }),
87
+ (0, typegoose_1.pre)('findOneAndUpdate', async function (next) {
88
+ await sortingOrderHooks_1.handlePreUpdateForSortingWithStatus.call(this, _1.ListContainerModel, ['itemType']);
98
89
  next();
99
90
  })
100
91
  ], ListContainer);