@lyxa.ai/marketing 1.0.30 → 1.0.32

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 (163) hide show
  1. package/dist/lib/event/event-initializations.d.ts +2 -0
  2. package/dist/lib/event/event-initializations.d.ts.map +1 -0
  3. package/dist/lib/event/event-initializations.js +8 -0
  4. package/dist/lib/event/event-initializations.js.map +1 -0
  5. package/dist/lib/event/event-listeners/event-listeners.d.ts +2 -0
  6. package/dist/lib/event/event-listeners/event-listeners.d.ts.map +1 -0
  7. package/dist/lib/event/event-listeners/event-listeners.js +12 -0
  8. package/dist/lib/event/event-listeners/event-listeners.js.map +1 -0
  9. package/dist/lib/index.d.ts +86 -58
  10. package/dist/lib/index.d.ts.map +1 -1
  11. package/dist/lib/index.js +17 -17
  12. package/dist/lib/index.js.map +1 -1
  13. package/dist/lib/modules/coupon/routers/coupon.router.d.ts +55 -55
  14. package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
  15. package/dist/lib/modules/coupon/routers/coupon.router.js +9 -6
  16. package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
  17. package/dist/lib/modules/coupon/services/coupon.service.d.ts +2 -1
  18. package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
  19. package/dist/lib/modules/coupon/services/coupon.service.js +90 -49
  20. package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
  21. package/dist/lib/modules/coupon/services/helper.service.d.ts +1 -0
  22. package/dist/lib/modules/coupon/services/helper.service.d.ts.map +1 -1
  23. package/dist/lib/modules/coupon/services/helper.service.js +21 -2
  24. package/dist/lib/modules/coupon/services/helper.service.js.map +1 -1
  25. package/dist/lib/modules/coupon/services/individual-store-coupon.service.js +1 -1
  26. package/dist/lib/modules/coupon/services/individual-store-coupon.service.js.map +1 -1
  27. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts +1 -0
  28. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
  29. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +134 -12
  30. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
  31. package/dist/lib/modules/coupon/services/referral-code-coupon.service.d.ts +1 -1
  32. package/dist/lib/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
  33. package/dist/lib/modules/coupon/services/referral-code-coupon.service.js +9 -3
  34. package/dist/lib/modules/coupon/services/referral-code-coupon.service.js.map +1 -1
  35. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
  36. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js +10 -2
  37. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
  38. package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js +1 -1
  39. package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js.map +1 -1
  40. package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts +153 -153
  41. package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +12 -12
  42. package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
  43. package/dist/lib/modules/coupon/validations/coupon.validation.js +2 -1
  44. package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
  45. package/dist/lib/modules/coupon/validations/custom-coupon.validation.d.ts +8 -8
  46. package/dist/lib/modules/coupon/validations/global-coupon.validation.d.ts +8 -8
  47. package/dist/lib/modules/coupon/validations/individual-store-coupon.validation.d.ts +10 -10
  48. package/dist/lib/modules/coupon/validations/individual-user-coupon.validation.d.ts +8 -8
  49. package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.d.ts +9 -9
  50. package/dist/lib/modules/coupon/validations/shops-categories-coupon.validation.d.ts +8 -8
  51. package/dist/lib/modules/deal-setting/validations/deal-setting.validation.d.ts +1 -1
  52. package/dist/lib/modules/marketing/routers/marketing.router.d.ts +28 -0
  53. package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  54. package/dist/lib/modules/marketing/routers/marketing.router.js +19 -0
  55. package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
  56. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.d.ts +2 -1
  57. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
  58. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js +45 -110
  59. package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js.map +1 -1
  60. package/dist/lib/modules/marketing/services/discount-marketing.service.d.ts +2 -1
  61. package/dist/lib/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
  62. package/dist/lib/modules/marketing/services/discount-marketing.service.js +54 -171
  63. package/dist/lib/modules/marketing/services/discount-marketing.service.js.map +1 -1
  64. package/dist/lib/modules/marketing/services/featured-marketing.service.d.ts +2 -0
  65. package/dist/lib/modules/marketing/services/featured-marketing.service.d.ts.map +1 -1
  66. package/dist/lib/modules/marketing/services/featured-marketing.service.js +30 -2
  67. package/dist/lib/modules/marketing/services/featured-marketing.service.js.map +1 -1
  68. package/dist/lib/modules/marketing/services/free-delivery-marketing.service.d.ts.map +1 -1
  69. package/dist/lib/modules/marketing/services/free-delivery-marketing.service.js +6 -1
  70. package/dist/lib/modules/marketing/services/free-delivery-marketing.service.js.map +1 -1
  71. package/dist/lib/modules/marketing/services/index.d.ts +1 -0
  72. package/dist/lib/modules/marketing/services/index.d.ts.map +1 -1
  73. package/dist/lib/modules/marketing/services/index.js +1 -0
  74. package/dist/lib/modules/marketing/services/index.js.map +1 -1
  75. package/dist/lib/modules/marketing/services/marketing.service.d.ts +5 -0
  76. package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
  77. package/dist/lib/modules/marketing/services/marketing.service.js +210 -5
  78. package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
  79. package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +2 -0
  80. package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
  81. package/dist/lib/modules/marketing/services/product-marketing.service.js +27 -3
  82. package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
  83. package/dist/lib/modules/marketing/services/punch-marketing.service.d.ts.map +1 -1
  84. package/dist/lib/modules/marketing/services/punch-marketing.service.js +6 -1
  85. package/dist/lib/modules/marketing/services/punch-marketing.service.js.map +1 -1
  86. package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts +15 -0
  87. package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -0
  88. package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js +250 -0
  89. package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js.map +1 -0
  90. package/dist/lib/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +2 -2
  91. package/dist/lib/modules/marketing/transformers/discount-marketing.transformer.d.ts +2 -2
  92. package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +55 -55
  93. package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts +65 -65
  94. package/dist/lib/modules/marketing/validations/featured-marketing.validation.d.ts +21 -21
  95. package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.d.ts +18 -18
  96. package/dist/lib/modules/marketing/validations/marketing.validation.d.ts +21 -7
  97. package/dist/lib/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
  98. package/dist/lib/modules/marketing/validations/marketing.validation.js +7 -1
  99. package/dist/lib/modules/marketing/validations/marketing.validation.js.map +1 -1
  100. package/dist/lib/modules/marketing/validations/product-marketing.validation.d.ts +4 -4
  101. package/dist/lib/modules/marketing/validations/punch-marketing.validation.d.ts +22 -22
  102. package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +3 -3
  103. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js +2 -2
  104. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js.map +1 -1
  105. package/dist/lib/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +6 -6
  106. package/dist/types/event/event-initializations.d.ts +2 -0
  107. package/dist/types/event/event-initializations.d.ts.map +1 -0
  108. package/dist/types/event/event-listeners/event-listeners.d.ts +2 -0
  109. package/dist/types/event/event-listeners/event-listeners.d.ts.map +1 -0
  110. package/dist/types/index.d.ts +86 -58
  111. package/dist/types/index.d.ts.map +1 -1
  112. package/dist/types/modules/coupon/routers/coupon.router.d.ts +55 -55
  113. package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
  114. package/dist/types/modules/coupon/services/coupon.service.d.ts +2 -1
  115. package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
  116. package/dist/types/modules/coupon/services/helper.service.d.ts +1 -0
  117. package/dist/types/modules/coupon/services/helper.service.d.ts.map +1 -1
  118. package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts +1 -0
  119. package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
  120. package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts +1 -1
  121. package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
  122. package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
  123. package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts +153 -153
  124. package/dist/types/modules/coupon/validations/coupon.validation.d.ts +12 -12
  125. package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
  126. package/dist/types/modules/coupon/validations/custom-coupon.validation.d.ts +8 -8
  127. package/dist/types/modules/coupon/validations/global-coupon.validation.d.ts +8 -8
  128. package/dist/types/modules/coupon/validations/individual-store-coupon.validation.d.ts +10 -10
  129. package/dist/types/modules/coupon/validations/individual-user-coupon.validation.d.ts +8 -8
  130. package/dist/types/modules/coupon/validations/referral-reward-coupon.validation.d.ts +9 -9
  131. package/dist/types/modules/coupon/validations/shops-categories-coupon.validation.d.ts +8 -8
  132. package/dist/types/modules/deal-setting/validations/deal-setting.validation.d.ts +1 -1
  133. package/dist/types/modules/marketing/routers/marketing.router.d.ts +28 -0
  134. package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  135. package/dist/types/modules/marketing/services/buy1-get1-marketing.service.d.ts +2 -1
  136. package/dist/types/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
  137. package/dist/types/modules/marketing/services/discount-marketing.service.d.ts +2 -1
  138. package/dist/types/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
  139. package/dist/types/modules/marketing/services/featured-marketing.service.d.ts +2 -0
  140. package/dist/types/modules/marketing/services/featured-marketing.service.d.ts.map +1 -1
  141. package/dist/types/modules/marketing/services/free-delivery-marketing.service.d.ts.map +1 -1
  142. package/dist/types/modules/marketing/services/index.d.ts +1 -0
  143. package/dist/types/modules/marketing/services/index.d.ts.map +1 -1
  144. package/dist/types/modules/marketing/services/marketing.service.d.ts +5 -0
  145. package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
  146. package/dist/types/modules/marketing/services/product-marketing.service.d.ts +2 -0
  147. package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
  148. package/dist/types/modules/marketing/services/punch-marketing.service.d.ts.map +1 -1
  149. package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts +15 -0
  150. package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -0
  151. package/dist/types/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +2 -2
  152. package/dist/types/modules/marketing/transformers/discount-marketing.transformer.d.ts +2 -2
  153. package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +55 -55
  154. package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts +65 -65
  155. package/dist/types/modules/marketing/validations/featured-marketing.validation.d.ts +21 -21
  156. package/dist/types/modules/marketing/validations/free-delivery-marketing.validation.d.ts +18 -18
  157. package/dist/types/modules/marketing/validations/marketing.validation.d.ts +21 -7
  158. package/dist/types/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
  159. package/dist/types/modules/marketing/validations/product-marketing.validation.d.ts +4 -4
  160. package/dist/types/modules/marketing/validations/punch-marketing.validation.d.ts +22 -22
  161. package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +3 -3
  162. package/dist/types/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +6 -6
  163. package/package.json +2 -2
@@ -44,6 +44,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.buy1Get1MarketingService = exports.Buy1Get1MarketingService = void 0;
46
46
  const typedi_1 = __importStar(require("typedi"));
47
+ const typegoose_1 = require("@typegoose/typegoose");
47
48
  const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models/");
48
49
  const _1 = require("./");
49
50
  const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
@@ -56,141 +57,75 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
56
57
  }
57
58
  async create(data) {
58
59
  const result = await this.model.create(data);
59
- if (data.products &&
60
- data.products.length > 0 &&
61
- (!data.categories || data.categories.length === 0) &&
62
- !data.isEntireMenu) {
63
- for (const product of data.products) {
64
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
65
- this.productMarketingsCreate(result._id, product.product);
66
- }
67
- }
68
- }
69
- else if (data.categories &&
70
- data.categories.length > 0 &&
71
- (!data.products || data.products.length === 0) &&
72
- !data.isEntireMenu) {
73
- const categoryWiseProducts = await this.productModel
74
- .find({
75
- shopCategory: { $in: data.categories },
76
- })
77
- .lean();
78
- for (const product of categoryWiseProducts) {
79
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
80
- this.productMarketingsCreate(result._id, product._id);
81
- }
82
- }
83
- }
84
- else if (data.categories &&
85
- data.categories.length > 0 &&
86
- data.products &&
87
- data.products.length > 0 &&
88
- !data.isEntireMenu) {
89
- const categoryWiseProducts = await this.productModel
90
- .find({
91
- shopCategory: { $in: data.categories },
92
- })
93
- .lean();
94
- for (const product of categoryWiseProducts) {
95
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
96
- this.productMarketingsCreate(result._id, product._id);
97
- }
98
- }
99
- for (const product of data.products) {
100
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
101
- this.productMarketingsCreate(result._id, product.product);
102
- }
103
- }
104
- }
105
- else if (data.isEntireMenu) {
106
- this.productModel
107
- .find({ shop: data.shop })
108
- .select('_id')
109
- .exec()
110
- .then(productDocuments => {
111
- for (const product of productDocuments) {
112
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
113
- this.productMarketingsCreate(result._id, product._id);
114
- }
115
- }
116
- });
60
+ if (!result) {
61
+ (0, error_common_1.internalServerError)('Unable to create marketing');
117
62
  }
63
+ await this.createProductMarketings(result.shop._id, result._id, data.products.map(p => p.product) ?? [], data.categories ?? [], data.isEntireMenu ?? false);
118
64
  return result;
119
65
  }
120
66
  async update(_id, data) {
121
67
  const { products, ...rest } = data;
122
- const record = await this.model.findOneAndUpdate({
68
+ const record = await this.model
69
+ .findOneAndUpdate({
123
70
  _id: _id,
124
71
  deletedAt: null,
125
72
  }, rest, {
126
73
  new: true,
127
74
  runValidators: true,
75
+ })
76
+ .populate({
77
+ path: 'shop',
78
+ select: '_id name shopId',
128
79
  });
80
+ if (!record) {
81
+ (0, error_common_1.notFoundError)('Marketing not found');
82
+ }
129
83
  if ((data.products && data.products.length > 0) ||
130
84
  (data.categories && data.categories.length > 0) ||
131
85
  data.isEntireMenu) {
132
86
  await _1.productMarketingService.deleteMany({ marketing: _id }, true);
133
87
  }
134
- if (data.products &&
135
- data.products.length > 0 &&
136
- (!data.categories || data.categories.length === 0) &&
137
- !data.isEntireMenu) {
138
- for (const product of data.products) {
139
- this.productMarketingsCreate(_id, product.product);
140
- }
141
- }
142
- else if (data.categories &&
143
- data.categories.length > 0 &&
144
- (!data.products || data.products.length === 0) &&
145
- !data.isEntireMenu) {
146
- const categoryWiseProducts = await this.productModel
147
- .find({
148
- shopCategory: { $in: data.categories },
149
- })
150
- .lean();
151
- for (const product of categoryWiseProducts) {
152
- this.productMarketingsCreate(_id, product._id);
153
- }
154
- }
155
- else if (data.categories &&
156
- data.categories.length > 0 &&
157
- data.products &&
158
- data.products.length > 0 &&
159
- !data.isEntireMenu) {
160
- const categoryWiseProducts = await this.productModel
161
- .find({
162
- shopCategory: { $in: data.categories },
163
- })
164
- .lean();
165
- for (const product of categoryWiseProducts) {
166
- this.productMarketingsCreate(_id, product._id);
167
- }
168
- for (const product of data.products) {
169
- this.productMarketingsCreate(_id, product.product);
170
- }
171
- }
172
- else if (data.isEntireMenu) {
173
- this.productModel
174
- .find({ shop: data.shop })
175
- .select('_id')
176
- .exec()
177
- .then(productDocuments => {
178
- for (const product of productDocuments) {
179
- this.productMarketingsCreate(_id, product._id);
180
- }
181
- });
182
- }
88
+ await this.createProductMarketings(record.shop._id, _id, data.products?.map((p) => p.product) ?? [], data.categories ?? [], data.isEntireMenu ?? false);
183
89
  if (!record)
184
90
  (0, error_common_1.notFoundError)('Record not found');
185
91
  return record;
186
92
  }
187
- async productMarketingsCreate(marketingId, productId) {
188
- _1.productMarketingService.create({
93
+ async createSingleProductMarketing(marketingId, productId) {
94
+ await _1.productMarketingService.create({
189
95
  marketing: marketingId,
190
96
  product: productId,
191
97
  isBuy1Get1: true,
192
98
  });
193
99
  }
100
+ async createProductMarketings(shop, marketingId, products, categories, isEntireMenu) {
101
+ if (isEntireMenu) {
102
+ await this.productModel
103
+ .find({ shop })
104
+ .select('_id')
105
+ .exec()
106
+ .then(async (productDocuments) => {
107
+ for (const product of productDocuments) {
108
+ await this.createSingleProductMarketing(marketingId, product._id);
109
+ }
110
+ });
111
+ }
112
+ else {
113
+ const productsToProcess = new Set(products.map(p => p._id.toString()));
114
+ const categoryWiseProducts = await this.productModel
115
+ .find({
116
+ shopCategory: { $in: categories },
117
+ })
118
+ .lean();
119
+ if (categoryWiseProducts) {
120
+ categoryWiseProducts.forEach(p => {
121
+ productsToProcess.add(p._id.toString());
122
+ });
123
+ }
124
+ for (const product of productsToProcess) {
125
+ await this.createSingleProductMarketing(marketingId, new typegoose_1.mongoose.Types.ObjectId(product));
126
+ }
127
+ }
128
+ }
194
129
  };
195
130
  exports.Buy1Get1MarketingService = Buy1Get1MarketingService;
196
131
  exports.Buy1Get1MarketingService = Buy1Get1MarketingService = __decorate([
@@ -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,IACC,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YACxB,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;YAClD,CAAC,IAAI,CAAC,YAAY,EACjB,CAAC;YACF,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrC,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CA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ACN,IAAI,CAAC,gBAAgB,CAAC,EAAE;gBACxB,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;oBACxC,IAAI,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;AApMY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAoMpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tBuy1Get1MarketingModel,\n\tBuy1Get1Marketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateBuy1Get1MarketingDTO as CreateDTO,\n\tUpdateBuy1Get1MarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class Buy1Get1MarketingService {\n\tprivate model: typeof Buy1Get1MarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = Buy1Get1MarketingModel;\n\t\tthis.productModel = ProductModel;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\n\t\t// Only products\n\t\tif (\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t(!data.categories || data.categories.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update record\n\t * @param _id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { products, ...rest } = data;\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: _id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\trest,\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\t// Only products\n\t\tif (\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t(!data.categories || data.categories.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\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\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async productMarketingsCreate(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tproductMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tisBuy1Get1: true,\n\t\t});\n\t}\n}\n\nexport const buy1Get1MarketingService = Container.get(Buy1Get1MarketingService);\n"]}
1
+ {"version":3,"file":"buy1-get1-marketing.service.js","sourceRoot":"/","sources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{ 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 { internalServerError, 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\tif (!result) {\n\t\t\tinternalServerError('Unable to create marketing');\n\t\t}\n\n\t\tawait this.createProductMarketings(\n\t\t\tresult.shop._id,\n\t\t\tresult._id,\n\t\t\tdata.products.map(p => p.product) ?? [],\n\t\t\tdata.categories ?? [],\n\t\t\tdata.isEntireMenu ?? false\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\n\t\t\t.findOneAndUpdate(\n\t\t\t\t{\n\t\t\t\t\t_id: _id,\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t},\n\t\t\t\trest,\n\t\t\t\t{\n\t\t\t\t\tnew: true,\n\t\t\t\t\trunValidators: true,\n\t\t\t\t}\n\t\t\t)\n\t\t\t.populate({\n\t\t\t\tpath: 'shop',\n\t\t\t\tselect: '_id name shopId',\n\t\t\t});\n\t\t\n\t\tif (!record) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\t\t\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\tawait this.createProductMarketings(\n\t\t\trecord.shop._id,\n\t\t\t_id,\n\t\t\tdata.products?.map((p: any) => p.product) ?? [],\n\t\t\tdata.categories ?? [],\n\t\t\tdata.isEntireMenu ?? false\n\t\t);\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tprivate async createSingleProductMarketing(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tawait productMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tisBuy1Get1: true,\n\t\t});\n\t}\n\n\tprivate async createProductMarketings(\n\t\tshop: mongoose.Types.ObjectId,\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproducts: mongoose.Types.ObjectId[],\n\t\tcategories: mongoose.Types.ObjectId[],\n\t\tisEntireMenu: boolean\n\t): Promise<void> {\n\t\tif (isEntireMenu) {\n\t\t\tawait this.productModel\n\t\t\t\t.find({ shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(async productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tawait this.createSingleProductMarketing(marketingId, product._id);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t} else {\n\t\t\tconst productsToProcess = new Set(products.map(p => p._id.toString()));\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tif (categoryWiseProducts) {\n\t\t\t\tcategoryWiseProducts.forEach(p => {\n\t\t\t\t\tproductsToProcess.add(p._id.toString());\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tfor (const product of productsToProcess) {\n\t\t\t\tawait this.createSingleProductMarketing(marketingId, new mongoose.Types.ObjectId(product));\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const buy1Get1MarketingService = Container.get(Buy1Get1MarketingService);\n"]}
@@ -8,7 +8,8 @@ export declare class DiscountMarketingService {
8
8
  constructor();
9
9
  create(data: CreateDTO): Promise<DocumentType<Model>>;
10
10
  update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>>;
11
- productMarketingsCreate(marketingId: mongoose.Types.ObjectId, productId: mongoose.Types.ObjectId, value: number, valueType: ValueType): Promise<void>;
11
+ createSingleProductMarketing(marketingId: mongoose.Types.ObjectId, productId: mongoose.Types.ObjectId, value: number, valueType: ValueType): Promise<void>;
12
+ private createProductMarketings;
12
13
  }
13
14
  export declare const discountMarketingService: DiscountMarketingService;
14
15
  //# sourceMappingURL=discount-marketing.service.d.ts.map
@@ -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;IAmIrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAiInF,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;AAO9D,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;IAuBrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAiDnF,4BAA4B,CACxC,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;YASF,uBAAuB;CAkErC;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
@@ -44,6 +44,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.discountMarketingService = exports.DiscountMarketingService = void 0;
46
46
  const typedi_1 = __importStar(require("typedi"));
47
+ const typegoose_1 = require("@typegoose/typegoose");
47
48
  const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models");
48
49
  const _1 = require("./");
49
50
  const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
@@ -56,196 +57,37 @@ let DiscountMarketingService = class DiscountMarketingService {
56
57
  }
57
58
  async create(data) {
58
59
  const result = await this.model.create(data);
59
- if (data.products &&
60
- data.products.length > 0 &&
61
- (!data.categories || data.categories.length === 0) &&
62
- !data.isEntireMenu) {
63
- for (const product of data.products) {
64
- if (product.valueType !== undefined && product.valueType !== null) {
65
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
66
- await this.productMarketingsCreate(result._id, product.product, Number(product.value), product.valueType);
67
- }
68
- }
69
- else {
70
- (0, error_common_1.badRequestError)('Product discount value & value-type is required');
71
- }
72
- }
73
- }
74
- else if (data.categories &&
75
- data.categories.length > 0 &&
76
- (!data.products || data.products.length === 0) &&
77
- !data.isEntireMenu) {
78
- const categoryWiseProducts = await this.productModel
79
- .find({
80
- shopCategory: { $in: data.categories },
81
- })
82
- .lean();
83
- for (const product of categoryWiseProducts) {
84
- if (data.categoryValueType !== undefined && data.categoryValueType !== null) {
85
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
86
- await this.productMarketingsCreate(result._id, product._id, Number(data.categoryValue), data.categoryValueType);
87
- }
88
- }
89
- else {
90
- (0, error_common_1.badRequestError)('Category discount value & value-type is required');
91
- }
92
- }
93
- }
94
- else if (data.categories &&
95
- data.categories.length > 0 &&
96
- data.products &&
97
- data.products.length > 0 &&
98
- !data.isEntireMenu) {
99
- const categoryWiseProducts = await this.productModel
100
- .find({
101
- shopCategory: { $in: data.categories },
102
- })
103
- .lean();
104
- for (const product of categoryWiseProducts) {
105
- if (data.categoryValueType !== undefined && data.categoryValueType !== null) {
106
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
107
- await this.productMarketingsCreate(result._id, product._id, Number(data.categoryValue), data.categoryValueType);
108
- }
109
- }
110
- else {
111
- (0, error_common_1.badRequestError)('Category discount value & value-type is required');
112
- }
113
- }
114
- for (const product of data.products) {
115
- const isProductAddedByCategory = categoryWiseProducts.find(p => p._id.toString() === product.product.toString());
116
- if (isProductAddedByCategory)
117
- continue;
118
- if (product.valueType !== undefined && product.valueType !== null) {
119
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
120
- await this.productMarketingsCreate(result._id, product.product, Number(product.value), product.valueType);
121
- }
122
- }
123
- else {
124
- (0, error_common_1.badRequestError)('Product discount value & value-type is required');
125
- }
126
- }
127
- }
128
- else if (data.isEntireMenu) {
129
- this.productModel
130
- .find({
131
- shop: data.shop,
132
- })
133
- .select('_id')
134
- .exec()
135
- .then(productDocuments => {
136
- for (const product of productDocuments) {
137
- if (data.valueType !== undefined) {
138
- if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
139
- this.productMarketingsCreate(result._id, product._id, Number(data.value), data.valueType);
140
- }
141
- }
142
- else {
143
- (0, error_common_1.badRequestError)('Discount value & value-type is required for entire menu');
144
- }
145
- }
146
- });
147
- }
60
+ await this.createProductMarketings(data.shop, result._id, data.products, data.categories, data.isEntireMenu, data.categoryValue, data.categoryValueType, data.value, data.valueType);
148
61
  return result;
149
62
  }
150
63
  async update(_id, data) {
151
64
  const { categories, products, ...rest } = data;
152
- const record = await this.model.findOneAndUpdate({
65
+ const record = await this.model
66
+ .findOneAndUpdate({
153
67
  _id: _id,
154
68
  deletedAt: null,
155
69
  }, { categories, ...rest }, {
156
70
  new: true,
157
71
  runValidators: true,
72
+ })
73
+ .populate({
74
+ path: 'shop',
75
+ select: '_id name shopId',
158
76
  });
77
+ if (!record) {
78
+ (0, error_common_1.internalServerError)('Could not update marketing');
79
+ }
159
80
  if ((data.products && data.products.length > 0) ||
160
81
  (data.categories && data.categories.length > 0) ||
161
82
  data.isEntireMenu) {
162
83
  await _1.productMarketingService.deleteMany({ marketing: _id }, true);
163
84
  }
164
- if (data.products &&
165
- data.products.length > 0 &&
166
- (!data.categories || data.categories.length === 0) &&
167
- !data.isEntireMenu) {
168
- for (const product of data.products) {
169
- if (product.valueType !== undefined && product.valueType !== null) {
170
- await this.productMarketingsCreate(_id, product.product, Number(product.value), product.valueType);
171
- }
172
- else {
173
- (0, error_common_1.badRequestError)('Product discount value & value-type is required');
174
- }
175
- }
176
- console.log('Step 6.1');
177
- }
178
- else if (data.categories &&
179
- data.categories.length > 0 &&
180
- (!data.products || data.products.length === 0) &&
181
- !data.isEntireMenu) {
182
- const categoryWiseProducts = await this.productModel
183
- .find({
184
- shopCategory: { $in: data.categories },
185
- })
186
- .lean();
187
- for (const product of categoryWiseProducts) {
188
- if (data.categoryValueType !== undefined && data.categoryValueType !== null) {
189
- await this.productMarketingsCreate(_id, product._id, Number(data.categoryValue), data.categoryValueType);
190
- }
191
- else {
192
- (0, error_common_1.badRequestError)('Category discount value & value-type is required');
193
- }
194
- }
195
- }
196
- else if (data.categories &&
197
- data.categories.length > 0 &&
198
- data.products &&
199
- data.products.length > 0 &&
200
- !data.isEntireMenu) {
201
- const categoryWiseProducts = await this.productModel
202
- .find({
203
- shopCategory: { $in: data.categories },
204
- })
205
- .lean();
206
- for (const product of categoryWiseProducts) {
207
- if (data.categoryValueType !== undefined && data.categoryValueType !== null) {
208
- await this.productMarketingsCreate(_id, product._id, Number(data.categoryValue), data.categoryValueType);
209
- }
210
- else {
211
- (0, error_common_1.badRequestError)('Category discount value & value-type is required');
212
- }
213
- }
214
- for (const product of data.products) {
215
- const isProductAddedByCategory = categoryWiseProducts.find(p => p._id.toString() === product.product.toString());
216
- if (isProductAddedByCategory)
217
- continue;
218
- if (product.valueType !== undefined && product.valueType !== null) {
219
- await this.productMarketingsCreate(_id, product.product, Number(product.value), product.valueType);
220
- }
221
- else {
222
- (0, error_common_1.badRequestError)('Product discount value & value-type is required');
223
- }
224
- }
225
- }
226
- else if (data.isEntireMenu) {
227
- this.productModel
228
- .find({
229
- shop: data.shop,
230
- })
231
- .select('_id')
232
- .exec()
233
- .then(productDocuments => {
234
- for (const product of productDocuments) {
235
- if (data.valueType !== undefined) {
236
- this.productMarketingsCreate(_id, product._id, Number(data.value), data.valueType);
237
- }
238
- else {
239
- (0, error_common_1.badRequestError)('Discount value & value-type is required for entire menu');
240
- }
241
- }
242
- });
243
- }
85
+ await this.createProductMarketings(record.shop._id, record._id, data.products, data.categories, data.isEntireMenu, data.categoryValue, data.categoryValueType, data.value, data.valueType);
244
86
  if (!record)
245
87
  (0, error_common_1.notFoundError)('Record not found');
246
88
  return record;
247
89
  }
248
- async productMarketingsCreate(marketingId, productId, value, valueType) {
90
+ async createSingleProductMarketing(marketingId, productId, value, valueType) {
249
91
  _1.productMarketingService.create({
250
92
  marketing: marketingId,
251
93
  product: productId,
@@ -253,6 +95,47 @@ let DiscountMarketingService = class DiscountMarketingService {
253
95
  valueType: valueType,
254
96
  });
255
97
  }
98
+ async createProductMarketings(shop, marketingId, products, categories, isEntireMenu, categoryValue, categoryValueType, value, valueType) {
99
+ if (isEntireMenu) {
100
+ await this.productModel
101
+ .find({ shop })
102
+ .select('_id')
103
+ .exec()
104
+ .then(async (productDocuments) => {
105
+ for (const product of productDocuments) {
106
+ await this.createSingleProductMarketing(marketingId, product._id, value, valueType);
107
+ }
108
+ });
109
+ }
110
+ else {
111
+ const productsMap = (products || []).reduce((acc, p) => {
112
+ const idStr = p.product.toString();
113
+ if (p.value !== undefined && p.valueType !== undefined) {
114
+ acc[idStr] = {
115
+ value: Number(p.value),
116
+ valueType: p.valueType,
117
+ };
118
+ }
119
+ return acc;
120
+ }, {});
121
+ const categoryWiseProducts = (await this.productModel
122
+ .find({
123
+ shopCategory: { $in: categories },
124
+ })
125
+ .lean()).map(p => p._id.toString());
126
+ for (const id of categoryWiseProducts) {
127
+ if (!productsMap[id] && categoryValue !== undefined && categoryValueType !== undefined) {
128
+ productsMap[id] = {
129
+ value: Number(categoryValue),
130
+ valueType: categoryValueType,
131
+ };
132
+ }
133
+ }
134
+ for (const [productId, info] of Object.entries(productsMap)) {
135
+ await this.createSingleProductMarketing(marketingId, new typegoose_1.mongoose.Types.ObjectId(productId), info.value, info.valueType);
136
+ }
137
+ }
138
+ }
256
139
  };
257
140
  exports.DiscountMarketingService = DiscountMarketingService;
258
141
  exports.DiscountMarketingService = DiscountMarketingService = __decorate([
@@ -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,IACC,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YACxB,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;YAClD,CAAC,IAAI,CAAC,YAAY,EACjB,CAAC;YACF,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrC,IAAI,OAAO,CAAC,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QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tDiscountMarketingModel,\n\tDiscountMarketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tCreateDiscountMarketingDTO as CreateDTO,\n\tUpdateDiscountMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { badRequestError, notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class DiscountMarketingService {\n\tprivate model: typeof DiscountMarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = DiscountMarketingModel;\n\t\tthis.productModel = ProductModel;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\n\t\t// Only products\n\t\tif (\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t(!data.categories || data.categories.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct.product,\n\t\t\t\t\t\t\tNumber(product.value),\n\t\t\t\t\t\t\tproduct.valueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\t// Ignore the product which is already added by category\n\t\t\t\tconst isProductAddedByCategory = categoryWiseProducts.find(\n\t\t\t\t\tp => p._id.toString() === product.product.toString()\n\t\t\t\t);\n\t\t\t\tif (isProductAddedByCategory) continue;\n\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t\tresult._id,\n\t\t\t\t\t\t\tproduct.product,\n\t\t\t\t\t\t\tNumber(product.value),\n\t\t\t\t\t\t\tproduct.valueType\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshop: data.shop,\n\t\t\t\t})\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (data.valueType !== undefined) {\n\t\t\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id, Number(data.value), data.valueType);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tbadRequestError('Discount value & value-type is required for entire menu');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update record\n\t * @param _id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { categories, products, ...rest } = data;\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: _id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\t{ categories, ...rest },\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\t// Only products\n\t\tif (\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t(!data.categories || data.categories.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\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\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\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 (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (data.categoryValueType !== undefined && data.categoryValueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(\n\t\t\t\t\t\t_id,\n\t\t\t\t\t\tproduct._id,\n\t\t\t\t\t\tNumber(data.categoryValue),\n\t\t\t\t\t\tdata.categoryValueType\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Category discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\t// Ignore the product which is already added by category\n\t\t\t\tconst isProductAddedByCategory = categoryWiseProducts.find(\n\t\t\t\t\tp => p._id.toString() === product.product.toString()\n\t\t\t\t);\n\t\t\t\tif (isProductAddedByCategory) continue;\n\n\t\t\t\tif (product.valueType !== undefined && product.valueType !== null) {\n\t\t\t\t\tawait this.productMarketingsCreate(_id, product.product, Number(product.value), product.valueType);\n\t\t\t\t} else {\n\t\t\t\t\tbadRequestError('Product discount value & value-type is required');\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshop: data.shop,\n\t\t\t\t})\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (data.valueType !== undefined) {\n\t\t\t\t\t\t\tthis.productMarketingsCreate(_id, product._id, Number(data.value), data.valueType);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tbadRequestError('Discount value & value-type is required for entire menu');\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async productMarketingsCreate(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId,\n\t\tvalue: number,\n\t\tvalueType: ValueType\n\t): Promise<void> {\n\t\tproductMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tvalue: value,\n\t\t\tvalueType: valueType,\n\t\t});\n\t}\n}\n\nexport const discountMarketingService = Container.get(DiscountMarketingService);\n"]}
1
+ {"version":3,"file":"discount-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,oDAA8D;AAC9D,sEAImD;AAKnD,yBAA6C;AAE7C,4EAImD;AAG5C,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;QAE7C,MAAM,IAAI,CAAC,uBAAuB,CACjC,IAAI,CAAC,IAAI,EACT,MAAM,CAAC,GAAG,EACV,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,YAAY,EACjB,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,KAA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C;wBAC/B,SAAS,EAAG,CAAS,CAAC,SAAS;qBAC/B,CAAC;gBACH,CAAC;gBACD,OAAO,GAAG,CAAC;YACZ,CAAC,EACD,EAA6D,CAC7D,CAAC;YAEF,MAAM,oBAAoB,GAAG,CAC5B,MAAM,IAAI,CAAC,YAAY;iBACrB,IAAI,CAAC;gBACL,YAAY,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE;aACjC,CAAC;iBACD,IAAI,EAAE,CACR,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAG7B,KAAK,MAAM,EAAE,IAAI,oBAAoB,EAAE,CAAC;gBACvC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,aAAa,KAAK,SAAS,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;oBACxF,WAAW,CAAC,EAAE,CAAC,GAAG;wBACjB,KAAK,EAAE,MAAM,CAAC,aAAa,CAAC;wBAC5B,SAAS,EAAE,iBAAiB;qBAC5B,CAAC;gBACH,CAAC;YACF,CAAC;YAGD,KAAK,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC7D,MAAM,IAAI,CAAC,4BAA4B,CACtC,WAAW,EACX,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EACtC,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,SAAS,CACd,CAAC;YACH,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAA;AArKY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAqKpC;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 {\n\tbadRequestError,\n\tinternalServerError,\n\tnotFoundError,\n} 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\tawait this.createProductMarketings(\n\t\t\tdata.shop,\n\t\t\tresult._id,\n\t\t\tdata.products,\n\t\t\tdata.categories,\n\t\t\tdata.isEntireMenu,\n\t\t\tdata.categoryValue,\n\t\t\tdata.categoryValueType,\n\t\t\tdata.value,\n\t\t\tdata.valueType\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\n\t\t\t.findOneAndUpdate(\n\t\t\t\t{\n\t\t\t\t\t_id: _id,\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t},\n\t\t\t\t{ categories, ...rest },\n\t\t\t\t{\n\t\t\t\t\tnew: true,\n\t\t\t\t\trunValidators: true,\n\t\t\t\t}\n\t\t\t)\n\t\t\t.populate({\n\t\t\t\tpath: 'shop',\n\t\t\t\tselect: '_id name shopId',\n\t\t\t});\n\n\t\tif (!record) {\n\t\t\tinternalServerError('Could not update marketing');\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\tawait this.createProductMarketings(\n\t\t\trecord.shop._id,\n\t\t\trecord._id,\n\t\t\tdata.products,\n\t\t\tdata.categories,\n\t\t\tdata.isEntireMenu,\n\t\t\tdata.categoryValue,\n\t\t\tdata.categoryValueType,\n\t\t\tdata.value,\n\t\t\tdata.valueType\n\t\t);\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async createSingleProductMarketing(\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\tprivate async createProductMarketings(\n\t\tshop: mongoose.Types.ObjectId,\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproducts: { product: mongoose.Types.ObjectId; value?: number; valueType?: ValueType | null }[],\n\t\tcategories: mongoose.Types.ObjectId[],\n\t\tisEntireMenu: boolean,\n\t\tcategoryValue?: number,\n\t\tcategoryValueType?: ValueType,\n\t\tvalue?: number,\n\t\tvalueType?: ValueType\n\t): Promise<void> {\n\t\tif (isEntireMenu) {\n\t\t\tawait this.productModel\n\t\t\t\t.find({ shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(async productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tawait this.createSingleProductMarketing(marketingId, product._id, value!, valueType!);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t} else {\n\t\t\tconst productsMap = (products || []).reduce(\n\t\t\t\t(acc, p) => {\n\t\t\t\t\tconst idStr = p.product.toString();\n\n\t\t\t\t\tif ((p as any).value !== undefined && (p as any).valueType !== undefined) {\n\t\t\t\t\t\tacc[idStr] = {\n\t\t\t\t\t\t\tvalue: Number((p as any).value),\n\t\t\t\t\t\t\tvalueType: (p as any).valueType,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn acc;\n\t\t\t\t},\n\t\t\t\t{} as Record<string, { value: number; valueType: ValueType }>\n\t\t\t);\n\n\t\t\tconst categoryWiseProducts = (\n\t\t\t\tawait this.productModel\n\t\t\t\t\t.find({\n\t\t\t\t\t\tshopCategory: { $in: categories },\n\t\t\t\t\t})\n\t\t\t\t\t.lean()\n\t\t\t).map(p => p._id.toString());\n\n\t\t\t// ensure category products are present in the map with category values if not already set\n\t\t\tfor (const id of categoryWiseProducts) {\n\t\t\t\tif (!productsMap[id] && categoryValue !== undefined && categoryValueType !== undefined) {\n\t\t\t\t\tproductsMap[id] = {\n\t\t\t\t\t\tvalue: Number(categoryValue),\n\t\t\t\t\t\tvalueType: categoryValueType,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// process all entries\n\t\t\tfor (const [productId, info] of Object.entries(productsMap)) {\n\t\t\t\tawait this.createSingleProductMarketing(\n\t\t\t\t\tmarketingId,\n\t\t\t\t\tnew mongoose.Types.ObjectId(productId),\n\t\t\t\t\tinfo.value,\n\t\t\t\t\tinfo.valueType\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const discountMarketingService = Container.get(DiscountMarketingService);\n"]}
@@ -3,6 +3,8 @@ import { FeaturedMarketing as Model } from '@lyxa.ai/core/dist/libraries/mongo/m
3
3
  import { CreateFeaturedMarketingDTO as CreateDTO, UpdateFeaturedMarketingDTO as UpdateDTO } from '../../marketing/validations';
4
4
  export declare class FeaturedMarketingService {
5
5
  private model;
6
+ private financeSettlementModel;
7
+ private shopModel;
6
8
  constructor();
7
9
  create(data: CreateDTO): Promise<DocumentType<Model>>;
8
10
  update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>>;
@@ -1 +1 @@
1
- {"version":3,"file":"featured-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/featured-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAC1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAExC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAC;;IAUD,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IASrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;CAsBhG;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
1
+ {"version":3,"file":"featured-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/featured-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAGN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAKxC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAC;IACd,OAAO,CAAC,sBAAsB,CAAgC;IAC9D,OAAO,CAAC,SAAS,CAAmB;;IAYvB,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA2BrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;CA2BhG;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}