@lyxa.ai/marketing 1.0.26 → 1.0.28

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 (89) hide show
  1. package/dist/lib/index.d.ts +11 -4
  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 +1 -0
  8. package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
  9. package/dist/lib/modules/coupon/services/coupon.service.js +22 -0
  10. package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
  11. package/dist/lib/modules/marketing/routers/marketing.router.d.ts +4 -4
  12. package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  13. package/dist/lib/modules/marketing/routers/marketing.router.js +0 -2
  14. package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
  15. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
  16. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js +38 -18
  17. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js.map +1 -1
  18. package/dist/lib/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
  19. package/dist/lib/modules/marketing/services/discount-marketing.service.js +37 -17
  20. package/dist/lib/modules/marketing/services/discount-marketing.service.js.map +1 -1
  21. package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
  22. package/dist/lib/modules/marketing/services/marketing.service.js +4 -1
  23. package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
  24. package/dist/lib/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +2 -0
  25. package/dist/lib/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts.map +1 -1
  26. package/dist/lib/modules/marketing/transformers/discount-marketing.transformer.d.ts +2 -0
  27. package/dist/lib/modules/marketing/transformers/discount-marketing.transformer.d.ts.map +1 -1
  28. package/dist/lib/modules/marketing/transformers/featured-marketing.transformer.d.ts +1 -0
  29. package/dist/lib/modules/marketing/transformers/featured-marketing.transformer.d.ts.map +1 -1
  30. package/dist/lib/modules/marketing/transformers/free-delivery-marketing.transformer.d.ts +1 -0
  31. package/dist/lib/modules/marketing/transformers/free-delivery-marketing.transformer.d.ts.map +1 -1
  32. package/dist/lib/modules/marketing/transformers/punch-marketing.transformer.d.ts +1 -0
  33. package/dist/lib/modules/marketing/transformers/punch-marketing.transformer.d.ts.map +1 -1
  34. package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +28 -0
  35. package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts.map +1 -1
  36. package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.js +1 -0
  37. package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.js.map +1 -1
  38. package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts +254 -123
  39. package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts.map +1 -1
  40. package/dist/lib/modules/marketing/validations/discount-marketing.validation.js +19 -3
  41. package/dist/lib/modules/marketing/validations/discount-marketing.validation.js.map +1 -1
  42. package/dist/lib/modules/marketing/validations/featured-marketing.validation.d.ts +14 -0
  43. package/dist/lib/modules/marketing/validations/featured-marketing.validation.d.ts.map +1 -1
  44. package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.d.ts +107 -26
  45. package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.d.ts.map +1 -1
  46. package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.js +34 -2
  47. package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.js.map +1 -1
  48. package/dist/lib/modules/marketing/validations/marketing.validation.d.ts +10 -0
  49. package/dist/lib/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
  50. package/dist/lib/modules/marketing/validations/marketing.validation.js +1 -0
  51. package/dist/lib/modules/marketing/validations/marketing.validation.js.map +1 -1
  52. package/dist/lib/modules/marketing/validations/punch-marketing.validation.d.ts +127 -30
  53. package/dist/lib/modules/marketing/validations/punch-marketing.validation.d.ts.map +1 -1
  54. package/dist/lib/modules/marketing/validations/punch-marketing.validation.js +80 -2
  55. package/dist/lib/modules/marketing/validations/punch-marketing.validation.js.map +1 -1
  56. package/dist/types/index.d.ts +11 -4
  57. package/dist/types/index.d.ts.map +1 -1
  58. package/dist/types/modules/coupon/routers/coupon.router.d.ts +7 -0
  59. package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
  60. package/dist/types/modules/coupon/services/coupon.service.d.ts +1 -0
  61. package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
  62. package/dist/types/modules/marketing/routers/marketing.router.d.ts +4 -4
  63. package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  64. package/dist/types/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
  65. package/dist/types/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
  66. package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
  67. package/dist/types/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +2 -0
  68. package/dist/types/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts.map +1 -1
  69. package/dist/types/modules/marketing/transformers/discount-marketing.transformer.d.ts +2 -0
  70. package/dist/types/modules/marketing/transformers/discount-marketing.transformer.d.ts.map +1 -1
  71. package/dist/types/modules/marketing/transformers/featured-marketing.transformer.d.ts +1 -0
  72. package/dist/types/modules/marketing/transformers/featured-marketing.transformer.d.ts.map +1 -1
  73. package/dist/types/modules/marketing/transformers/free-delivery-marketing.transformer.d.ts +1 -0
  74. package/dist/types/modules/marketing/transformers/free-delivery-marketing.transformer.d.ts.map +1 -1
  75. package/dist/types/modules/marketing/transformers/punch-marketing.transformer.d.ts +1 -0
  76. package/dist/types/modules/marketing/transformers/punch-marketing.transformer.d.ts.map +1 -1
  77. package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +28 -0
  78. package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts.map +1 -1
  79. package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts +254 -123
  80. package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts.map +1 -1
  81. package/dist/types/modules/marketing/validations/featured-marketing.validation.d.ts +14 -0
  82. package/dist/types/modules/marketing/validations/featured-marketing.validation.d.ts.map +1 -1
  83. package/dist/types/modules/marketing/validations/free-delivery-marketing.validation.d.ts +107 -26
  84. package/dist/types/modules/marketing/validations/free-delivery-marketing.validation.d.ts.map +1 -1
  85. package/dist/types/modules/marketing/validations/marketing.validation.d.ts +10 -0
  86. package/dist/types/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
  87. package/dist/types/modules/marketing/validations/punch-marketing.validation.d.ts +127 -30
  88. package/dist/types/modules/marketing/validations/punch-marketing.validation.d.ts.map +1 -1
  89. package/package.json +2 -2
@@ -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,IAAI,KAAK,EAE1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAIxC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAoDrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAoEnF,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"}
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,IAAI,KAAK,EAE1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAIxC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAuErD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,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"}
@@ -58,38 +58,52 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
58
58
  const result = await this.model.create(data);
59
59
  if (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {
60
60
  for (const product of data.products) {
61
- this.productMarketingsCreate(result._id, product.product);
61
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
62
+ this.productMarketingsCreate(result._id, product.product);
63
+ }
62
64
  }
63
65
  }
64
- else if (data.categories && data.categories.length > 0 && (!data.products || data.products.length === 0)) {
65
- const categoryWiseProducts = await this.productModel.find({
66
- shopCategory: { $in: data.categories }
66
+ else if (data.categories &&
67
+ data.categories.length > 0 &&
68
+ (!data.products || data.products.length === 0)) {
69
+ const categoryWiseProducts = await this.productModel
70
+ .find({
71
+ shopCategory: { $in: data.categories },
67
72
  })
68
73
  .lean();
69
74
  for (const product of categoryWiseProducts) {
70
- this.productMarketingsCreate(result._id, product._id);
75
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
76
+ this.productMarketingsCreate(result._id, product._id);
77
+ }
71
78
  }
72
79
  }
73
80
  else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {
74
- const categoryWiseProducts = await this.productModel.find({
75
- shopCategory: { $in: data.categories }
81
+ const categoryWiseProducts = await this.productModel
82
+ .find({
83
+ shopCategory: { $in: data.categories },
76
84
  })
77
85
  .lean();
78
86
  for (const product of categoryWiseProducts) {
79
- this.productMarketingsCreate(result._id, product._id);
87
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
88
+ this.productMarketingsCreate(result._id, product._id);
89
+ }
80
90
  }
81
91
  for (const product of data.products) {
82
- this.productMarketingsCreate(result._id, product.product);
92
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
93
+ this.productMarketingsCreate(result._id, product.product);
94
+ }
83
95
  }
84
96
  }
85
97
  else if (data.isEntireMenu) {
86
98
  this.productModel
87
- .find({ shop: data.shop, })
99
+ .find({ shop: data.shop })
88
100
  .select('_id')
89
101
  .exec()
90
102
  .then(productDocuments => {
91
103
  for (const product of productDocuments) {
92
- this.productMarketingsCreate(result._id, product._id);
104
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
105
+ this.productMarketingsCreate(result._id, product._id);
106
+ }
93
107
  }
94
108
  });
95
109
  }
@@ -104,7 +118,9 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
104
118
  new: true,
105
119
  runValidators: true,
106
120
  });
107
- if ((data.products && data.products.length > 0) || (data.categories && data.categories.length > 0) || data.isEntireMenu) {
121
+ if ((data.products && data.products.length > 0) ||
122
+ (data.categories && data.categories.length > 0) ||
123
+ data.isEntireMenu) {
108
124
  await _1.productMarketingService.deleteMany({ marketing: _id }, true);
109
125
  }
110
126
  if (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {
@@ -112,9 +128,12 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
112
128
  this.productMarketingsCreate(_id, product.product);
113
129
  }
114
130
  }
115
- else if (data.categories && data.categories.length > 0 && (!data.products || data.products.length === 0)) {
116
- const categoryWiseProducts = await this.productModel.find({
117
- shopCategory: { $in: data.categories }
131
+ else if (data.categories &&
132
+ data.categories.length > 0 &&
133
+ (!data.products || data.products.length === 0)) {
134
+ const categoryWiseProducts = await this.productModel
135
+ .find({
136
+ shopCategory: { $in: data.categories },
118
137
  })
119
138
  .lean();
120
139
  for (const product of categoryWiseProducts) {
@@ -122,8 +141,9 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
122
141
  }
123
142
  }
124
143
  else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {
125
- const categoryWiseProducts = await this.productModel.find({
126
- shopCategory: { $in: data.categories }
144
+ const categoryWiseProducts = await this.productModel
145
+ .find({
146
+ shopCategory: { $in: data.categories },
127
147
  })
128
148
  .lean();
129
149
  for (const product of categoryWiseProducts) {
@@ -135,7 +155,7 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
135
155
  }
136
156
  else if (data.isEntireMenu) {
137
157
  this.productModel
138
- .find({ shop: data.shop, })
158
+ .find({ shop: data.shop })
139
159
  .select('_id')
140
160
  .exec()
141
161
  .then(productDocuments => {
@@ -1 +1 @@
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,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;YACrG,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrC,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YAC3D,CAAC;QACF,CAAC;aAAM,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;YAC5G,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC;gBACzD,YAAY,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC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AI,CAAC,uBAAuB,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;AA/IY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CA+IpC;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\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && (!data.products || data.products.length === 0)) { // Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel.find({\n\t\t\t\tshopCategory: { $in: data.categories }\n\t\t\t})\n\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) { // Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel.find({\n\t\t\t\tshopCategory: { $in: data.categories }\n\t\t\t})\n\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(result._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(result._id, product.product);\n\t\t\t}\n\t\t} else if (data.isEntireMenu) { // 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(result._id, product._id);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\t\t\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((data.products && data.products.length > 0) || (data.categories && data.categories.length > 0) || data.isEntireMenu) {\n\t\t\tawait productMarketingService.deleteMany(\n\t\t\t\t{ marketing: _id },\n\t\t\t\ttrue\n\t\t\t);\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 (data.categories && data.categories.length > 0 && (!data.products || data.products.length === 0)) { // Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel.find({\n\t\t\t\tshopCategory: { $in: data.categories }\n\t\t\t})\n\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) { // Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel.find({\n\t\t\t\tshopCategory: { $in: data.categories }\n\t\t\t})\n\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) { // 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,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC;YACrG,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,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;gBAC3D,CAAC;YACF,CAAC;QACF,CAAC;aAA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/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;AA5KY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CA4KpC;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 +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;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAG9D,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA8ErD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA+FnF,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"}
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;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAG9D,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAuHrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,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"}
@@ -59,21 +59,28 @@ let DiscountMarketingService = class DiscountMarketingService {
59
59
  if (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {
60
60
  for (const product of data.products) {
61
61
  if (product.valueType !== undefined && product.valueType !== null) {
62
- await this.productMarketingsCreate(result._id, product.product, Number(product.value), product.valueType);
62
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
63
+ await this.productMarketingsCreate(result._id, product.product, Number(product.value), product.valueType);
64
+ }
63
65
  }
64
66
  else {
65
67
  (0, error_common_1.badRequestError)('Product discount value & value-type is required');
66
68
  }
67
69
  }
68
70
  }
69
- else if (data.categories && data.categories.length > 0 && (!data.products || data.products.length === 0)) {
70
- const categoryWiseProducts = await this.productModel.find({
71
- shopCategory: { $in: data.categories }
71
+ else if (data.categories &&
72
+ data.categories.length > 0 &&
73
+ (!data.products || data.products.length === 0)) {
74
+ const categoryWiseProducts = await this.productModel
75
+ .find({
76
+ shopCategory: { $in: data.categories },
72
77
  })
73
78
  .lean();
74
79
  for (const product of categoryWiseProducts) {
75
80
  if (data.categoryValueType !== undefined && data.categoryValueType !== null) {
76
- await this.productMarketingsCreate(result._id, product._id, Number(data.categoryValue), data.categoryValueType);
81
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
82
+ await this.productMarketingsCreate(result._id, product._id, Number(data.categoryValue), data.categoryValueType);
83
+ }
77
84
  }
78
85
  else {
79
86
  (0, error_common_1.badRequestError)('Category discount value & value-type is required');
@@ -81,13 +88,16 @@ let DiscountMarketingService = class DiscountMarketingService {
81
88
  }
82
89
  }
83
90
  else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {
84
- const categoryWiseProducts = await this.productModel.find({
85
- shopCategory: { $in: data.categories }
91
+ const categoryWiseProducts = await this.productModel
92
+ .find({
93
+ shopCategory: { $in: data.categories },
86
94
  })
87
95
  .lean();
88
96
  for (const product of categoryWiseProducts) {
89
97
  if (data.categoryValueType !== undefined && data.categoryValueType !== null) {
90
- await this.productMarketingsCreate(result._id, product._id, Number(data.categoryValue), data.categoryValueType);
98
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
99
+ await this.productMarketingsCreate(result._id, product._id, Number(data.categoryValue), data.categoryValueType);
100
+ }
91
101
  }
92
102
  else {
93
103
  (0, error_common_1.badRequestError)('Category discount value & value-type is required');
@@ -98,7 +108,9 @@ let DiscountMarketingService = class DiscountMarketingService {
98
108
  if (isProductAddedByCategory)
99
109
  continue;
100
110
  if (product.valueType !== undefined && product.valueType !== null) {
101
- await this.productMarketingsCreate(result._id, product.product, Number(product.value), product.valueType);
111
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
112
+ await this.productMarketingsCreate(result._id, product.product, Number(product.value), product.valueType);
113
+ }
102
114
  }
103
115
  else {
104
116
  (0, error_common_1.badRequestError)('Product discount value & value-type is required');
@@ -115,7 +127,9 @@ let DiscountMarketingService = class DiscountMarketingService {
115
127
  .then(productDocuments => {
116
128
  for (const product of productDocuments) {
117
129
  if (data.valueType !== undefined) {
118
- this.productMarketingsCreate(result._id, product._id, Number(data.value), data.valueType);
130
+ if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
131
+ this.productMarketingsCreate(result._id, product._id, Number(data.value), data.valueType);
132
+ }
119
133
  }
120
134
  else {
121
135
  (0, error_common_1.badRequestError)('Discount value & value-type is required for entire menu');
@@ -134,7 +148,9 @@ let DiscountMarketingService = class DiscountMarketingService {
134
148
  new: true,
135
149
  runValidators: true,
136
150
  });
137
- if ((data.products && data.products.length > 0) || (data.categories && data.categories.length > 0) || data.isEntireMenu) {
151
+ if ((data.products && data.products.length > 0) ||
152
+ (data.categories && data.categories.length > 0) ||
153
+ data.isEntireMenu) {
138
154
  await _1.productMarketingService.deleteMany({ marketing: _id }, true);
139
155
  }
140
156
  if (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {
@@ -148,9 +164,12 @@ let DiscountMarketingService = class DiscountMarketingService {
148
164
  }
149
165
  console.log('Step 6.1');
150
166
  }
151
- else if (data.categories && data.categories.length > 0 && (!data.products || data.products.length === 0)) {
152
- const categoryWiseProducts = await this.productModel.find({
153
- shopCategory: { $in: data.categories }
167
+ else if (data.categories &&
168
+ data.categories.length > 0 &&
169
+ (!data.products || data.products.length === 0)) {
170
+ const categoryWiseProducts = await this.productModel
171
+ .find({
172
+ shopCategory: { $in: data.categories },
154
173
  })
155
174
  .lean();
156
175
  for (const product of categoryWiseProducts) {
@@ -163,8 +182,9 @@ let DiscountMarketingService = class DiscountMarketingService {
163
182
  }
164
183
  }
165
184
  else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {
166
- const categoryWiseProducts = await this.productModel.find({
167
- shopCategory: { $in: data.categories }
185
+ const categoryWiseProducts = await this.productModel
186
+ .find({
187
+ shopCategory: { $in: data.categories },
168
188
  })
169
189
  .lean();
170
190
  for (const product of categoryWiseProducts) {
@@ -214,7 +234,7 @@ let DiscountMarketingService = class DiscountMarketingService {
214
234
  marketing: marketingId,
215
235
  product: productId,
216
236
  value: value,
217
- valueType: valueType
237
+ valueType: valueType,
218
238
  });
219
239
  }
220
240
  };
@@ -1 +1 @@
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,IAAI,IAAI,CAAC,QAAQ,IAAI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,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;AAvMY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAuMpC;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\tawait this.productMarketingsCreate(result._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.categories && data.categories.length > 0 && (!data.products || data.products.length === 0)) { // Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel.find({\n\t\t\t\tshopCategory: { $in: data.categories }\n\t\t\t})\n\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(result._id, product._id, Number(data.categoryValue), data.categoryValueType);\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) { // Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel.find({\n\t\t\t\tshopCategory: { $in: data.categories }\n\t\t\t})\n\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(result._id, product._id, Number(data.categoryValue), data.categoryValueType);\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(p => p._id.toString() === product.product.toString());\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(result._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) { // 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(result._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\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((data.products && data.products.length > 0) || (data.categories && data.categories.length > 0) || data.isEntireMenu) {\n\t\t\tawait productMarketingService.deleteMany(\n\t\t\t\t{ marketing: _id },\n\t\t\t\ttrue\n\t\t\t);\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 (data.categories && data.categories.length > 0 && (!data.products || data.products.length === 0)) { // Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel.find({\n\t\t\t\tshopCategory: { $in: data.categories }\n\t\t\t})\n\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(_id, product._id, Number(data.categoryValue), data.categoryValueType);\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) { // Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel.find({\n\t\t\t\tshopCategory: { $in: data.categories }\n\t\t\t})\n\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(_id, product._id, Number(data.categoryValue), data.categoryValueType);\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(p => p._id.toString() === product.product.toString());\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) { // 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,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,EAAE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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 +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;IA2GlB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAe7D,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,I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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"}
@@ -105,6 +105,9 @@ let MarketingService = class MarketingService {
105
105
  });
106
106
  }
107
107
  }
108
+ if (admin) {
109
+ data.admin = admin;
110
+ }
108
111
  let marketing;
109
112
  switch (data.marketingType) {
110
113
  case enum_2.MarketingType.DISCOUNT: {
@@ -134,7 +137,7 @@ let MarketingService = class MarketingService {
134
137
  break;
135
138
  }
136
139
  default: {
137
- marketing = await this.model.create(data);
140
+ marketing = await this.model.create(data, admin);
138
141
  }
139
142
  }
140
143
  if (admin) {
@@ -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;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,aAA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AhB,gBAAgB;IAD5B,IAAA,gBAAO,GAAE;;GACG,gBAAgB,CA+U5B;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\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);\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;Q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,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"]}
@@ -22,6 +22,7 @@ export declare const buy1Get1MarketingTransformer: import("@lyxa.ai/core/dist/ut
22
22
  isBuy1Get1?: boolean | undefined;
23
23
  valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
24
24
  }>, "many">>>>;
25
+ excludeProducts: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>, "many">>>>;
25
26
  spendLimit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
26
27
  isSpendLimitEnabled: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
27
28
  isOnlyForSubscriber: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
@@ -39,6 +40,7 @@ export declare const buy1Get1MarketingTransformer: import("@lyxa.ai/core/dist/ut
39
40
  }>>;
40
41
  status: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNativeEnum<typeof import("@lyxa.ai/core/dist/utilities/enum").MarketingStatus>>>;
41
42
  pausedAt: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Date, string>, import("zod").ZodDate]>, Date, string | Date>, Date, string | Date>>>>>;
43
+ admin: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>>>;
42
44
  _id: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
43
45
  }, import("zod").ZodTypeAny, "passthrough">>;
44
46
  //# sourceMappingURL=buy1-get1-marketing.transformer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"buy1-get1-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/buy1-get1-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,+EAA+E,CAAC;AAM3H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
1
+ {"version":3,"file":"buy1-get1-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/buy1-get1-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,+EAA+E,CAAC;AAM3H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
@@ -26,6 +26,7 @@ export declare const discountMarketingTransformer: import("@lyxa.ai/core/dist/ut
26
26
  isBuy1Get1?: boolean | undefined;
27
27
  valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
28
28
  }>, "many">>>>;
29
+ excludeProducts: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>, "many">>>>;
29
30
  maxDiscountPerOrder: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
30
31
  isMaxDiscountPerOrderEnabled: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
31
32
  spendLimit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
@@ -45,6 +46,7 @@ export declare const discountMarketingTransformer: import("@lyxa.ai/core/dist/ut
45
46
  }>>;
46
47
  status: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNativeEnum<typeof import("@lyxa.ai/core/dist/utilities/enum").MarketingStatus>>>;
47
48
  pausedAt: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Date, string>, import("zod").ZodDate]>, Date, string | Date>, Date, string | Date>>>>>;
49
+ admin: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>>>;
48
50
  _id: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
49
51
  }, import("zod").ZodTypeAny, "passthrough">>;
50
52
  //# sourceMappingURL=discount-marketing.transformer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discount-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/discount-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,8EAA8E,CAAC;AAM1H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
1
+ {"version":3,"file":"discount-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/discount-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,8EAA8E,CAAC;AAM1H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
@@ -16,6 +16,7 @@ export declare const featuredMarketingTransformer: import("@lyxa.ai/core/dist/ut
16
16
  }>>;
17
17
  status: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNativeEnum<typeof import("@lyxa.ai/core/dist/utilities/enum").MarketingStatus>>>;
18
18
  pausedAt: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Date, string>, import("zod").ZodDate]>, Date, string | Date>, Date, string | Date>>>>>;
19
+ admin: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>>>;
19
20
  _id: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
20
21
  }, import("zod").ZodTypeAny, "passthrough">>;
21
22
  //# sourceMappingURL=featured-marketing.transformer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"featured-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/featured-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,8EAA8E,CAAC;AAM1H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
1
+ {"version":3,"file":"featured-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/featured-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,8EAA8E,CAAC;AAM1H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
@@ -17,6 +17,7 @@ export declare const freeDeliveryMarketingTransformer: import("@lyxa.ai/core/dis
17
17
  }>>;
18
18
  status: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNativeEnum<typeof import("@lyxa.ai/core/dist/utilities/enum").MarketingStatus>>>;
19
19
  pausedAt: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Date, string>, import("zod").ZodDate]>, Date, string | Date>, Date, string | Date>>>>>;
20
+ admin: import("zod").ZodOptional<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>>>;
20
21
  _id: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
21
22
  }, import("zod").ZodTypeAny, "passthrough">>;
22
23
  //# sourceMappingURL=free-delivery-marketing.transformer.d.ts.map