@lyxa.ai/marketing 1.0.28 → 1.0.29

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 (109) hide show
  1. package/dist/lib/index.d.ts +7 -0
  2. package/dist/lib/index.d.ts.map +1 -1
  3. package/dist/lib/modules/coupon/routers/coupon.router.d.ts +7 -0
  4. package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
  5. package/dist/lib/modules/coupon/routers/coupon.router.js +6 -0
  6. package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
  7. package/dist/lib/modules/coupon/services/coupon.service.d.ts +2 -2
  8. package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
  9. package/dist/lib/modules/coupon/services/coupon.service.js +36 -32
  10. package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
  11. package/dist/lib/modules/coupon/services/custom-coupon.service.d.ts.map +1 -1
  12. package/dist/lib/modules/coupon/services/custom-coupon.service.js +6 -0
  13. package/dist/lib/modules/coupon/services/custom-coupon.service.js.map +1 -1
  14. package/dist/lib/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
  15. package/dist/lib/modules/coupon/services/global-coupon.service.js +6 -0
  16. package/dist/lib/modules/coupon/services/global-coupon.service.js.map +1 -1
  17. package/dist/lib/modules/coupon/services/helper.service.d.ts +12 -0
  18. package/dist/lib/modules/coupon/services/helper.service.d.ts.map +1 -0
  19. package/dist/lib/modules/coupon/services/helper.service.js +147 -0
  20. package/dist/lib/modules/coupon/services/helper.service.js.map +1 -0
  21. package/dist/lib/modules/coupon/services/individual-store-coupon.service.d.ts.map +1 -1
  22. package/dist/lib/modules/coupon/services/individual-store-coupon.service.js +6 -0
  23. package/dist/lib/modules/coupon/services/individual-store-coupon.service.js.map +1 -1
  24. package/dist/lib/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
  25. package/dist/lib/modules/coupon/services/individual-user-coupon.service.js +7 -1
  26. package/dist/lib/modules/coupon/services/individual-user-coupon.service.js.map +1 -1
  27. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts +6 -1
  28. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
  29. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +102 -6
  30. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
  31. package/dist/lib/modules/coupon/services/referral-code-coupon.service.d.ts +0 -1
  32. package/dist/lib/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
  33. package/dist/lib/modules/coupon/services/referral-code-coupon.service.js +14 -14
  34. package/dist/lib/modules/coupon/services/referral-code-coupon.service.js.map +1 -1
  35. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts +2 -1
  36. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
  37. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js +22 -20
  38. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
  39. package/dist/lib/modules/coupon/services/shops-categories-coupon.service.d.ts.map +1 -1
  40. package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js +8 -1
  41. package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js.map +1 -1
  42. package/dist/lib/modules/coupon/validations/coupon.validation.js +3 -6
  43. package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
  44. package/dist/lib/modules/deal-setting/routers/deal-setting.router.d.ts.map +1 -1
  45. package/dist/lib/modules/deal-setting/services/deal-setting.service.d.ts +2 -0
  46. package/dist/lib/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
  47. package/dist/lib/modules/deal-setting/services/deal-setting.service.js +32 -8
  48. package/dist/lib/modules/deal-setting/services/deal-setting.service.js.map +1 -1
  49. package/dist/lib/modules/featured-setting/routers/featured-setting.router.d.ts.map +1 -1
  50. package/dist/lib/modules/featured-setting/services/featured-setting.service.d.ts +2 -0
  51. package/dist/lib/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
  52. package/dist/lib/modules/featured-setting/services/featured-setting.service.js +54 -8
  53. package/dist/lib/modules/featured-setting/services/featured-setting.service.js.map +1 -1
  54. package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  55. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
  56. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js +11 -3
  57. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js.map +1 -1
  58. package/dist/lib/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
  59. package/dist/lib/modules/marketing/services/discount-marketing.service.js +11 -3
  60. package/dist/lib/modules/marketing/services/discount-marketing.service.js.map +1 -1
  61. package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
  62. package/dist/lib/modules/marketing/services/marketing.service.js +8 -1
  63. package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
  64. package/dist/lib/modules/marketing/validations/featured-marketing.validation.d.ts.map +1 -1
  65. package/dist/lib/modules/marketing/validations/featured-marketing.validation.js +12 -13
  66. package/dist/lib/modules/marketing/validations/featured-marketing.validation.js.map +1 -1
  67. package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.d.ts.map +1 -1
  68. package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.js +8 -6
  69. package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.js.map +1 -1
  70. package/dist/lib/modules/marketing/validations/punch-marketing.validation.js +3 -6
  71. package/dist/lib/modules/marketing/validations/punch-marketing.validation.js.map +1 -1
  72. package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts.map +1 -1
  73. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
  74. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js +12 -9
  75. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js.map +1 -1
  76. package/dist/types/index.d.ts +7 -0
  77. package/dist/types/index.d.ts.map +1 -1
  78. package/dist/types/modules/coupon/routers/coupon.router.d.ts +7 -0
  79. package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
  80. package/dist/types/modules/coupon/services/coupon.service.d.ts +2 -2
  81. package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
  82. package/dist/types/modules/coupon/services/custom-coupon.service.d.ts.map +1 -1
  83. package/dist/types/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
  84. package/dist/types/modules/coupon/services/helper.service.d.ts +12 -0
  85. package/dist/types/modules/coupon/services/helper.service.d.ts.map +1 -0
  86. package/dist/types/modules/coupon/services/individual-store-coupon.service.d.ts.map +1 -1
  87. package/dist/types/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
  88. package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts +6 -1
  89. package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
  90. package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts +0 -1
  91. package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
  92. package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts +2 -1
  93. package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
  94. package/dist/types/modules/coupon/services/shops-categories-coupon.service.d.ts.map +1 -1
  95. package/dist/types/modules/deal-setting/routers/deal-setting.router.d.ts.map +1 -1
  96. package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts +2 -0
  97. package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
  98. package/dist/types/modules/featured-setting/routers/featured-setting.router.d.ts.map +1 -1
  99. package/dist/types/modules/featured-setting/services/featured-setting.service.d.ts +2 -0
  100. package/dist/types/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
  101. package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  102. package/dist/types/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
  103. package/dist/types/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
  104. package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
  105. package/dist/types/modules/marketing/validations/featured-marketing.validation.d.ts.map +1 -1
  106. package/dist/types/modules/marketing/validations/free-delivery-marketing.validation.d.ts.map +1 -1
  107. package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts.map +1 -1
  108. package/dist/types/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
  109. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"featured-setting.service.js","sourceRoot":"/","sources":["modules/featured-setting/services/featured-setting.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA+E;AAE/E,wEAA6G;AAE7G,uEAA4G;AAM5G,8DAAkE;AAElE,iGAAoG;AACpG,4DAA+E;AAGxE,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAC1B,KAAK,CAAuD;IAEpE;QACC,IAAI,CAAC,KAAK,GAAG,6BAA4E,CAAC;IAC3F,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe,EAAE,KAAc;QAClD,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,iBAAiB;aAC1B,CAAC,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YACtC,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACvB,CAAC,CAAC;QACH,IAAI,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,kCAAkC,IAAI,CAAC,QAAQ,uDAAuD;aAC/G,CAAC,CAAC;QACJ,CAAC;QACD,M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{ Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport { FilterDTO, PaginatedResponse, DeleteDTO } from '@lyxa.ai/core/dist/utilities/validation';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { FeaturedSettingModel, FeaturedSetting as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateFeaturedSettingDTO as CreateDTO,\n\tUpdateFeaturedSettingDTO as UpdateDTO,\n} from '@modules/featured-setting/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType } from '@lyxa.ai/core/dist/utilities/enum';\n\n@Service()\nexport class FeaturedSettingService {\n\tprivate model: typeof FeaturedSettingModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.model = FeaturedSettingModel as typeof FeaturedSettingModel & SoftDeleteModel<Model>;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO, admin?: string): Promise<DocumentType<Model>> {\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Admin not found',\n\t\t\t});\n\t\t}\n\n\t\tconst exists = await this.model.exists({\n\t\t\titemType: data.itemType,\n\t\t});\n\t\tif (exists) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `Featured settings for itemType ${data.itemType} already exists. Please update the existing settings.`,\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.create(data);\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.CREATED_MARKETING_SETTINGS,\n\t\t\t'',\n\t\t\tresult\n\t\t);\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(id: string | mongoose.Types.ObjectId): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.findOne({\n\t\t\t_id: id,\n\t\t\tdeletedAt: null,\n\t\t});\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t * @param admin Admin id\n\t */\n\tpublic async update(id: string, data: UpdateDTO, admin?: string): Promise<DocumentType<Model>> {\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Admin not found`,\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(id);\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Record not found`,\n\t\t\t});\n\t\t}\n\n\t\tconst result = await this.model.findByIdAndUpdate(id, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\n\t\t});\n\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Record not found`,\n\t\t\t});\n\t\t}\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.CHANGE_IN_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn result;\n\t}\n\n\tprivate async logMarketingSettingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: string): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Admin not found',\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(_id);\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete record',\n\t\t\t});\n\t\t}\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.DELETED_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn 'Record deleted successfully';\n\t}\n}\n\nexport const featuredSettingService = Container.get(FeaturedSettingService);\n"]}
1
+ {"version":3,"file":"featured-setting.service.js","sourceRoot":"/","sources":["modules/featured-setting/services/featured-setting.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA+E;AAE/E,wEAA6G;AAE7G,uEAA4G;AAM5G,8DAAkE;AAElE,iGAAoG;AACpG,4DAAiG;AAG1F,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAC1B,KAAK,CAAuD;IAC5D,UAAU,GAAG;QACpB,eAAQ,CAAC,IAAI;QACb,eAAQ,CAAC,OAAO;QAChB,eAAQ,CAAC,MAAM;QACf,eAAQ,CAAC,MAAM;QACf,eAAQ,CAAC,GAAG;KAGZ,CAAC;IAEF;QACC,IAAI,CAAC,KAAK,GAAG,6BAA4E,CAAC;IAC3F,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe,EAAE,KAAc;QAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YACtC,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACvB,CAAC,CAAC;QACH,IAAI,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,kCAAkC,IAAI,CAAC,QAAQ,uDAAuD;aAC/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AAO,GAAE;;GACG,sBAAsB,CA2OlC;AAEY,QAAA,sBAAsB,GAAG,gBAAS,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport { FilterDTO, PaginatedResponse, DeleteDTO } from '@lyxa.ai/core/dist/utilities/validation';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { FeaturedSettingModel, FeaturedSetting as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateFeaturedSettingDTO as CreateDTO,\n\tUpdateFeaturedSettingDTO as UpdateDTO,\n} from '@modules/featured-setting/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType, ItemType, Status } from '@lyxa.ai/core/dist/utilities/enum';\n\n@Service()\nexport class FeaturedSettingService {\n\tprivate model: typeof FeaturedSettingModel & SoftDeleteModel<Model>;\n\tprivate ITEM_TYPES = [\n\t\tItemType.FOOD,\n\t\tItemType.GROCERY,\n\t\tItemType.COFFEE,\n\t\tItemType.FLOWER,\n\t\tItemType.PET,\n\t\t// ItemType.PHARMACY,\n\t\t// ItemType.HEALTHY_CORNER,\n\t];\n\n\tconstructor() {\n\t\tthis.model = FeaturedSettingModel as typeof FeaturedSettingModel & SoftDeleteModel<Model>;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO, admin?: string): Promise<DocumentType<Model>> {\n\t\tconst exists = await this.model.exists({\n\t\t\titemType: data.itemType,\n\t\t});\n\t\tif (exists) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `Featured settings for itemType ${data.itemType} already exists. Please update the existing settings.`,\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.create(data);\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingSettingAdminAction(\n\t\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\t\tAdminLogsUpdatedFieldsType.CREATED_MARKETING_SETTINGS,\n\t\t\t\t'',\n\t\t\t\tresult\n\t\t\t);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(id: string | mongoose.Types.ObjectId): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.findOne({\n\t\t\t_id: id,\n\t\t\tdeletedAt: null,\n\t\t});\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tlet paginatedResult = await paginate(options);\n\n\t\t\tif (!data?.query && paginatedResult.metadata.totalElements < this.ITEM_TYPES.length) {\n\t\t\t\tawait this.createDefaultFeaturedSettings(\n\t\t\t\t\tpaginatedResult.documents as unknown as DocumentType<Model>[]\n\t\t\t\t);\n\t\t\t\tpaginatedResult = await paginate(options);\n\t\t\t}\n\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async createDefaultFeaturedSettings(documents: DocumentType<Model>[]): Promise<void> {\n\t\tconst existingItemTypes = documents.map(setting => setting.itemType);\n\t\tconst newItemTypes = this.ITEM_TYPES.filter(item => !existingItemTypes.includes(item));\n\t\tconst defaultSetting = {\n\t\t\tfeaturedItems: [\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 3,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 7,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 14,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 21,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 28,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\n\t\tfor (const item of newItemTypes) {\n\t\t\tawait this.create({\n\t\t\t\t...defaultSetting,\n\t\t\t\titemType: item as ItemType,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t * @param admin Admin id\n\t */\n\tpublic async update(id: string, data: UpdateDTO, admin?: string): Promise<DocumentType<Model>> {\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Admin not found`,\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(id);\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Record not found`,\n\t\t\t});\n\t\t}\n\n\t\tconst result = await this.model.findByIdAndUpdate(id, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\n\t\t});\n\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Record not found`,\n\t\t\t});\n\t\t}\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.CHANGE_IN_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn result;\n\t}\n\n\tprivate async logMarketingSettingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: string): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Admin not found',\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(_id);\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete record',\n\t\t\t});\n\t\t}\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.DELETED_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn 'Record deleted successfully';\n\t}\n}\n\nexport const featuredSettingService = Container.get(FeaturedSettingService);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"marketing.router.d.ts","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAgBN,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CrB,CAAC"}
1
+ {"version":3,"file":"marketing.router.d.ts","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAiBpB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CP,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"buy1-get1-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAA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YAAY,CAAC,KAAK,CAAC,CAAC;IA8EnF,uBAAuB,CACnC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACpC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAChC,OAAO,CAAC,IAAI,CAAC;CAOhB;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
@@ -56,7 +56,10 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
56
56
  }
57
57
  async create(data) {
58
58
  const result = await this.model.create(data);
59
- if (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {
59
+ if (data.products &&
60
+ data.products.length > 0 &&
61
+ (!data.categories || data.categories.length === 0) &&
62
+ !data.isEntireMenu) {
60
63
  for (const product of data.products) {
61
64
  if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
62
65
  this.productMarketingsCreate(result._id, product.product);
@@ -65,7 +68,8 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
65
68
  }
66
69
  else if (data.categories &&
67
70
  data.categories.length > 0 &&
68
- (!data.products || data.products.length === 0)) {
71
+ (!data.products || data.products.length === 0) &&
72
+ !data.isEntireMenu) {
69
73
  const categoryWiseProducts = await this.productModel
70
74
  .find({
71
75
  shopCategory: { $in: data.categories },
@@ -77,7 +81,11 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
77
81
  }
78
82
  }
79
83
  }
80
- else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {
84
+ else if (data.categories &&
85
+ data.categories.length > 0 &&
86
+ data.products &&
87
+ data.products.length > 0 &&
88
+ !data.isEntireMenu) {
81
89
  const categoryWiseProducts = await this.productModel
82
90
  .find({
83
91
  shopCategory: { $in: data.categories },
@@ -1 +1 @@
1
- {"version":3,"file":"buy1-get1-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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pC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tBuy1Get1MarketingModel,\n\tBuy1Get1Marketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateBuy1Get1MarketingDTO as CreateDTO,\n\tUpdateBuy1Get1MarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class Buy1Get1MarketingService {\n\tprivate model: typeof Buy1Get1MarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = Buy1Get1MarketingModel;\n\t\tthis.productModel = ProductModel;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\n\t\t// Only products\n\t\tif (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0)\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update record\n\t * @param _id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { products, ...rest } = data;\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: _id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\trest,\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\t// Only products\n\t\tif (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0)\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async productMarketingsCreate(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tproductMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tisBuy1Get1: true,\n\t\t});\n\t}\n}\n\nexport const buy1Get1MarketingService = Container.get(Buy1Get1MarketingService);\n"]}
1
+ {"version":3,"file":"buy1-get1-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,uEAIoD;AAKpD,yBAA6C;AAC7C,4EAA0E;AAGnE,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,KAAK,CAAgC;IACrC,YAAY,CAAsB;IAE1C;QACC,IAAI,CAAC,KAAK,GAAG,+BAAsB,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,qBAAY,CAAC;IAClC,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAG7C,IACC,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YACxB,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;YAClD,CAAC,IAAI,CAAC,YAAY,EACjB,CAAC;YACF,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrC,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC;oBACzF,IA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BAAuB,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBAChD,CAAC;YACF,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM;YAAE,IAAA,4BAAa,EAAC,kBAAkB,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,uBAAuB,CACnC,WAAoC,EACpC,SAAkC;QAElC,0BAAuB,CAAC,MAAM,CAAC;YAC9B,SAAS,EAAE,WAAW;YACtB,OAAO,EAAE,SAAS;YAClB,UAAU,EAAE,IAAI;SAChB,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAxLY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAwLpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tBuy1Get1MarketingModel,\n\tBuy1Get1Marketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateBuy1Get1MarketingDTO as CreateDTO,\n\tUpdateBuy1Get1MarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class Buy1Get1MarketingService {\n\tprivate model: typeof Buy1Get1MarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = Buy1Get1MarketingModel;\n\t\tthis.productModel = ProductModel;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\n\t\t// Only products\n\t\tif (\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t(!data.categories || data.categories.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update record\n\t * @param _id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { products, ...rest } = data;\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: _id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\trest,\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\t// Only products\n\t\tif (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0)\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async productMarketingsCreate(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tproductMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tisBuy1Get1: true,\n\t\t});\n\t}\n}\n\nexport const buy1Get1MarketingService = Container.get(Buy1Get1MarketingService);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"discount-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;A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AAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAqHnF,uBAAuB,CACnC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACpC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAClC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,IAAI,CAAC;CAQhB;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
@@ -56,7 +56,10 @@ let DiscountMarketingService = class DiscountMarketingService {
56
56
  }
57
57
  async create(data) {
58
58
  const result = await this.model.create(data);
59
- if (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {
59
+ if (data.products &&
60
+ data.products.length > 0 &&
61
+ (!data.categories || data.categories.length === 0) &&
62
+ !data.isEntireMenu) {
60
63
  for (const product of data.products) {
61
64
  if (product.valueType !== undefined && product.valueType !== null) {
62
65
  if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
@@ -70,7 +73,8 @@ let DiscountMarketingService = class DiscountMarketingService {
70
73
  }
71
74
  else if (data.categories &&
72
75
  data.categories.length > 0 &&
73
- (!data.products || data.products.length === 0)) {
76
+ (!data.products || data.products.length === 0) &&
77
+ !data.isEntireMenu) {
74
78
  const categoryWiseProducts = await this.productModel
75
79
  .find({
76
80
  shopCategory: { $in: data.categories },
@@ -87,7 +91,11 @@ let DiscountMarketingService = class DiscountMarketingService {
87
91
  }
88
92
  }
89
93
  }
90
- else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {
94
+ else if (data.categories &&
95
+ data.categories.length > 0 &&
96
+ data.products &&
97
+ data.products.length > 0 &&
98
+ !data.isEntireMenu) {
91
99
  const categoryWiseProducts = await this.productModel
92
100
  .find({
93
101
  shopCategory: { $in: data.categories },
@@ -1 +1 @@
1
- {"version":3,"file":"discount-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;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8BAAe,EAAC,yDAAyD,CAAC,CAAC;oBAC5E,CAAC;gBACF,CAAC;YACF,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM;YAAE,IAAA,4BAAa,EAAC,kBAAkB,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,uBAAuB,CACnC,WAAoC,EACpC,SAAkC,EAClC,KAAa,EACb,SAAoB;QAEpB,0BAAuB,CAAC,MAAM,CAAC;YAC9B,SAAS,EAAE,WAAW;YACtB,OAAO,EAAE,SAAS;YAClB,KAAK,EAAE,KAAK;YACZ,SAAS,EAAE,SAAS;SACpB,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAtQY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAsQpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tDiscountMarketingModel,\n\tDiscountMarketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tCreateDiscountMarketingDTO as CreateDTO,\n\tUpdateDiscountMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { badRequestError, notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class DiscountMarketingService {\n\tprivate model: typeof DiscountMarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = DiscountMarketingModel;\n\t\tthis.productModel = ProductModel;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\n\t\t// Only products\n\t\tif (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct.product,\n\t\t\t\t\t\t\tNumber(product.value),\n\t\t\t\t\t\t\tproduct.valueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0)\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\t// Ignore the product which is already added by category\n\t\t\t\tconst isProductAddedByCategory = categoryWiseProducts.find(\n\t\t\t\t\tp => p._id.toString() === product.product.toString()\n\t\t\t\t);\n\t\t\t\tif (isProductAddedByCategory) continue;\n\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct.product,\n\t\t\t\t\t\t\tNumber(product.value),\n\t\t\t\t\t\t\tproduct.valueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshop: data.shop,\n\t\t\t\t})\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (data.valueType !== undefined) {\n\t\t\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id, Number(data.value), data.valueType);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tbadRequestError('Discount value & value-type is required for entire menu');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update record\n\t * @param _id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { categories, products, ...rest } = data;\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: _id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\t{ categories, ...rest },\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\t// Only products\n\t\tif (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(_id, product.product, Number(product.value), product.valueType);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t\tconsole.log('Step 6.1');\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0)\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t_id,\n\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t_id,\n\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\t// Ignore the product which is already added by category\n\t\t\t\tconst isProductAddedByCategory = categoryWiseProducts.find(\n\t\t\t\t\tp => p._id.toString() === product.product.toString()\n\t\t\t\t);\n\t\t\t\tif (isProductAddedByCategory) continue;\n\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(_id, product.product, Number(product.value), product.valueType);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshop: data.shop,\n\t\t\t\t})\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (data.valueType !== undefined) {\n\t\t\t\t\t\t\tthis.productMarketingsCreate(_id, product._id, Number(data.value), data.valueType);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tbadRequestError('Discount value & value-type is required for entire menu');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async productMarketingsCreate(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId,\n\t\tvalue: number,\n\t\tvalueType: ValueType\n\t): Promise<void> {\n\t\tproductMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tvalue: value,\n\t\t\tvalueType: valueType,\n\t\t});\n\t}\n}\n\nexport const discountMarketingService = Container.get(DiscountMarketingService);\n"]}
1
+ {"version":3,"file":"discount-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAE5C,sEAImD;AAKnD,yBAA6C;AAE7C,4EAA2F;AAGpF,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,KAAK,CAAgC;IACrC,YAAY,CAAsB;IAE1C;QACC,IAAI,CAAC,KAAK,GAAG,+BAAsB,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,qBAAY,CAAC;IAClC,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAG7C,IACC,IAAI,CAAC,QAAQ;YACb,IAA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AClB,KAAK,EAAE,KAAK;YACZ,SAAS,EAAE,SAAS;SACpB,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAlRY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAkRpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tDiscountMarketingModel,\n\tDiscountMarketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tCreateDiscountMarketingDTO as CreateDTO,\n\tUpdateDiscountMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { badRequestError, notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class DiscountMarketingService {\n\tprivate model: typeof DiscountMarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = DiscountMarketingModel;\n\t\tthis.productModel = ProductModel;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\n\t\t// Only products\n\t\tif (\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t(!data.categories || data.categories.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct.product,\n\t\t\t\t\t\t\tNumber(product.value),\n\t\t\t\t\t\t\tproduct.valueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\t// Ignore the product which is already added by category\n\t\t\t\tconst isProductAddedByCategory = categoryWiseProducts.find(\n\t\t\t\t\tp => p._id.toString() === product.product.toString()\n\t\t\t\t);\n\t\t\t\tif (isProductAddedByCategory) continue;\n\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct.product,\n\t\t\t\t\t\t\tNumber(product.value),\n\t\t\t\t\t\t\tproduct.valueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshop: data.shop,\n\t\t\t\t})\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (data.valueType !== undefined) {\n\t\t\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id, Number(data.value), data.valueType);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tbadRequestError('Discount value & value-type is required for entire menu');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update record\n\t * @param _id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { categories, products, ...rest } = data;\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: _id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\t{ categories, ...rest },\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\t// Only products\n\t\tif (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(_id, product.product, Number(product.value), product.valueType);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t\tconsole.log('Step 6.1');\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0)\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t_id,\n\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t_id,\n\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\t// Ignore the product which is already added by category\n\t\t\t\tconst isProductAddedByCategory = categoryWiseProducts.find(\n\t\t\t\t\tp => p._id.toString() === product.product.toString()\n\t\t\t\t);\n\t\t\t\tif (isProductAddedByCategory) continue;\n\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(_id, product.product, Number(product.value), product.valueType);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshop: data.shop,\n\t\t\t\t})\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (data.valueType !== undefined) {\n\t\t\t\t\t\t\tthis.productMarketingsCreate(_id, product._id, Number(data.value), data.valueType);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tbadRequestError('Discount value & value-type is required for entire menu');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async productMarketingsCreate(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId,\n\t\tvalue: number,\n\t\tvalueType: ValueType\n\t): Promise<void> {\n\t\tproductMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tvalue: value,\n\t\t\tvalueType: valueType,\n\t\t});\n\t}\n}\n\nexport const discountMarketingService = Container.get(DiscountMarketingService);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAGN,SAAS,IAAI,KAAK,EAElB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAEN,0BAA0B,EAE1B,oCAAoC,EACpC,kBAAkB,IAAI,SAAS,EAC/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACN,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAsB3D,qBACa,gBAAgB;IAC5B,OAAO,CAAC,KAAK,CAAiD;;IAUjD,MAAM,CAClB,IAAI,EAAE,0BAA0B,EAChC,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAC7B,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA+GlB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC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IA+GlB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAsB7D,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IA0B3F,MAAM,CAClB,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAC5B,IAAI,EAAE,SAAS,EACf,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAC7B,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YA0FjB,uBAAuB;IAmBxB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IA4B7E,sCAAsC,CAAC,IAAI,EAAE,oCAAoC;CAgC9F;AAED,eAAO,MAAM,gBAAgB,kBAAkC,CAAC"}
@@ -146,7 +146,14 @@ let MarketingService = class MarketingService {
146
146
  return marketing;
147
147
  }
148
148
  async findById(data) {
149
- const result = await this.model.findRecordById(data);
149
+ const select = data.select || '';
150
+ const populate = data.populate || [];
151
+ const result = await this.model
152
+ .findOne({
153
+ _id: data._id,
154
+ })
155
+ .select(select)
156
+ .populate(populate);
150
157
  if (!result) {
151
158
  throw new server_1.TRPCError({
152
159
  code: 'NOT_FOUND',
@@ -1 +1 @@
1
- {"version":3,"file":"marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AAEzC,sEAKmD;AAenD,wEAA6G;AAE7G,8FAA6G;AAC7G,iGAAoG;AACpG,4DAAgG;AAChG,8DAAkE;AAGlE,wBAOW;AACX,4DAAkE;A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AAC;gBACD,IAAI,iBAAiB,CAAC,aAAa,IAAI,oBAAa,CAAC,QAAQ,EAAE,CAAC;oBAC/D,oBAAoB,CAAC,KAAK,GAAI,iBAAqD,CAAC,KAAK,CAAC;oBAC1F,oBAAoB,CAAC,SAAS,GAAI,iBAAqD,CAAC,SAAS,CAAC;gBACnG,CAAC;gBACD,MAAM,MAAM,GAAG,MAAM,0BAAuB,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;gBAE1E,OAAO,CAAC,GAAG,CAAC,8BAA8B,MAAM,EAAE,CAAC,CAAC;YACrD,CAAC;QACF,CAAC;QAED,OAAO,8BAA8B,CAAC;IACvC,CAAC;CACD,CAAA;AAnVY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,gBAAO,GAAE;;GACG,gBAAgB,CAmV5B;AAEY,QAAA,gBAAgB,GAAG,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport {\n\tDiscountMarketing,\n\tMarketingModel,\n\tMarketing as Model,\n\tPunchMarketingHistory,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tAllMarketingsDTO,\n\tAllMarketingsValidationDTO,\n\tCreateProductMarketingDTO,\n\tProductEntireMenuMarketingHandlerDTO,\n\tUpdateMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport {\n\tFilterDTO,\n\tPaginatedResponse,\n\tDeleteDTO,\n\tGetByIdInputDTO,\n} from '@lyxa.ai/core/dist/utilities/validation';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { filterRelevantChanges, getChangedFields } from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType, MarketingStatus } from '@lyxa.ai/core/dist/utilities/enum';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\n\nimport {\n\tbuy1Get1MarketingService,\n\tdiscountMarketingService,\n\tfeaturedMarketingService,\n\tfreeDeliveryMarketingService,\n\tproductMarketingService,\n\tpunchMarketingService,\n} from '.';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tinternalServerError,\n\tnotFoundError,\n\tunauthorizedError,\n} from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class MarketingService {\n\tprivate model: typeof MarketingModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.model = MarketingModel as typeof MarketingModel & SoftDeleteModel<Model>;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(\n\t\tdata: AllMarketingsValidationDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tconst now = new Date();\n\n\t\tconst existingRecord = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: data.marketingType,\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t});\n\t\tif (existingRecord) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `This shop already has a ${data.marketingType} marketing`,\n\t\t\t});\n\t\t}\n\n\t\tif (data.isEntireMenu) {\n\t\t\tconst existingMarketing = await this.model.findOne({\n\t\t\t\tshop: data.shop,\n\t\t\t\t'duration.start': { $lt: now },\n\t\t\t\t'duration.end': { $gt: now },\n\t\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\t\tmarketingType: { $in: [MarketingType.BUY1GET1, MarketingType.DISCOUNT] },\n\t\t\t});\n\t\t\tif (existingMarketing) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Cannot create marketing for entire menu while another product based marketing exists for the shop`,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (data.products && data.products.length > 0) {\n\t\t\tconst productIds = data.products.map((product: CreateProductMarketingDTO) => product.product);\n\n\t\t\tconst hasDuplicates = new Set(productIds.map(String)).size !== productIds.length;\n\n\t\t\tif (hasDuplicates) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'BAD_REQUEST',\n\t\t\t\t\tmessage: `Product list contains duplicate products`,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability(productIds);\n\n\t\t\tif (!isAvailable) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Product list contains products which already have marketing applied`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (admin) {\n\t\t\tdata.admin = admin;\n\t\t}\n\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tswitch (data.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: 'UNAUTHORIZED',\n\t\t\t\t\t\tmessage: `Only admin is allowed to create ${data.marketingType} marketing`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.create(data, admin);\n\t\t\t}\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.ACTIVATED_MARKETING_PROMOTIONS,\n\t\t\t\t'',\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\treturn marketing;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(data: GetByIdInputDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.findRecordById(data);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(\n\t\t_id: mongoose.Types.ObjectId,\n\t\tdata: UpdateDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tconst oldMarketing = await this.model.findById(_id);\n\n\t\tif (!oldMarketing) {\n\t\t\tnotFoundError('Could not find marketing');\n\t\t}\n\n\t\tswitch (oldMarketing.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tunauthorizedError(`Only admin is allowed to update ${data.marketingType} marketing`);\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.findOneAndUpdate(\n\t\t\t\t\t{\n\t\t\t\t\t\t_id: _id,\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t\tdata,\n\t\t\t\t\t{\n\t\t\t\t\t\tnew: true,\n\t\t\t\t\t\trunValidators: true,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!marketing) {\n\t\t\tinternalServerError('Could not update marketing');\n\t\t}\n\n\t\tif (admin) {\n\t\t\tconst allChanges = getChangedFields(oldMarketing, marketing);\n\t\t\tconst relevantChanges = filterRelevantChanges(allChanges, data);\n\n\t\t\tif (Object.keys(relevantChanges).includes('pausedAt')) {\n\t\t\t\tif (data.pausedAt == null) {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.CONTINUED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.PAUSED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.EDITED_MARKETING_PROMOTIONS,\n\t\t\t\toldMarketing,\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\treturn marketing;\n\t}\n\n\tprivate async logMarketingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: mongoose.Types.ObjectId): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tconst record = await this.model.findById(_id);\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete marketing',\n\t\t\t});\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(admin, AdminLogsUpdatedFieldsType.DELETED_MARKETING_PROMOTIONS, record);\n\t\t}\n\n\t\tproductMarketingService.deleteMany({ marketing: data._id }, data.softDelete);\n\n\t\treturn 'Record deleted successfully';\n\t}\n\n\tpublic async handleNewProductForEntireMenuMarketing(data: ProductEntireMenuMarketingHandlerDTO) {\n\t\tconst existingMarketing = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: { $in: [MarketingType.BUY1GET1, MarketingType.DISCOUNT] },\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\tisEntireMenu: true,\n\t\t});\n\n\t\t// check if existing marketing\n\t\tif (existingMarketing) {\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability([data.product]);\n\t\t\tif (isAvailable) {\n\t\t\t\tconst productMarketingData: CreateProductMarketingDTO = {\n\t\t\t\t\tproduct: data.product,\n\t\t\t\t\tmarketing: existingMarketing._id,\n\t\t\t\t};\n\t\t\t\tif (existingMarketing.marketingType == MarketingType.BUY1GET1) {\n\t\t\t\t\tproductMarketingData.isBuy1Get1 = true;\n\t\t\t\t}\n\t\t\t\tif (existingMarketing.marketingType == MarketingType.DISCOUNT) {\n\t\t\t\t\tproductMarketingData.value = (existingMarketing as DocumentType<DiscountMarketing>).value;\n\t\t\t\t\tproductMarketingData.valueType = (existingMarketing as DocumentType<DiscountMarketing>).valueType;\n\t\t\t\t}\n\t\t\t\tconst result = await productMarketingService.create(productMarketingData);\n\n\t\t\t\tconsole.log(`Created product marketing: ${result}`);\n\t\t\t}\n\t\t}\n\n\t\treturn 'Product handled successfully';\n\t}\n}\n\nexport const marketingService = Container.get(MarketingService);\n"]}
1
+ {"version":3,"file":"marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AAEzC,sEAKmD;AAenD,wEAA6G;AAE7G,8FAA6G;AAC7G,iGAAoG;AACpG,4DAAgG;AAChG,8DAAkE;AAGlE,wBAOW;AACX,4DAAkE;AAClE,4EAImD;AAG5C,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACpB,KAAK,CAAiD;IAE9D;QACC,IAAI,CAAC,KAAK,GAAG,uBAAgE,CAAC;IAC/E,CAAC;IAMM,KAAK,CAAC,MAAM,CAClB,IAAgC,EAChC,KAA+B;QAE/B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QAEvB,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;YAC/C,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,cAAc,EAAE,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE;YACnC,MAAM,EAAE,sBAAe,CAAC,MAAM;SAC9B,CAAC,CAAC;QACH,IAAI,cAAc,EAAE,CAAC;YACpB,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,2BAA2B,IAAI,CAAC,aAAa,YAAY;aAClE,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;gBAClD,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,gBAAgB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i';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport {\n\tDiscountMarketing,\n\tMarketingModel,\n\tMarketing as Model,\n\tPunchMarketingHistory,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tAllMarketingsDTO,\n\tAllMarketingsValidationDTO,\n\tCreateProductMarketingDTO,\n\tProductEntireMenuMarketingHandlerDTO,\n\tUpdateMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport {\n\tFilterDTO,\n\tPaginatedResponse,\n\tDeleteDTO,\n\tGetByIdInputDTO,\n} from '@lyxa.ai/core/dist/utilities/validation';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { filterRelevantChanges, getChangedFields } from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType, MarketingStatus } from '@lyxa.ai/core/dist/utilities/enum';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\n\nimport {\n\tbuy1Get1MarketingService,\n\tdiscountMarketingService,\n\tfeaturedMarketingService,\n\tfreeDeliveryMarketingService,\n\tproductMarketingService,\n\tpunchMarketingService,\n} from '.';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tinternalServerError,\n\tnotFoundError,\n\tunauthorizedError,\n} from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class MarketingService {\n\tprivate model: typeof MarketingModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.model = MarketingModel as typeof MarketingModel & SoftDeleteModel<Model>;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(\n\t\tdata: AllMarketingsValidationDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tconst now = new Date();\n\n\t\tconst existingRecord = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: data.marketingType,\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t});\n\t\tif (existingRecord) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `This shop already has a ${data.marketingType} marketing`,\n\t\t\t});\n\t\t}\n\n\t\tif (data.isEntireMenu) {\n\t\t\tconst existingMarketing = await this.model.findOne({\n\t\t\t\tshop: data.shop,\n\t\t\t\t'duration.start': { $lt: now },\n\t\t\t\t'duration.end': { $gt: now },\n\t\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\t\tmarketingType: { $in: [MarketingType.BUY1GET1, MarketingType.DISCOUNT] },\n\t\t\t});\n\t\t\tif (existingMarketing) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Cannot create marketing for entire menu while another product based marketing exists for the shop`,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (data.products && data.products.length > 0) {\n\t\t\tconst productIds = data.products.map((product: CreateProductMarketingDTO) => product.product);\n\n\t\t\tconst hasDuplicates = new Set(productIds.map(String)).size !== productIds.length;\n\n\t\t\tif (hasDuplicates) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'BAD_REQUEST',\n\t\t\t\t\tmessage: `Product list contains duplicate products`,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability(productIds);\n\n\t\t\tif (!isAvailable) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Product list contains products which already have marketing applied`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (admin) {\n\t\t\tdata.admin = admin;\n\t\t}\n\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tswitch (data.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: 'UNAUTHORIZED',\n\t\t\t\t\t\tmessage: `Only admin is allowed to create ${data.marketingType} marketing`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.create(data, admin);\n\t\t\t}\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.ACTIVATED_MARKETING_PROMOTIONS,\n\t\t\t\t'',\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\treturn marketing;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(data: GetByIdInputDTO): Promise<DocumentType<Model>> {\n\t\tconst select = data.select || '';\n\t\tconst populate = data.populate || [];\n\t\tconst result = await this.model\n\t\t\t.findOne({\n\t\t\t\t_id: data._id,\n\t\t\t})\n\t\t\t.select(select)\n\t\t\t.populate(populate);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(\n\t\t_id: mongoose.Types.ObjectId,\n\t\tdata: UpdateDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tconst oldMarketing = await this.model.findById(_id);\n\n\t\tif (!oldMarketing) {\n\t\t\tnotFoundError('Could not find marketing');\n\t\t}\n\n\t\tswitch (oldMarketing.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tunauthorizedError(`Only admin is allowed to update ${data.marketingType} marketing`);\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.findOneAndUpdate(\n\t\t\t\t\t{\n\t\t\t\t\t\t_id: _id,\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t\tdata,\n\t\t\t\t\t{\n\t\t\t\t\t\tnew: true,\n\t\t\t\t\t\trunValidators: true,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!marketing) {\n\t\t\tinternalServerError('Could not update marketing');\n\t\t}\n\n\t\tif (admin) {\n\t\t\tconst allChanges = getChangedFields(oldMarketing, marketing);\n\t\t\tconst relevantChanges = filterRelevantChanges(allChanges, data);\n\n\t\t\tif (Object.keys(relevantChanges).includes('pausedAt')) {\n\t\t\t\tif (data.pausedAt == null) {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.CONTINUED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.PAUSED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.EDITED_MARKETING_PROMOTIONS,\n\t\t\t\toldMarketing,\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\treturn marketing;\n\t}\n\n\tprivate async logMarketingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: mongoose.Types.ObjectId): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tconst record = await this.model.findById(_id);\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete marketing',\n\t\t\t});\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(admin, AdminLogsUpdatedFieldsType.DELETED_MARKETING_PROMOTIONS, record);\n\t\t}\n\n\t\tproductMarketingService.deleteMany({ marketing: data._id }, data.softDelete);\n\n\t\treturn 'Record deleted successfully';\n\t}\n\n\tpublic async handleNewProductForEntireMenuMarketing(data: ProductEntireMenuMarketingHandlerDTO) {\n\t\tconst existingMarketing = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: { $in: [MarketingType.BUY1GET1, MarketingType.DISCOUNT] },\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\tisEntireMenu: true,\n\t\t});\n\n\t\t// check if existing marketing\n\t\tif (existingMarketing) {\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability([data.product]);\n\t\t\tif (isAvailable) {\n\t\t\t\tconst productMarketingData: CreateProductMarketingDTO = {\n\t\t\t\t\tproduct: data.product,\n\t\t\t\t\tmarketing: existingMarketing._id,\n\t\t\t\t};\n\t\t\t\tif (existingMarketing.marketingType == MarketingType.BUY1GET1) {\n\t\t\t\t\tproductMarketingData.isBuy1Get1 = true;\n\t\t\t\t}\n\t\t\t\tif (existingMarketing.marketingType == MarketingType.DISCOUNT) {\n\t\t\t\t\tproductMarketingData.value = (existingMarketing as DocumentType<DiscountMarketing>).value;\n\t\t\t\t\tproductMarketingData.valueType = (existingMarketing as DocumentType<DiscountMarketing>).valueType;\n\t\t\t\t}\n\t\t\t\tconst result = await productMarketingService.create(productMarketingData);\n\n\t\t\t\tconsole.log(`Created product marketing: ${result}`);\n\t\t\t}\n\t\t}\n\n\t\treturn 'Product handled successfully';\n\t}\n}\n\nexport const marketingService = Container.get(MarketingService);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"featured-marketing.validation.d.ts","sourceRoot":"/","sources":["modules/marketing/validations/featured-marketing.validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGN,GAAG,EACH,MAAM,2DAA2D,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAsBlE,QAAA,MACa,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAC/B,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAC3B,yBAAyB,mNACrB,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCACQ,CAAC;AAErD,QAAA,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsB7C,CAAC;AAKF,OAAO,EACN,wCAAwC,IAAI,iCAAiC,EAC7E,uBAAuB,EACvB,yBAAyB,IAAI,mCAAmC,EAChE,6BAA6B,GAC7B,CAAC;AAKF,MAAM,MAAM,0BAA0B,GAAG,GAAG,CAAC,OAAO,iCAAiC,CAAC,CAAC;AACvF,MAAM,MAAM,oBAAoB,GAAG,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACvE,MAAM,MAAM,0BAA0B,GAAG,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC"}
1
+ {"version":3,"file":"featured-marketing.validation.d.ts","sourceRoot":"/","sources":["modules/marketing/validations/featured-marketing.validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGN,GAAG,EACH,MAAM,2DAA2D,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAsBlE,QAAA,MACa,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAC/B,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAC3B,yBAAyB,mNACrB,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCACQ,CAAC;AAErD,QAAA,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuB7C,CAAC;AAKF,OAAO,EACN,wCAAwC,IAAI,iCAAiC,EAC7E,uBAAuB,EACvB,yBAAyB,IAAI,mCAAmC,EAChE,6BAA6B,GAC7B,CAAC;AAKF,MAAM,MAAM,0BAA0B,GAAG,GAAG,CAAC,OAAO,iCAAiC,CAAC,CAAC;AACvF,MAAM,MAAM,oBAAoB,GAAG,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACvE,MAAM,MAAM,0BAA0B,GAAG,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC"}
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.UpdateFeaturedMarketingSchema = exports.FeaturedMarketingIdValidationSchema = exports.FeaturedMarketingSchema = exports.FeaturedMarketingValidationSchema = void 0;
7
4
  const zod_1 = require("zod");
8
5
  const global_validation_1 = require("@lyxa.ai/core/dist/utilities/validation/global-validation");
9
6
  const marketing_validation_1 = require("./marketing.validation");
10
7
  const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
11
- const dayjs_1 = __importDefault(require("dayjs"));
8
+ const dayjs_1 = require("@lyxa.ai/core/dist/utilities/dayjs");
12
9
  const baseFields = {
13
10
  ...marketing_validation_1.baseMarketingFields,
14
11
  marketingType: zod_1.z.literal(enum_1.MarketingType.FEATURED),
@@ -27,15 +24,17 @@ const FeaturedMarketingValidationSchemaRefined = FeaturedMarketingValidationSche
27
24
  path: ['isAppliedByCompany'],
28
25
  });
29
26
  }
30
- const startDate = (0, dayjs_1.default)(data.duration.start);
31
- const endDate = (0, dayjs_1.default)(data.duration.end);
32
- const diff = endDate.diff(startDate, 'day');
33
- if (diff < 3 || diff > 28) {
34
- ctx.addIssue({
35
- code: zod_1.z.ZodIssueCode.custom,
36
- message: 'Duration should be between 3 and 28 days',
37
- path: ['duration'],
38
- });
27
+ if (data.duration) {
28
+ const startDate = (0, dayjs_1.dayjs)(data.duration.start);
29
+ const endDate = (0, dayjs_1.dayjs)(data.duration.end);
30
+ const diff = endDate.diff(startDate, 'day');
31
+ if (diff < 3 || diff > 28) {
32
+ ctx.addIssue({
33
+ code: zod_1.z.ZodIssueCode.custom,
34
+ message: 'Duration should be between 3 and 28 days',
35
+ path: ['duration'],
36
+ });
37
+ }
39
38
  }
40
39
  });
41
40
  exports.FeaturedMarketingValidationSchema = FeaturedMarketingValidationSchemaRefined;
@@ -1 +1 @@
1
- {"version":3,"file":"featured-marketing.validation.js","sourceRoot":"/","sources":["modules/marketing/validations/featured-marketing.validation.ts"],"names":[],"mappings":";;;;;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,iEAA6D;AAC7D,4DAAkE;AAClE,kDAA0B;AAK1B,MAAM,UAAU,GAAG;IAClB,GAAG,0CAAmB;IACtB,aAAa,EAAE,OAAC,CAAC,OAAO,CAAC,oBAAa,CAAC,QAAQ,CAAC;IAChD,MAAM,EAAE,iCAAa,CAAC,MAAM,CAAC,QAAQ,CAAC;CACtC,CAAC;AAOF,MAAM,aAAa,GAAG,IAAA,uCAAmB,EAAC,UAAU,CAAC,CAAC;AAKtD,MAAM,EACL,UAAU,EAAE,iCAAiC,EAC7C,YAAY,EAAE,uBAAuB,EACrC,QAAQ,EAAE,yBAAyB,EACnC,YAAY,EAAE,6BAA6B,GAC3C,GAAG,aAAa,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AA+BpD,0DAAuB;AACM,wEAAmC;AAChE,sEAA6B;AA/B9B,MAAM,wCAAwC,GAAG,iCAAiC,CAAC,WAAW,CAC7F,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IAEb,IAAI,IAAI,CAAC,kBAAkB,IAAI,KAAK,EAAE,CAAC;QACtC,GAAG,CAAC,QAAQ,CAAC;YACZ,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,iDAAiD;YAC1D,IAAI,EAAE,CAAC,oBAAoB,CAAC;SAC5B,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,IAAA,eAAK,EAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC7C,MAAM,OAAO,GAAG,IAAA,eAAK,EAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC5C,IAAI,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,EAAE,EAAE,CAAC;QAC3B,GAAG,CAAC,QAAQ,CAAC;YACZ,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,0CAA0C;YACnD,IAAI,EAAE,CAAC,UAAU,CAAC;SAClB,CAAC,CAAC;IACJ,CAAC;AACF,CAAC,CACD,CAAC;AAM2C,qFAAiC","sourcesContent":["import { z } from 'zod';\nimport {\n\tZodValidation,\n\tcreateSchemaBuilder,\n\tDTO,\n} from '@lyxa.ai/core/dist/utilities/validation/global-validation';\nimport { baseMarketingFields } from './marketing.validation';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport dayjs from 'dayjs';\n\n/**\n * Define the base parent schema fields\n */\nconst baseFields = {\n\t...baseMarketingFields,\n\tmarketingType: z.literal(MarketingType.FEATURED),\n\tamount: ZodValidation.number('Amount'),\n};\n\n/**\n * Create schema builder for Parent entity\n * - Includes timestamps\n * - Excludes 'createdAt' from update operations\n */\nconst schemaBuilder = createSchemaBuilder(baseFields);\n\n/**\n * Get all schemas for the Parent entity\n */\nconst {\n\tBaseSchema: FeaturedMarketingValidationSchema,\n\tEntitySchema: FeaturedMarketingSchema,\n\tIdSchema: FeaturedMarketingIdSchema,\n\tUpdateSchema: UpdateFeaturedMarketingSchema,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\nconst FeaturedMarketingValidationSchemaRefined = FeaturedMarketingValidationSchema.superRefine(\n\t(data, ctx) => {\n\n\t\tif (data.isAppliedByCompany == false) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Featured marketing can only be created by admin',\n\t\t\t\tpath: ['isAppliedByCompany'],\n\t\t\t});\n\t\t}\n\n\t\tconst startDate = dayjs(data.duration.start);\n\t\tconst endDate = dayjs(data.duration.end);\n\t\tconst diff = endDate.diff(startDate, 'day');\n\t\tif (diff < 3 || diff > 28) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Duration should be between 3 and 28 days',\n\t\t\t\tpath: ['duration'],\n\t\t\t});\n\t\t}\n\t}\n);\n\n/**\n * Export schemas\n */\nexport {\n\tFeaturedMarketingValidationSchemaRefined as FeaturedMarketingValidationSchema,\n\tFeaturedMarketingSchema,\n\tFeaturedMarketingIdSchema as FeaturedMarketingIdValidationSchema,\n\tUpdateFeaturedMarketingSchema,\n};\n\n/**\n * Export DTO types\n */\nexport type CreateFeaturedMarketingDTO = DTO<typeof FeaturedMarketingValidationSchema>;\nexport type FeaturedMarketingDTO = DTO<typeof FeaturedMarketingSchema>;\nexport type UpdateFeaturedMarketingDTO = DTO<typeof UpdateFeaturedMarketingSchema>;\n"]}
1
+ {"version":3,"file":"featured-marketing.validation.js","sourceRoot":"/","sources":["modules/marketing/validations/featured-marketing.validation.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,iEAA6D;AAC7D,4DAAkE;AAClE,8DAA2D;AAK3D,MAAM,UAAU,GAAG;IAClB,GAAG,0CAAmB;IACtB,aAAa,EAAE,OAAC,CAAC,OAAO,CAAC,oBAAa,CAAC,QAAQ,CAAC;IAChD,MAAM,EAAE,iCAAa,CAAC,MAAM,CAAC,QAAQ,CAAC;CACtC,CAAC;AAOF,MAAM,aAAa,GAAG,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ation,\n\tcreateSchemaBuilder,\n\tDTO,\n} from '@lyxa.ai/core/dist/utilities/validation/global-validation';\nimport { baseMarketingFields } from './marketing.validation';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\n\n/**\n * Define the base parent schema fields\n */\nconst baseFields = {\n\t...baseMarketingFields,\n\tmarketingType: z.literal(MarketingType.FEATURED),\n\tamount: ZodValidation.number('Amount'),\n};\n\n/**\n * Create schema builder for Parent entity\n * - Includes timestamps\n * - Excludes 'createdAt' from update operations\n */\nconst schemaBuilder = createSchemaBuilder(baseFields);\n\n/**\n * Get all schemas for the Parent entity\n */\nconst {\n\tBaseSchema: FeaturedMarketingValidationSchema,\n\tEntitySchema: FeaturedMarketingSchema,\n\tIdSchema: FeaturedMarketingIdSchema,\n\tUpdateSchema: UpdateFeaturedMarketingSchema,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\nconst FeaturedMarketingValidationSchemaRefined = FeaturedMarketingValidationSchema.superRefine(\n\t(data, ctx) => {\n\t\tif (data.isAppliedByCompany == false) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Featured marketing can only be created by admin',\n\t\t\t\tpath: ['isAppliedByCompany'],\n\t\t\t});\n\t\t}\n\n\t\tif (data.duration) {\n\t\t\tconst startDate = dayjs(data.duration.start);\n\t\t\tconst endDate = dayjs(data.duration.end);\n\t\t\tconst diff = endDate.diff(startDate, 'day');\n\t\t\tif (diff < 3 || diff > 28) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: 'Duration should be between 3 and 28 days',\n\t\t\t\t\tpath: ['duration'],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n);\n\n/**\n * Export schemas\n */\nexport {\n\tFeaturedMarketingValidationSchemaRefined as FeaturedMarketingValidationSchema,\n\tFeaturedMarketingSchema,\n\tFeaturedMarketingIdSchema as FeaturedMarketingIdValidationSchema,\n\tUpdateFeaturedMarketingSchema,\n};\n\n/**\n * Export DTO types\n */\nexport type CreateFeaturedMarketingDTO = DTO<typeof FeaturedMarketingValidationSchema>;\nexport type FeaturedMarketingDTO = DTO<typeof FeaturedMarketingSchema>;\nexport type UpdateFeaturedMarketingDTO = DTO<typeof UpdateFeaturedMarketingSchema>;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"free-delivery-marketing.validation.d.ts","sourceRoot":"/","sources":["modules/marketing/validations/free-delivery-marketing.validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGN,GAAG,EACH,MAAM,2DAA2D,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAsBlE,QAAA,MAEe,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAC/B,6BAA6B,iNAEY,CAAC;AAErD,QAAA,MAAM,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBxC,CAAC;AAEJ,QAAA,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAiBtC,CAAC;AAKF,OAAO,EACN,qCAAqC,EACrC,2BAA2B,EAC3B,6BAA6B,IAAI,uCAAuC,EACxE,iCAAiC,GACjC,CAAC;AAKF,MAAM,MAAM,8BAA8B,GAAG,GAAG,CAAC,OAAO,qCAAqC,CAAC,CAAC;AAC/F,MAAM,MAAM,wBAAwB,GAAG,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAC/E,MAAM,MAAM,8BAA8B,GAAG,GAAG,CAAC,OAAO,iCAAiC,CAAC,CAAC"}
1
+ {"version":3,"file":"free-delivery-marketing.validation.d.ts","sourceRoot":"/","sources":["modules/marketing/validations/free-delivery-marketing.validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGN,GAAG,EACH,MAAM,2DAA2D,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAsBlE,QAAA,MAEe,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAC/B,6BAA6B,iNAEY,CAAC;AAErD,QAAA,MAAM,qCAAqC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgBxC,CAAC;AAEJ,QAAA,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAmBtC,CAAC;AAKF,OAAO,EACN,qCAAqC,EACrC,2BAA2B,EAC3B,6BAA6B,IAAI,uCAAuC,EACxE,iCAAiC,GACjC,CAAC;AAKF,MAAM,MAAM,8BAA8B,GAAG,GAAG,CAAC,OAAO,qCAAqC,CAAC,CAAC;AAC/F,MAAM,MAAM,wBAAwB,GAAG,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAC/E,MAAM,MAAM,8BAA8B,GAAG,GAAG,CAAC,OAAO,iCAAiC,CAAC,CAAC"}
@@ -40,12 +40,14 @@ const UpdateFreeDeliveryMarketingSchema = UpdateFreeDeliveryMarketingSchemaWitho
40
40
  path: ['spendLimit', 'isSpendLimitEnabled'],
41
41
  });
42
42
  }
43
- if (!data.duration.end) {
44
- ctx.addIssue({
45
- code: zod_1.z.ZodIssueCode.custom,
46
- message: 'End date is required',
47
- path: ['duration', 'end'],
48
- });
43
+ if (data.duration) {
44
+ if (!data.duration.end) {
45
+ ctx.addIssue({
46
+ code: zod_1.z.ZodIssueCode.custom,
47
+ message: 'End date is required',
48
+ path: ['duration', 'end'],
49
+ });
50
+ }
49
51
  }
50
52
  });
51
53
  exports.UpdateFreeDeliveryMarketingSchema = UpdateFreeDeliveryMarketingSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"free-delivery-marketing.validation.js","sourceRoot":"/","sources":["modules/marketing/validations/free-delivery-marketing.validation.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,iEAA6D;AAC7D,4DAAkE;AAKlE,MAAM,UAAU,GAAG;IAClB,GAAG,0CAAmB;IACtB,aAAa,EAAE,OAAC,CAAC,OAAO,CAAC,oBAAa,CAAC,aAAa,CAAC;IACrD,UAAU,EAAE,iCAAa,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,mBAAmB,EAAE,iCAAa,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;CACnF,CAAC;AAOF,MAAM,aAAa,GAAG,IAAA,uCAAmB,EAAC,UAAU,CAAC,CAAC;AAKtD,MAAM,EACL,UAAU,EAAE,sDAAsD,EAClE,YAAY,EAAE,2BAA2B,EACzC,QAAQ,EAAE,6BAA6B,EACvC,YAAY,EAAE,kDAAkD,GAChE,GAAG,aAAa,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AA4CpD,kEAA2B;AACM,gFAAuC;AA3CzE,MAAM,qCAAqC,GAC1C,sDAAsD,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IAChF,IAAI,IAAI,CAAC,mBAAmB,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5E,GAAG,CA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core/dist/utilities/validation/global-validation';\nimport { baseMarketingFields } from './marketing.validation';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\n\n/**\n * Define the base parent schema fields\n */\nconst baseFields = {\n\t...baseMarketingFields,\n\tmarketingType: z.literal(MarketingType.FREE_DELIVERY),\n\tspendLimit: ZodValidation.number('Spend limit').default(0),\n\tisSpendLimitEnabled: ZodValidation.boolean('Is spend limit enabled').default(false),\n};\n\n/**\n * Create schema builder for Parent entity\n * - Includes timestamps\n * - Excludes 'createdAt' from update operations\n */\nconst schemaBuilder = createSchemaBuilder(baseFields);\n\n/**\n * Get all schemas for the Parent entity\n */\nconst {\n\tBaseSchema: FreeDeliveryMarketingValidationSchemaWithoutRefinement,\n\tEntitySchema: FreeDeliveryMarketingSchema,\n\tIdSchema: FreeDeliveryMarketingIdSchema,\n\tUpdateSchema: UpdateFreeDeliveryMarketingSchemaWithoutRefinement,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\nconst FreeDeliveryMarketingValidationSchema =\n\tFreeDeliveryMarketingValidationSchemaWithoutRefinement.superRefine((data, ctx) => {\n\t\tif (data.isSpendLimitEnabled && (!data.spendLimit || data.spendLimit <= 0)) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Spend limit must be greater than 0 when enabled',\n\t\t\t\tpath: ['spendLimit', 'isSpendLimitEnabled'],\n\t\t\t});\n\t\t}\n\t\tif (!data.duration.end) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'End date is required',\n\t\t\t\tpath: ['duration', 'end'],\n\t\t\t});\n\t\t}\n\t});\n\nconst UpdateFreeDeliveryMarketingSchema = UpdateFreeDeliveryMarketingSchemaWithoutRefinement.superRefine(\n\t(data, ctx) => {\n\t\tif (data.isSpendLimitEnabled && (!data.spendLimit || data.spendLimit <= 0)) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Spend limit must be greater than 0 when enabled',\n\t\t\t\tpath: ['spendLimit', 'isSpendLimitEnabled'],\n\t\t\t});\n\t\t}\n\t\tif (!data.duration.end) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'End date is required',\n\t\t\t\tpath: ['duration', 'end'],\n\t\t\t});\n\t\t}\n\t}\n);\n\n/**\n * Export schemas\n */\nexport {\n\tFreeDeliveryMarketingValidationSchema,\n\tFreeDeliveryMarketingSchema,\n\tFreeDeliveryMarketingIdSchema as FreeDeliveryMarketingIdValidationSchema,\n\tUpdateFreeDeliveryMarketingSchema,\n};\n\n/**\n * Export DTO types\n */\nexport type CreateFreeDeliveryMarketingDTO = DTO<typeof FreeDeliveryMarketingValidationSchema>;\nexport type FreeDeliveryMarketingDTO = DTO<typeof FreeDeliveryMarketingSchema>;\nexport type UpdateFreeDeliveryMarketingDTO = DTO<typeof UpdateFreeDeliveryMarketingSchema>;\n"]}
1
+ {"version":3,"file":"free-delivery-marketing.validation.js","sourceRoot":"/","sources":["modules/marketing/validations/free-delivery-marketing.validation.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,iEAA6D;AAC7D,4DAAkE;AAKlE,MAAM,UAAU,GAAG;IAClB,GAAG,0CAAmB;IACtB,aAAa,EAAE,OAAC,CAAC,OAAO,CAAC,oBAAa,CAAC,aAAa,CAAC;IACrD,UAAU,EAAE,iCAAa,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,mBAAmB,EAAE,iCAAa,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;CACnF,CAAC;AAOF,MAAM,aAAa,GAAG,IAAA,uCAAmB,EAAC,UAAU,CAAC,CAAC;AAKtD,MAAM,EACL,UAAU,EAAE,sDAAsD,EAClE,YAAY,EAAE,2BAA2B,EACzC,QA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CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;YACxB,GAAG,CAAC,QAAQ,CAAC;gBACZ,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;gBAC3B,OAAO,EAAE,sBAAsB;gBAC/B,IAAI,EAAE,CAAC,UAAU,EAAE,KAAK,CAAC;aACzB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC,CACD,CAAC;AASD,8EAAiC","sourcesContent":["import { z } from 'zod';\nimport {\n\tZodValidation,\n\tcreateSchemaBuilder,\n\tDTO,\n} from '@lyxa.ai/core/dist/utilities/validation/global-validation';\nimport { baseMarketingFields } from './marketing.validation';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\n\n/**\n * Define the base parent schema fields\n */\nconst baseFields = {\n\t...baseMarketingFields,\n\tmarketingType: z.literal(MarketingType.FREE_DELIVERY),\n\tspendLimit: ZodValidation.number('Spend limit').default(0),\n\tisSpendLimitEnabled: ZodValidation.boolean('Is spend limit enabled').default(false),\n};\n\n/**\n * Create schema builder for Parent entity\n * - Includes timestamps\n * - Excludes 'createdAt' from update operations\n */\nconst schemaBuilder = createSchemaBuilder(baseFields);\n\n/**\n * Get all schemas for the Parent entity\n */\nconst {\n\tBaseSchema: FreeDeliveryMarketingValidationSchemaWithoutRefinement,\n\tEntitySchema: FreeDeliveryMarketingSchema,\n\tIdSchema: FreeDeliveryMarketingIdSchema,\n\tUpdateSchema: UpdateFreeDeliveryMarketingSchemaWithoutRefinement,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\nconst FreeDeliveryMarketingValidationSchema =\n\tFreeDeliveryMarketingValidationSchemaWithoutRefinement.superRefine((data, ctx) => {\n\t\tif (data.isSpendLimitEnabled && (!data.spendLimit || data.spendLimit <= 0)) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Spend limit must be greater than 0 when enabled',\n\t\t\t\tpath: ['spendLimit', 'isSpendLimitEnabled'],\n\t\t\t});\n\t\t}\n\t\tif (!data.duration.end) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'End date is required',\n\t\t\t\tpath: ['duration', 'end'],\n\t\t\t});\n\t\t}\n\t});\n\nconst UpdateFreeDeliveryMarketingSchema = UpdateFreeDeliveryMarketingSchemaWithoutRefinement.superRefine(\n\t(data, ctx) => {\n\t\tif (data.isSpendLimitEnabled && (!data.spendLimit || data.spendLimit <= 0)) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Spend limit must be greater than 0 when enabled',\n\t\t\t\tpath: ['spendLimit', 'isSpendLimitEnabled'],\n\t\t\t});\n\t\t}\n\t\tif (data.duration) {\n\t\t\tif (!data.duration.end) {\n\t\t\t\tctx.addIssue({\n\t\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\t\tmessage: 'End date is required',\n\t\t\t\t\tpath: ['duration', 'end'],\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n);\n\n/**\n * Export schemas\n */\nexport {\n\tFreeDeliveryMarketingValidationSchema,\n\tFreeDeliveryMarketingSchema,\n\tFreeDeliveryMarketingIdSchema as FreeDeliveryMarketingIdValidationSchema,\n\tUpdateFreeDeliveryMarketingSchema,\n};\n\n/**\n * Export DTO types\n */\nexport type CreateFreeDeliveryMarketingDTO = DTO<typeof FreeDeliveryMarketingValidationSchema>;\nexport type FreeDeliveryMarketingDTO = DTO<typeof FreeDeliveryMarketingSchema>;\nexport type UpdateFreeDeliveryMarketingDTO = DTO<typeof UpdateFreeDeliveryMarketingSchema>;\n"]}
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.UpdatePunchMarketingSchema = exports.PunchMarketingIdValidationSchema = exports.PunchMarketingSchema = exports.PunchMarketingValidationSchema = void 0;
7
4
  const zod_1 = require("zod");
8
5
  const global_validation_1 = require("@lyxa.ai/core/dist/utilities/validation/global-validation");
9
6
  const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
10
7
  const marketing_validation_1 = require("./marketing.validation");
11
- const dayjs_1 = __importDefault(require("dayjs"));
8
+ const dayjs_1 = require("@lyxa.ai/core/dist/utilities/dayjs");
12
9
  const baseFields = {
13
10
  ...marketing_validation_1.baseMarketingFields,
14
11
  marketingType: zod_1.z.literal(enum_1.MarketingType.PUNCH_MARKETING),
@@ -50,7 +47,7 @@ const PunchMarketingValidationSchema = PunchMarketingValidationSchemaWithoutRefi
50
47
  });
51
48
  }
52
49
  if (data.dayLimit) {
53
- const durationInDays = (0, dayjs_1.default)(data.duration.end).diff((0, dayjs_1.default)(data.duration.start), 'day') + 1;
50
+ const durationInDays = (0, dayjs_1.dayjs)(data.duration.end).diff((0, dayjs_1.dayjs)(data.duration.start), 'day') + 1;
54
51
  if (data.dayLimit > durationInDays) {
55
52
  ctx.addIssue({
56
53
  code: zod_1.z.ZodIssueCode.custom,
@@ -88,7 +85,7 @@ const UpdatePunchMarketingSchema = UpdatePunchMarketingSchemaWithoutRefinement.s
88
85
  });
89
86
  }
90
87
  if (data.dayLimit) {
91
- const durationInDays = (0, dayjs_1.default)(data.duration.end).diff((0, dayjs_1.default)(data.duration.start), 'day') + 1;
88
+ const durationInDays = (0, dayjs_1.dayjs)(data.duration.end).diff((0, dayjs_1.dayjs)(data.duration.start), 'day') + 1;
92
89
  if (data.dayLimit > durationInDays) {
93
90
  ctx.addIssue({
94
91
  code: zod_1.z.ZodIssueCode.custom,