@lyxa.ai/marketing 1.0.59 → 1.0.60

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 (194) hide show
  1. package/dist/lib/event/event-initializations.d.ts.map +1 -1
  2. package/dist/lib/event/event-initializations.js +0 -1
  3. package/dist/lib/event/event-initializations.js.map +1 -1
  4. package/dist/lib/event/event-listeners/event-listeners.d.ts +0 -1
  5. package/dist/lib/event/event-listeners/event-listeners.d.ts.map +1 -1
  6. package/dist/lib/event/event-listeners/event-listeners.js +12 -62
  7. package/dist/lib/event/event-listeners/event-listeners.js.map +1 -1
  8. package/dist/lib/event/events/marketing-product-seed.event.d.ts +2 -1
  9. package/dist/lib/event/events/marketing-product-seed.event.d.ts.map +1 -1
  10. package/dist/lib/event/events/marketing-product-seed.event.js.map +1 -1
  11. package/dist/lib/index.d.ts +11 -7869
  12. package/dist/lib/index.d.ts.map +1 -1
  13. package/dist/lib/index.js +0 -2
  14. package/dist/lib/index.js.map +1 -1
  15. package/dist/lib/modules/coupon/routers/coupon.router.d.ts +2 -7630
  16. package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
  17. package/dist/lib/modules/coupon/routers/coupon.router.js +7 -0
  18. package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
  19. package/dist/lib/modules/coupon/services/coupon.service.d.ts +1 -0
  20. package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
  21. package/dist/lib/modules/coupon/services/coupon.service.js +4 -3
  22. package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
  23. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +2 -2
  24. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
  25. package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +6 -6
  26. package/dist/lib/modules/coupon/validations/coupon.validation.js +2 -2
  27. package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
  28. package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
  29. package/dist/lib/modules/coupon/validations/create-coupon.validation.js +1 -4
  30. package/dist/lib/modules/coupon/validations/create-coupon.validation.js.map +1 -1
  31. package/dist/lib/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
  32. package/dist/lib/modules/deal-setting/services/deal-setting.service.js +1 -4
  33. package/dist/lib/modules/deal-setting/services/deal-setting.service.js.map +1 -1
  34. package/dist/lib/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
  35. package/dist/lib/modules/featured-setting/services/featured-setting.service.js +0 -3
  36. package/dist/lib/modules/featured-setting/services/featured-setting.service.js.map +1 -1
  37. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts +8 -54
  38. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
  39. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js +0 -11
  40. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js.map +1 -1
  41. package/dist/lib/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
  42. package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js +0 -6
  43. package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js.map +1 -1
  44. package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +1 -0
  45. package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
  46. package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js +6 -2
  47. package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js.map +1 -1
  48. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +3 -16
  49. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
  50. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js +3 -22
  51. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js.map +1 -1
  52. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +0 -2
  53. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
  54. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js +0 -12
  55. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js.map +1 -1
  56. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +35 -242
  57. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
  58. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js +1 -19
  59. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js.map +1 -1
  60. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +1 -6
  61. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
  62. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js +1 -45
  63. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js.map +1 -1
  64. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +0 -3
  65. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
  66. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js +8 -66
  67. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js.map +1 -1
  68. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
  69. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
  70. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js +19 -37
  71. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js.map +1 -1
  72. package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +10 -241
  73. package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
  74. package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts +0 -2
  75. package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
  76. package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js +3 -15
  77. package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js.map +1 -1
  78. package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
  79. package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js +1 -1
  80. package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js.map +1 -1
  81. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +2 -10
  82. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
  83. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js +1 -4
  84. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js.map +1 -1
  85. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +0 -10
  86. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
  87. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js +0 -43
  88. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js.map +1 -1
  89. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +2 -187
  90. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
  91. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js +0 -29
  92. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js.map +1 -1
  93. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +0 -395
  94. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
  95. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js +6 -16
  96. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js.map +1 -1
  97. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +4 -7
  98. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
  99. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js +6 -31
  100. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js.map +1 -1
  101. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +3 -14
  102. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
  103. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js +16 -76
  104. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js.map +1 -1
  105. package/dist/lib/modules/marketing/services/marketing.service.d.ts +0 -1
  106. package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
  107. package/dist/lib/modules/marketing/services/marketing.service.js +46 -60
  108. package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
  109. package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +3 -2
  110. package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
  111. package/dist/lib/modules/marketing/services/product-marketing.service.js +13 -42
  112. package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
  113. package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
  114. package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js +27 -95
  115. package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js.map +1 -1
  116. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts +1 -0
  117. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
  118. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js +49 -2
  119. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js.map +1 -1
  120. package/dist/types/event/event-initializations.d.ts.map +1 -1
  121. package/dist/types/event/event-listeners/event-listeners.d.ts +0 -1
  122. package/dist/types/event/event-listeners/event-listeners.d.ts.map +1 -1
  123. package/dist/types/event/events/marketing-product-seed.event.d.ts +2 -1
  124. package/dist/types/event/events/marketing-product-seed.event.d.ts.map +1 -1
  125. package/dist/types/index.d.ts +11 -7869
  126. package/dist/types/index.d.ts.map +1 -1
  127. package/dist/types/modules/coupon/routers/coupon.router.d.ts +2 -7630
  128. package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
  129. package/dist/types/modules/coupon/services/coupon.service.d.ts +1 -0
  130. package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
  131. package/dist/types/modules/coupon/validations/coupon.validation.d.ts +6 -6
  132. package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
  133. package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
  134. package/dist/types/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
  135. package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts +8 -54
  136. package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
  137. package/dist/types/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
  138. package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +1 -0
  139. package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
  140. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +3 -16
  141. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
  142. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +0 -2
  143. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
  144. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +35 -242
  145. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
  146. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +1 -6
  147. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
  148. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +0 -3
  149. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
  150. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
  151. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
  152. package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +10 -241
  153. package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
  154. package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts +0 -2
  155. package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
  156. package/dist/types/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
  157. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +2 -10
  158. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
  159. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +0 -10
  160. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
  161. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +2 -187
  162. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
  163. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +0 -395
  164. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
  165. package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +4 -7
  166. package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
  167. package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +3 -14
  168. package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
  169. package/dist/types/modules/marketing/services/marketing.service.d.ts +0 -1
  170. package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
  171. package/dist/types/modules/marketing/services/product-marketing.service.d.ts +3 -7
  172. package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
  173. package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
  174. package/dist/types/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts +5 -0
  175. package/dist/types/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
  176. package/package.json +2 -2
  177. package/dist/lib/event/events/marketing-product-sync.event.d.ts +0 -11
  178. package/dist/lib/event/events/marketing-product-sync.event.d.ts.map +0 -1
  179. package/dist/lib/event/events/marketing-product-sync.event.js +0 -12
  180. package/dist/lib/event/events/marketing-product-sync.event.js.map +0 -1
  181. package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts +0 -13
  182. package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts.map +0 -1
  183. package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.js +0 -75
  184. package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.js.map +0 -1
  185. package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts +0 -21
  186. package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts.map +0 -1
  187. package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.js +0 -83
  188. package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.js.map +0 -1
  189. package/dist/types/event/events/marketing-product-sync.event.d.ts +0 -11
  190. package/dist/types/event/events/marketing-product-sync.event.d.ts.map +0 -1
  191. package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts +0 -13
  192. package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts.map +0 -1
  193. package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts +0 -21
  194. package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts.map +0 -1
@@ -1,6 +1,5 @@
1
1
  import { DocumentType, mongoose } from '@typegoose/typegoose';
2
- import { LimitedTimeOfferCampaign } from '@lyxa.ai/core/dist/libraries/mongo/models';
3
- import { AdminEnrollShopEntryDTO, JoinLtoCampaignDTO, ParticipantStatusDTO } from '../limited-time-offer-participant.validation';
2
+ import { JoinLtoCampaignDTO, ParticipantStatusDTO } from '../limited-time-offer-participant.validation';
4
3
  import { GetLtoCampaignParticipantsDTO } from '../../campaign/limited-time-offer-campaign.validation';
5
4
  export declare class LimitedTimeOfferParticipantService {
6
5
  private repository;
@@ -8,16 +7,7 @@ export declare class LimitedTimeOfferParticipantService {
8
7
  private marketingService;
9
8
  constructor();
10
9
  join(shopId: mongoose.Types.ObjectId, dto: JoinLtoCampaignDTO): Promise<DocumentType<import("@lyxa.ai/core/dist/libraries/mongo/models").LimitedTimeOfferParticipant>>;
11
- enrollShops(entries: AdminEnrollShopEntryDTO[]): Promise<(mongoose.Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, import("@lyxa.ai/core/dist/libraries/mongo/models").LimitedTimeOfferParticipant, Record<string, any>, {}> & import("@lyxa.ai/core/dist/libraries/mongo/models").LimitedTimeOfferParticipant & {
12
- _id: mongoose.Types.ObjectId;
13
- } & {
14
- __v: number;
15
- } & import("@typegoose/typegoose/lib/types").IObjectWithTypegooseFunction)[]>;
16
- private joinShop;
17
- private pauseIfLive;
18
10
  withdraw(shopId: mongoose.Types.ObjectId): Promise<void>;
19
- cleanupCampaignMarketings(campaignId: mongoose.Types.ObjectId): Promise<void>;
20
- isActiveParticipant(shopId: mongoose.Types.ObjectId): Promise<boolean>;
21
11
  getStatus(shopId: mongoose.Types.ObjectId): Promise<ParticipantStatusDTO>;
22
12
  update(shopId: mongoose.Types.ObjectId, dto: JoinLtoCampaignDTO): Promise<DocumentType<import("@lyxa.ai/core/dist/libraries/mongo/models").LimitedTimeOfferParticipant> | null>;
23
13
  getParticipants(dto: GetLtoCampaignParticipantsDTO): Promise<{
@@ -25,9 +15,9 @@ export declare class LimitedTimeOfferParticipantService {
25
15
  shopId: mongoose.Types.ObjectId;
26
16
  joinedAt: Date;
27
17
  shopName: string | null;
28
- shopPhoto?: string | null | undefined;
29
18
  discountPercentage?: number | undefined;
30
19
  maxDiscountCap?: number | undefined;
20
+ shopPhoto?: string | null | undefined;
31
21
  }[];
32
22
  metadata: {
33
23
  page: number;
@@ -41,8 +31,7 @@ export declare class LimitedTimeOfferParticipantService {
41
31
  latitude: number;
42
32
  longitude: number;
43
33
  }): Promise<any[]>;
44
- reactivateMarketings(campaign: DocumentType<LimitedTimeOfferCampaign>): Promise<void>;
45
- private applyMarketingWithRollback;
34
+ removeCampaignMarketings(campaignId: mongoose.Types.ObjectId): Promise<void>;
46
35
  private fetchCurrentCampaignOrThrow;
47
36
  private assertNotAlreadyJoined;
48
37
  private resolveCategorySelection;
@@ -1 +1 @@
1
- {"version":3,"file":"limited-time-offer-participant.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/participant/services/limited-time-offer-participant.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YA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M,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAOlC,oBAAoB,CAAC,QAAQ,EAAE,YAAY,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YA+BpF,0BAA0B;YAe1B,2BAA2B;YAQ3B,sBAAsB;YActB,wBAAwB;YAqBxB,0BAA0B;IAexC,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,0BAA0B;CAkBlC;AAED,eAAO,MAAM,qBAAqB,oCAAoD,CAAC"}
1
+ {"version":3,"file":"limited-time-offer-participant.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/participant/services/limited-time-offer-participant.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAM5D,OAAO,EACN,kBAAkB,EAElB,oBAAoB,EAEpB,MAAM,8CAA8C,CAAC;AAGtD,OAAO,EAAC,6BAA6B,EAAC,MAAM,uDAAuD,CAAC;AAGpG,qBACa,kCAAkC;IAC9C,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,eAAe,CAAqB;IAC5C,OAAO,CAAC,gBAAgB,CAAiC;;IAQ5C,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,kBAAkB;IAsB7D,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxD,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAmBzE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,kBAAkB;IA0B/D,eAAe,CAAC,GAAG,EAAE,6BAA6B;;;;;;;;;;;;;;;;IAalD,6BAA6B,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ;IAIjE,SAAS,CACrB,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACnC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAOlC,wBAAwB,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;YAI3E,2BAA2B;YAQ3B,sBAAsB;YActB,wBAAwB;YAqBxB,0BAA0B;IAexC,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,0BAA0B;CAiBlC;AAED,eAAO,MAAM,qBAAqB,oCAAoD,CAAC"}
@@ -63,40 +63,15 @@ let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantServic
63
63
  }
64
64
  async join(shopId, dto) {
65
65
  const campaign = await this.fetchCurrentCampaignOrThrow();
66
- return this.joinShop(campaign, shopId, dto);
67
- }
68
- async enrollShops(entries) {
69
- const campaign = await this.fetchCurrentCampaignOrThrow();
70
- return Promise.all(entries.map(({ shopId, ...dto }) => this.joinShop(campaign, shopId, dto)));
71
- }
72
- async joinShop(campaign, shopId, dto) {
73
66
  await this.assertNotAlreadyJoined(campaign._id, shopId);
74
- this.validateDiscountSelections({ campaign, discountPercentage: dto.discountPercentage, maxDiscountCap: dto.maxDiscountCap });
67
+ this.validateDiscountSelections(campaign, dto.discountPercentage, dto.maxDiscountCap);
75
68
  await this.assertProductsBelongToShop(shopId, dto);
76
69
  const resolvedDto = await this.resolveCategorySelection(shopId, dto);
77
- const pausedMarketings = await this.pauseIfLive(campaign, shopId);
78
- const { marketingId, pausedMarketingIds } = await this.applyMarketingWithRollback({
79
- shopId,
80
- campaign,
81
- dto: resolvedDto,
82
- pausedMarketings,
83
- });
84
- const allPausedMarketings = this.uniqueObjectIds([...pausedMarketings, ...pausedMarketingIds]);
85
- const participant = await this.repository.create(limited_time_offer_participant_builder_1.LtoParticipantQueryBuilder.buildCreateInput({
86
- campaignId: campaign._id,
87
- shopId,
88
- marketingId,
89
- dto: resolvedDto,
90
- pausedMarketings: allPausedMarketings,
91
- }));
70
+ const marketingId = await this.marketingService.applyMarketing(shopId, campaign, resolvedDto);
71
+ const participant = await this.repository.create(limited_time_offer_participant_builder_1.LtoParticipantQueryBuilder.buildCreateInput(campaign._id, shopId, marketingId, resolvedDto));
92
72
  await this.repository.updateShopOrderCapacity(shopId, resolvedDto.isOrderCapacityEnabled, resolvedDto.maxOrderCapacity);
93
73
  return participant;
94
74
  }
95
- async pauseIfLive(campaign, shopId) {
96
- if (campaign.status !== enum_1.LimitedTimeOfferCampaignStatus.ACTIVE)
97
- return [];
98
- return this.marketingService.pauseActiveShopMarketings(shopId, enum_1.MarketingType.DISCOUNT);
99
- }
100
75
  async withdraw(shopId) {
101
76
  const campaign = await this.fetchCurrentCampaignOrThrow();
102
77
  const participant = await this.repository.withdraw(campaign._id, shopId);
@@ -105,18 +80,6 @@ let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantServic
105
80
  if (participant.marketing) {
106
81
  await this.marketingService.removeMarketing(participant.marketing);
107
82
  }
108
- await this.marketingService.resumeMarketings((participant.pausedMarketings ?? []));
109
- }
110
- async cleanupCampaignMarketings(campaignId) {
111
- await this.marketingService.removeAllCampaignMarketings(campaignId);
112
- const pausedMarketingIds = await this.repository.findPausedMarketingIdsByCampaign(campaignId);
113
- await this.marketingService.resumeMarketings(pausedMarketingIds);
114
- }
115
- async isActiveParticipant(shopId) {
116
- const campaign = await this.campaignService.getCurrent();
117
- if (!campaign)
118
- return false;
119
- return this.repository.existsActiveByCampaignAndShop(campaign._id, shopId);
120
83
  }
121
84
  async getStatus(shopId) {
122
85
  const campaign = await this.campaignService.getCurrent();
@@ -137,13 +100,12 @@ let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantServic
137
100
  const participant = await this.repository.findActiveByCampaignAndShop(campaign._id, shopId);
138
101
  if (!participant)
139
102
  throw (0, error_common_1.notFoundError)('You have not joined this campaign.');
140
- this.validateDiscountSelections({ campaign, discountPercentage: dto.discountPercentage, maxDiscountCap: dto.maxDiscountCap, participant });
103
+ this.validateDiscountSelections(campaign, dto.discountPercentage, dto.maxDiscountCap, participant);
141
104
  await this.assertProductsBelongToShop(shopId, dto);
142
105
  const resolvedDto = await this.resolveCategorySelection(shopId, dto);
143
- if (participant.marketingId) {
144
- await this.marketingService.removeMarketing(participant.marketingId);
145
- }
146
- const { marketingId: newMarketingId } = await this.marketingService.applyMarketing(shopId, campaign, resolvedDto);
106
+ const newMarketingId = participant.marketingId
107
+ ? await this.marketingService.replaceMarketing(participant.marketingId, shopId, campaign, resolvedDto)
108
+ : await this.marketingService.applyMarketing(shopId, campaign, resolvedDto);
147
109
  return this.repository.updateParticipant(campaign._id, shopId, {
148
110
  products: resolvedDto.products ?? [],
149
111
  isEntireMenu: resolvedDto.isEntireMenu,
@@ -158,7 +120,12 @@ let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantServic
158
120
  const { documents, total } = await this.repository.findByCampaign(dto);
159
121
  return {
160
122
  documents,
161
- metadata: { page: dto.page, size: dto.size, totalElements: total, totalPages: Math.ceil(total / dto.size) },
123
+ metadata: {
124
+ page: dto.page,
125
+ size: dto.size,
126
+ totalElements: total,
127
+ totalPages: Math.ceil(total / dto.size),
128
+ },
162
129
  };
163
130
  }
164
131
  async getParticipantIdsByCampaignId(campaignId) {
@@ -169,34 +136,8 @@ let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantServic
169
136
  const nearByShopDistance = settings.nearByShopDistance || 10000;
170
137
  return this.repository.findNearby(campaignId, input, nearByShopDistance);
171
138
  }
172
- async reactivateMarketings(campaign) {
173
- const participants = await this.repository.findAllActiveByCampaign(campaign._id);
174
- for (const participant of participants) {
175
- const dto = {
176
- isEntireMenu: participant.isEntireMenu,
177
- products: (participant.products ?? []),
178
- shopCategories: [],
179
- discountPercentage: participant.discountPercentage ?? 0,
180
- maxDiscountCap: participant.maxDiscountCap ?? 0,
181
- isOrderCapacityEnabled: participant.isOrderCapacityEnabled,
182
- maxOrderCapacity: participant.maxOrderCapacity,
183
- };
184
- if (participant.marketing) {
185
- await this.marketingService.removeMarketing(participant.marketing);
186
- }
187
- const { marketingId } = await this.marketingService.applyMarketing(participant.shop, campaign, dto);
188
- await this.repository.updateParticipant(campaign._id, participant.shop, { ...dto, marketing: marketingId });
189
- }
190
- }
191
- async applyMarketingWithRollback(input) {
192
- const { shopId, campaign, dto, pausedMarketings } = input;
193
- try {
194
- return await this.marketingService.applyMarketing(shopId, campaign, dto);
195
- }
196
- catch (err) {
197
- await this.marketingService.resumeMarketings(pausedMarketings);
198
- throw err;
199
- }
139
+ async removeCampaignMarketings(campaignId) {
140
+ await this.marketingService.removeAllCampaignMarketings(campaignId);
200
141
  }
201
142
  async fetchCurrentCampaignOrThrow() {
202
143
  const campaign = await this.campaignService.getCurrent();
@@ -234,8 +175,7 @@ let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantServic
234
175
  uniqueObjectIds(ids) {
235
176
  return [...new Map(ids.map(id => [id.toString(), id])).values()];
236
177
  }
237
- validateDiscountSelections(input) {
238
- const { campaign, discountPercentage, maxDiscountCap, participant } = input;
178
+ validateDiscountSelections(campaign, discountPercentage, maxDiscountCap, participant) {
239
179
  if (!campaign.discountOptions.includes(discountPercentage)) {
240
180
  if (!participant || discountPercentage != participant.discountPercentage) {
241
181
  throw (0, error_common_1.badRequestError)('Selected discount is not an available option for this campaign.');
@@ -1 +1 @@
1
- {"version":3,"file":"limited-time-offer-participant.service.js","sourceRoot":"/","sources":["modules/limited-time-offer/participant/services/limited-time-offer-participant.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAG1C,4DAAgG;AAChG,4EAAwG;AACxG,2IAAqH;AACrH,yHAAkG;AAClG,4GAMsD;AACtD,sGAAqF;AACrF,4GAAsF;AAEtF,wCAA2C;AAGpC,IAAM,kCAAkC,GAAxC,M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,CAAC;YACxD,IAAI,CAAC,WAAW,IAAI,cAAc,IAAI,WAAW,CAAC,cAAc,EAAE,CAAC;gBAClE,MAAM,IAAA,8BAAe,EAAC,yEAAyE,CAAC,CAAC;YAClG,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAA;AA7RY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,gBAAO,GAAE;;GACG,kCAAkC,CA6R9C;AAEY,QAAA,qBAAqB,GAAG,gBAAS,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {DocumentType, mongoose} from '@typegoose/typegoose';\nimport {LimitedTimeOfferCampaign, Setting} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {LimitedTimeOfferCampaignStatus, MarketingType} from '@lyxa.ai/core/dist/utilities/enum';\nimport {badRequestError, conflictError, notFoundError} from '@lyxa.ai/core/dist/utilities/error-common';\nimport {LtoCampaignService} from '@modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service';\nimport {LtoParticipantMarketingService} from './limited-time-offer-participant-marketing.service';\nimport {\n\tAdminEnrollShopEntryDTO,\n\tJoinLtoCampaignDTO,\n\tLtoCardState,\n\tParticipantStatusDTO,\n\tParticipantSummaryDTO,\n} from '../limited-time-offer-participant.validation';\nimport {LtoParticipantQueryBuilder} from '../limited-time-offer-participant.builder';\nimport {LtoParticipantRepository} from '../limited-time-offer-participant.repository';\nimport {GetLtoCampaignParticipantsDTO} from '../../campaign/limited-time-offer-campaign.validation';\nimport {getLibraries} from '@lyxa.ai/core';\n\n@Service()\nexport class LimitedTimeOfferParticipantService {\n\tprivate repository: LtoParticipantRepository;\n\tprivate campaignService: LtoCampaignService;\n\tprivate marketingService: LtoParticipantMarketingService;\n\n\tconstructor() {\n\t\tthis.repository = Container.get(LtoParticipantRepository);\n\t\tthis.campaignService = Container.get(LtoCampaignService);\n\t\tthis.marketingService = Container.get(LtoParticipantMarketingService);\n\t}\n\n\tpublic async join(shopId: mongoose.Types.ObjectId, dto: JoinLtoCampaignDTO) {\n\t\tconst campaign = await this.fetchCurrentCampaignOrThrow();\n\t\treturn this.joinShop(campaign, shopId, dto);\n\t}\n\n\tpublic async enrollShops(entries: AdminEnrollShopEntryDTO[]) {\n\t\tconst campaign = await this.fetchCurrentCampaignOrThrow();\n\t\treturn Promise.all(entries.map(({shopId, ...dto}) => this.joinShop(campaign, shopId, dto)));\n\t}\n\n\tprivate async joinShop(\n\t\tcampaign: DocumentType<LimitedTimeOfferCampaign>,\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tdto: JoinLtoCampaignDTO\n\t) {\n\t\tawait this.assertNotAlreadyJoined(campaign._id, shopId);\n\t\tthis.validateDiscountSelections({campaign, discountPercentage: dto.discountPercentage, maxDiscountCap: dto.maxDiscountCap});\n\t\tawait this.assertProductsBelongToShop(shopId, dto);\n\n\t\tconst resolvedDto = await this.resolveCategorySelection(shopId, dto);\n\t\tconst pausedMarketings = await this.pauseIfLive(campaign, shopId);\n\n\t\tconst {marketingId, pausedMarketingIds} = await this.applyMarketingWithRollback({\n\t\t\tshopId,\n\t\t\tcampaign,\n\t\t\tdto: resolvedDto,\n\t\t\tpausedMarketings,\n\t\t});\n\t\tconst allPausedMarketings = this.uniqueObjectIds([...pausedMarketings, ...pausedMarketingIds]);\n\n\t\tconst participant = await this.repository.create(\n\t\t\tLtoParticipantQueryBuilder.buildCreateInput({\n\t\t\t\tcampaignId: campaign._id,\n\t\t\t\tshopId,\n\t\t\t\tmarketingId,\n\t\t\t\tdto: resolvedDto,\n\t\t\t\tpausedMarketings: allPausedMarketings,\n\t\t\t})\n\t\t);\n\t\tawait this.repository.updateShopOrderCapacity(\n\t\t\tshopId,\n\t\t\tresolvedDto.isOrderCapacityEnabled,\n\t\t\tresolvedDto.maxOrderCapacity\n\t\t);\n\t\treturn participant;\n\t}\n\n\tprivate async pauseIfLive(\n\t\tcampaign: DocumentType<LimitedTimeOfferCampaign>,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<mongoose.Types.ObjectId[]> {\n\t\tif (campaign.status !== LimitedTimeOfferCampaignStatus.ACTIVE) return [];\n\t\treturn this.marketingService.pauseActiveShopMarketings(shopId, MarketingType.DISCOUNT);\n\t}\n\n\tpublic async withdraw(shopId: mongoose.Types.ObjectId): Promise<void> {\n\t\tconst campaign = await this.fetchCurrentCampaignOrThrow();\n\n\t\tconst participant = await this.repository.withdraw(campaign._id, shopId);\n\t\tif (!participant) throw notFoundError('You have not joined this campaign.');\n\n\t\tif (participant.marketing) {\n\t\t\tawait this.marketingService.removeMarketing(participant.marketing as mongoose.Types.ObjectId);\n\t\t}\n\t\tawait this.marketingService.resumeMarketings(\n\t\t\t(participant.pausedMarketings ?? []) as mongoose.Types.ObjectId[]\n\t\t);\n\t}\n\n\tpublic async cleanupCampaignMarketings(campaignId: mongoose.Types.ObjectId): Promise<void> {\n\t\tawait this.marketingService.removeAllCampaignMarketings(campaignId);\n\t\tconst pausedMarketingIds = await this.repository.findPausedMarketingIdsByCampaign(campaignId);\n\t\tawait this.marketingService.resumeMarketings(pausedMarketingIds);\n\t}\n\n\tpublic async isActiveParticipant(shopId: mongoose.Types.ObjectId): Promise<boolean> {\n\t\tconst campaign = await this.campaignService.getCurrent();\n\t\tif (!campaign) return false;\n\t\treturn this.repository.existsActiveByCampaignAndShop(campaign._id, shopId);\n\t}\n\n\tpublic async getStatus(shopId: mongoose.Types.ObjectId): Promise<ParticipantStatusDTO> {\n\t\tconst campaign = await this.campaignService.getCurrent();\n\n\t\tif (!campaign) return { campaignState: LtoCardState.NONE };\n\n\t\tconst participant = await this.repository.findActiveByCampaignAndShop(campaign._id, shopId);\n\n\t\tconst campaignState =\n\t\t\tcampaign.status === LimitedTimeOfferCampaignStatus.SCHEDULED\n\t\t\t\t? LtoCardState.SCHEDULED\n\t\t\t\t: campaign.status === LimitedTimeOfferCampaignStatus.ACTIVE\n\t\t\t\t\t? LtoCardState.LIVE\n\t\t\t\t\t: LtoCardState.NONE;\n\n\t\treturn participant\n\t\t\t? { campaignState, campaign: campaign as any, participant }\n\t\t\t: { campaignState, campaign: campaign as any };\n\t}\n\n\tpublic async update(shopId: mongoose.Types.ObjectId, dto: JoinLtoCampaignDTO) {\n\t\tconst campaign = await this.fetchCurrentCampaignOrThrow();\n\n\t\tconst participant = await this.repository.findActiveByCampaignAndShop(campaign._id, shopId);\n\t\tif (!participant) throw notFoundError('You have not joined this campaign.');\n\n\t\tthis.validateDiscountSelections({campaign, discountPercentage: dto.discountPercentage, maxDiscountCap: dto.maxDiscountCap, participant});\n\t\tawait this.assertProductsBelongToShop(shopId, dto);\n\n\t\tconst resolvedDto = await this.resolveCategorySelection(shopId, dto);\n\n\t\tif (participant.marketingId) {\n\t\t\tawait this.marketingService.removeMarketing(participant.marketingId);\n\t\t}\n\t\tconst {marketingId: newMarketingId} = await this.marketingService.applyMarketing(shopId, campaign, resolvedDto);\n\n\t\treturn this.repository.updateParticipant(campaign._id, shopId, {\n\t\t\tproducts: resolvedDto.products ?? [],\n\t\t\tisEntireMenu: resolvedDto.isEntireMenu,\n\t\t\tdiscountPercentage: resolvedDto.discountPercentage,\n\t\t\tmaxDiscountCap: resolvedDto.maxDiscountCap,\n\t\t\tisOrderCapacityEnabled: resolvedDto.isOrderCapacityEnabled,\n\t\t\tmaxOrderCapacity: resolvedDto.maxOrderCapacity,\n\t\t\tmarketing: newMarketingId,\n\t\t});\n\t}\n\n\tpublic async getParticipants(dto: GetLtoCampaignParticipantsDTO) {\n\t\tconst {documents, total} = await this.repository.findByCampaign(dto);\n\t\treturn {\n\t\t\tdocuments,\n\t\t\tmetadata: {page: dto.page, size: dto.size, totalElements: total, totalPages: Math.ceil(total / dto.size)},\n\t\t};\n\t}\n\n\tpublic async getParticipantIdsByCampaignId(campaignId: mongoose.Types.ObjectId) {\n\t\treturn await this.repository.findParticipantIdsByCampaignId(campaignId);\n\t}\n\n\tpublic async getNearby(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tinput: { latitude: number; longitude: number }\n\t) {\n\t\tconst settings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\t\tconst nearByShopDistance = settings.nearByShopDistance || 10000;\n\t\treturn this.repository.findNearby(campaignId, input, nearByShopDistance);\n\t}\n\n\tpublic async reactivateMarketings(campaign: DocumentType<LimitedTimeOfferCampaign>): Promise<void> {\n\t\tconst participants = await this.repository.findAllActiveByCampaign(campaign._id);\n\n\t\tfor (const participant of participants) {\n\t\t\tconst dto: JoinLtoCampaignDTO = {\n\t\t\t\tisEntireMenu: participant.isEntireMenu,\n\t\t\t\tproducts: (participant.products ?? []) as mongoose.Types.ObjectId[],\n\t\t\t\tshopCategories: [],\n\t\t\t\tdiscountPercentage: participant.discountPercentage ?? 0,\n\t\t\t\tmaxDiscountCap: participant.maxDiscountCap ?? 0,\n\t\t\t\tisOrderCapacityEnabled: participant.isOrderCapacityEnabled,\n\t\t\t\tmaxOrderCapacity: participant.maxOrderCapacity,\n\t\t\t};\n\t\t\t// Drop any prior marketing (e.g. created when the shop joined between recurrences) so we\n\t\t\t// don't orphan it — it carries no campaign ref and would leak past cleanup.\n\t\t\tif (participant.marketing) {\n\t\t\t\tawait this.marketingService.removeMarketing(participant.marketing as mongoose.Types.ObjectId);\n\t\t\t}\n\t\t\tconst {marketingId} = await this.marketingService.applyMarketing(\n\t\t\t\tparticipant.shop as mongoose.Types.ObjectId,\n\t\t\t\tcampaign,\n\t\t\t\tdto,\n\t\t\t);\n\t\t\tawait this.repository.updateParticipant(\n\t\t\t\tcampaign._id,\n\t\t\t\tparticipant.shop as mongoose.Types.ObjectId,\n\t\t\t\t{...dto, marketing: marketingId},\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async applyMarketingWithRollback(input: {\n\t\tshopId: mongoose.Types.ObjectId;\n\t\tcampaign: DocumentType<LimitedTimeOfferCampaign>;\n\t\tdto: JoinLtoCampaignDTO;\n\t\tpausedMarketings: mongoose.Types.ObjectId[];\n\t}): Promise<{marketingId: mongoose.Types.ObjectId; pausedMarketingIds: mongoose.Types.ObjectId[]}> {\n\t\tconst {shopId, campaign, dto, pausedMarketings} = input;\n\t\ttry {\n\t\t\treturn await this.marketingService.applyMarketing(shopId, campaign, dto);\n\t\t} catch (err) {\n\t\t\tawait this.marketingService.resumeMarketings(pausedMarketings);\n\t\t\tthrow err;\n\t\t}\n\t}\n\n\tprivate async fetchCurrentCampaignOrThrow(): Promise<DocumentType<LimitedTimeOfferCampaign>> {\n\t\tconst campaign = await this.campaignService.getCurrent();\n\t\tif (!campaign) {\n\t\t\tthrow badRequestError('No campaign active or scheduled.');\n\t\t}\n\t\treturn campaign;\n\t}\n\n\tprivate async assertNotAlreadyJoined(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tif (await this.repository.existsActiveByCampaignAndShop(campaignId, shopId)) {\n\t\t\tthrow conflictError('Your shop has already joined this campaign.');\n\t\t}\n\t}\n\n\t/**\n\t * Expands the selected shop categories into their product ids and merges them with any explicitly\n\t * selected products. The marketing layer only ever receives a flat product list, so category\n\t * selection is purely an LTO-side convenience that is resolved here before anything is persisted.\n\t */\n\tprivate async resolveCategorySelection(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tdto: JoinLtoCampaignDTO\n\t): Promise<JoinLtoCampaignDTO> {\n\t\tif (dto.isEntireMenu || !dto.shopCategories?.length) return dto;\n\n\t\tconst categoryProductIds = await this.repository.findProductIdsByCategories(shopId, dto.shopCategories);\n\t\tconst products = this.uniqueObjectIds([...(dto.products ?? []), ...categoryProductIds]);\n\n\t\tif (products.length === 0) {\n\t\t\tthrow badRequestError('The selected categories do not contain any products.');\n\t\t}\n\n\t\treturn { ...dto, products };\n\t}\n\n\t/**\n\t * Validates that explicitly selected products belong to the shop. Categories are not checked here:\n\t * {@link resolveCategorySelection} fetches their products with a shop-scoped query, so any category\n\t * that does not belong to the shop simply contributes no products.\n\t */\n\tprivate async assertProductsBelongToShop(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tdto: JoinLtoCampaignDTO\n\t): Promise<void> {\n\t\tif (dto.isEntireMenu) return;\n\n\t\tconst productIds = this.uniqueObjectIds(dto.products ?? []);\n\t\tif (!productIds.length) return;\n\n\t\tconst owned = await this.repository.countShopProducts(shopId, productIds);\n\t\tif (owned !== productIds.length) {\n\t\t\tthrow badRequestError('One or more selected products do not belong to your shop.');\n\t\t}\n\t}\n\n\tprivate uniqueObjectIds(ids: mongoose.Types.ObjectId[]): mongoose.Types.ObjectId[] {\n\t\treturn [...new Map(ids.map(id => [id.toString(), id])).values()];\n\t}\n\n\tprivate validateDiscountSelections(input: {\n\t\tcampaign: DocumentType<LimitedTimeOfferCampaign>;\n\t\tdiscountPercentage: number;\n\t\tmaxDiscountCap: number;\n\t\tparticipant?: ParticipantSummaryDTO;\n\t}): void {\n\t\tconst {campaign, discountPercentage, maxDiscountCap, participant} = input;\n\t\tif (!campaign.discountOptions.includes(discountPercentage)) {\n\t\t\tif (!participant || discountPercentage != participant.discountPercentage) {\n\t\t\t\tthrow badRequestError('Selected discount is not an available option for this campaign.');\n\t\t\t}\n\t\t}\n\t\tif (!campaign.maxDiscountCaps.includes(maxDiscountCap)) {\n\t\t\tif (!participant || maxDiscountCap != participant.maxDiscountCap) {\n\t\t\t\tthrow badRequestError('Selected max discount cap is not an available option for this campaign.');\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const ltoParticipantService = Container.get(LimitedTimeOfferParticipantService);\n"]}
1
+ {"version":3,"file":"limited-time-offer-participant.service.js","sourceRoot":"/","sources":["modules/limited-time-offer/participant/services/limited-time-offer-participant.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAG1C,4DAAiF;AACjF,4EAAwG;AACxG,2IAAqH;AACrH,yHAAkG;AAClG,4GAKsD;AACtD,sGAAqF;AACrF,4GAAsF;AAEtF,wCAA2C;AAGpC,IAAM,kCAAkC,GA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,eAAe,CAAC,GAA8B;QACrD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IAClE,CAAC;IAEO,0BAA0B,CACjC,QAAgD,EAChD,kBAA0B,EAC1B,cAAsB,EACtB,WAAmC;QAEnC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;YAC5D,IAAI,CAAC,WAAW,IAAI,kBAAkB,IAAI,WAAW,CAAC,kBAAkB,EAAE,CAAC;gBAC1E,MAAM,IAAA,8BAAe,EAAC,iEAAiE,CAAC,CAAC;YAC1F,CAAC;QACF,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YACxD,IAAI,CAAC,WAAW,IAAI,cAAc,IAAI,WAAW,CAAC,cAAc,EAAE,CAAC;gBAClE,MAAM,IAAA,8BAAe,EAAC,yEAAyE,CAAC,CAAC;YAClG,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAA;AAtMY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,gBAAO,GAAE;;GACG,kCAAkC,CAsM9C;AAEY,QAAA,qBAAqB,GAAG,gBAAS,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {DocumentType, mongoose} from '@typegoose/typegoose';\nimport {LimitedTimeOfferCampaign, Setting} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {LimitedTimeOfferCampaignStatus} from '@lyxa.ai/core/dist/utilities/enum';\nimport {badRequestError, conflictError, notFoundError} from '@lyxa.ai/core/dist/utilities/error-common';\nimport {LtoCampaignService} from '@modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service';\nimport {LtoParticipantMarketingService} from './limited-time-offer-participant-marketing.service';\nimport {\n\tJoinLtoCampaignDTO,\n\tLtoCardState,\n\tParticipantStatusDTO,\n\tParticipantSummaryDTO,\n} from '../limited-time-offer-participant.validation';\nimport {LtoParticipantQueryBuilder} from '../limited-time-offer-participant.builder';\nimport {LtoParticipantRepository} from '../limited-time-offer-participant.repository';\nimport {GetLtoCampaignParticipantsDTO} from '../../campaign/limited-time-offer-campaign.validation';\nimport {getLibraries} from '@lyxa.ai/core';\n\n@Service()\nexport class LimitedTimeOfferParticipantService {\n\tprivate repository: LtoParticipantRepository;\n\tprivate campaignService: LtoCampaignService;\n\tprivate marketingService: LtoParticipantMarketingService;\n\n\tconstructor() {\n\t\tthis.repository = Container.get(LtoParticipantRepository);\n\t\tthis.campaignService = Container.get(LtoCampaignService);\n\t\tthis.marketingService = Container.get(LtoParticipantMarketingService);\n\t}\n\n\tpublic async join(shopId: mongoose.Types.ObjectId, dto: JoinLtoCampaignDTO) {\n\t\tconst campaign = await this.fetchCurrentCampaignOrThrow();\n\n\t\tawait this.assertNotAlreadyJoined(campaign._id, shopId);\n\t\tthis.validateDiscountSelections(campaign, dto.discountPercentage, dto.maxDiscountCap);\n\t\tawait this.assertProductsBelongToShop(shopId, dto);\n\n\t\tconst resolvedDto = await this.resolveCategorySelection(shopId, dto);\n\t\tconst marketingId = await this.marketingService.applyMarketing(shopId, campaign, resolvedDto);\n\n\t\tconst participant = await this.repository.create(\n\t\t\tLtoParticipantQueryBuilder.buildCreateInput(campaign._id, shopId, marketingId, resolvedDto)\n\t\t);\n\t\t// Update shop\n\t\tawait this.repository.updateShopOrderCapacity(\n\t\t\tshopId,\n\t\t\tresolvedDto.isOrderCapacityEnabled,\n\t\t\tresolvedDto.maxOrderCapacity\n\t\t);\n\t\treturn participant;\n\t}\n\n\tpublic async withdraw(shopId: mongoose.Types.ObjectId): Promise<void> {\n\t\tconst campaign = await this.fetchCurrentCampaignOrThrow();\n\n\t\tconst participant = await this.repository.withdraw(campaign._id, shopId);\n\t\tif (!participant) throw notFoundError('You have not joined this campaign.');\n\n\t\tif (participant.marketing) {\n\t\t\tawait this.marketingService.removeMarketing(participant.marketing as mongoose.Types.ObjectId);\n\t\t}\n\t}\n\n\tpublic async getStatus(shopId: mongoose.Types.ObjectId): Promise<ParticipantStatusDTO> {\n\t\tconst campaign = await this.campaignService.getCurrent();\n\n\t\tif (!campaign) return { campaignState: LtoCardState.NONE };\n\n\t\tconst participant = await this.repository.findActiveByCampaignAndShop(campaign._id, shopId);\n\n\t\tconst campaignState =\n\t\t\tcampaign.status === LimitedTimeOfferCampaignStatus.SCHEDULED\n\t\t\t\t? LtoCardState.SCHEDULED\n\t\t\t\t: campaign.status === LimitedTimeOfferCampaignStatus.ACTIVE\n\t\t\t\t\t? LtoCardState.LIVE\n\t\t\t\t\t: LtoCardState.NONE;\n\n\t\treturn participant\n\t\t\t? { campaignState, campaign: campaign as any, participant }\n\t\t\t: { campaignState, campaign: campaign as any };\n\t}\n\n\tpublic async update(shopId: mongoose.Types.ObjectId, dto: JoinLtoCampaignDTO) {\n\t\tconst campaign = await this.fetchCurrentCampaignOrThrow();\n\n\t\tconst participant = await this.repository.findActiveByCampaignAndShop(campaign._id, shopId);\n\t\tif (!participant) throw notFoundError('You have not joined this campaign.');\n\n\t\tthis.validateDiscountSelections(campaign, dto.discountPercentage, dto.maxDiscountCap, participant);\n\t\tawait this.assertProductsBelongToShop(shopId, dto);\n\n\t\tconst resolvedDto = await this.resolveCategorySelection(shopId, dto);\n\n\t\tconst newMarketingId = participant.marketingId\n\t\t\t? await this.marketingService.replaceMarketing(participant.marketingId, shopId, campaign, resolvedDto)\n\t\t\t: await this.marketingService.applyMarketing(shopId, campaign, resolvedDto);\n\n\t\treturn this.repository.updateParticipant(campaign._id, shopId, {\n\t\t\tproducts: resolvedDto.products ?? [],\n\t\t\tisEntireMenu: resolvedDto.isEntireMenu,\n\t\t\tdiscountPercentage: resolvedDto.discountPercentage,\n\t\t\tmaxDiscountCap: resolvedDto.maxDiscountCap,\n\t\t\tisOrderCapacityEnabled: resolvedDto.isOrderCapacityEnabled,\n\t\t\tmaxOrderCapacity: resolvedDto.maxOrderCapacity,\n\t\t\tmarketing: newMarketingId,\n\t\t});\n\t}\n\n\tpublic async getParticipants(dto: GetLtoCampaignParticipantsDTO) {\n\t\tconst { documents, total } = await this.repository.findByCampaign(dto);\n\t\treturn {\n\t\t\tdocuments,\n\t\t\tmetadata: {\n\t\t\t\tpage: dto.page,\n\t\t\t\tsize: dto.size,\n\t\t\t\ttotalElements: total,\n\t\t\t\ttotalPages: Math.ceil(total / dto.size),\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic async getParticipantIdsByCampaignId(campaignId: mongoose.Types.ObjectId) {\n\t\treturn await this.repository.findParticipantIdsByCampaignId(campaignId);\n\t}\n\n\tpublic async getNearby(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tinput: { latitude: number; longitude: number }\n\t) {\n\t\tconst settings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\t\tconst nearByShopDistance = settings.nearByShopDistance || 10000;\n\t\treturn this.repository.findNearby(campaignId, input, nearByShopDistance);\n\t}\n\n\tpublic async removeCampaignMarketings(campaignId: mongoose.Types.ObjectId): Promise<void> {\n\t\tawait this.marketingService.removeAllCampaignMarketings(campaignId);\n\t}\n\n\tprivate async fetchCurrentCampaignOrThrow(): Promise<DocumentType<LimitedTimeOfferCampaign>> {\n\t\tconst campaign = await this.campaignService.getCurrent();\n\t\tif (!campaign) {\n\t\t\tthrow badRequestError('No campaign active or scheduled.');\n\t\t}\n\t\treturn campaign;\n\t}\n\n\tprivate async assertNotAlreadyJoined(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tif (await this.repository.existsActiveByCampaignAndShop(campaignId, shopId)) {\n\t\t\tthrow conflictError('Your shop has already joined this campaign.');\n\t\t}\n\t}\n\n\t/**\n\t * Expands the selected shop categories into their product ids and merges them with any explicitly\n\t * selected products. The marketing layer only ever receives a flat product list, so category\n\t * selection is purely an LTO-side convenience that is resolved here before anything is persisted.\n\t */\n\tprivate async resolveCategorySelection(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tdto: JoinLtoCampaignDTO\n\t): Promise<JoinLtoCampaignDTO> {\n\t\tif (dto.isEntireMenu || !dto.shopCategories?.length) return dto;\n\n\t\tconst categoryProductIds = await this.repository.findProductIdsByCategories(shopId, dto.shopCategories);\n\t\tconst products = this.uniqueObjectIds([...(dto.products ?? []), ...categoryProductIds]);\n\n\t\tif (products.length === 0) {\n\t\t\tthrow badRequestError('The selected categories do not contain any products.');\n\t\t}\n\n\t\treturn { ...dto, products };\n\t}\n\n\t/**\n\t * Validates that explicitly selected products belong to the shop. Categories are not checked here:\n\t * {@link resolveCategorySelection} fetches their products with a shop-scoped query, so any category\n\t * that does not belong to the shop simply contributes no products.\n\t */\n\tprivate async assertProductsBelongToShop(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tdto: JoinLtoCampaignDTO\n\t): Promise<void> {\n\t\tif (dto.isEntireMenu) return;\n\n\t\tconst productIds = this.uniqueObjectIds(dto.products ?? []);\n\t\tif (!productIds.length) return;\n\n\t\tconst owned = await this.repository.countShopProducts(shopId, productIds);\n\t\tif (owned !== productIds.length) {\n\t\t\tthrow badRequestError('One or more selected products do not belong to your shop.');\n\t\t}\n\t}\n\n\tprivate uniqueObjectIds(ids: mongoose.Types.ObjectId[]): mongoose.Types.ObjectId[] {\n\t\treturn [...new Map(ids.map(id => [id.toString(), id])).values()];\n\t}\n\n\tprivate validateDiscountSelections(\n\t\tcampaign: DocumentType<LimitedTimeOfferCampaign>,\n\t\tdiscountPercentage: number,\n\t\tmaxDiscountCap: number,\n\t\tparticipant?: ParticipantSummaryDTO\n\t): void {\n\t\tif (!campaign.discountOptions.includes(discountPercentage)) {\n\t\t\tif (!participant || discountPercentage != participant.discountPercentage) {\n\t\t\t\tthrow badRequestError('Selected discount is not an available option for this campaign.');\n\t\t\t}\n\t\t}\n\t\tif (!campaign.maxDiscountCaps.includes(maxDiscountCap)) {\n\t\t\tif (!participant || maxDiscountCap != participant.maxDiscountCap) {\n\t\t\t\tthrow badRequestError('Selected max discount cap is not an available option for this campaign.');\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const ltoParticipantService = Container.get(LimitedTimeOfferParticipantService);\n"]}
@@ -24,7 +24,6 @@ export declare class MarketingService {
24
24
  private expireMarketingsExceedingSpendLimits;
25
25
  private unExpireMarketingsBelowSpendLimits;
26
26
  recomputeAndSyncAllMarketingSpent(): Promise<void>;
27
- private publishEntireMenuSeedEvents;
28
27
  reseedEntireMenuMarketing(marketingId: mongoose.Types.ObjectId): Promise<void>;
29
28
  assignMarketingToProducts(marketing: DocumentType<Buy1Get1Marketing | DiscountMarketing>): Promise<void>;
30
29
  }
@@ -1 +1 @@
1
- {"version":3,"file":"marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EACN,iBAAiB,EACjB,iBAAiB,EAMjB,SAAS,IAAI,KAAK,EAOlB,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;AA4C3D,qBACa,gBAAgB;IAC5B,OAAO,CAAC,KAAK,CAAiD;IAC9D,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,UAAU,CAA2D;IAC7E,OAAO,CAAC,0BAA0B,CAA6B;IAC/D,OAAO,CAAC,gCAAgC,CACM;;IAgBjC,MAAM,CAClB,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AG,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;YA0HjB,uBAAuB;YAkBvB,uBAAuB;IAmBxB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAsC7E,eAAe,CAAC,YAAY,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,UAAU,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC1F,sCAAsC,CAAC,IAAI,EAAE,oCAAoC;IA8BjF,gCAAgC,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAiChF,gCAAgC,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;YAiC/E,oCAAoC;YAgBpC,kCAAkC;IAgBnC,iCAAiC,IAAI,OAAO,CAAC,IAAI,CAAC;IAqClD,yBAAyB,CAAC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAqC9E,yBAAyB,CAAC,SAAS,EAAE,YAAY,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;CA0CrG;AAED,eAAO,MAAM,gBAAgB,kBAAkC,CAAC"}
@@ -55,14 +55,12 @@ const admin_logs_event_1 = require("@lyxa.ai/core/dist/libraries/event/events/ad
55
55
  const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
56
56
  const event_1 = require("@lyxa.ai/core/dist/libraries/event");
57
57
  const marketing_product_seed_event_1 = require("../../../event/events/marketing-product-seed.event");
58
- const marketing_product_sync_event_1 = require("../../../event/events/marketing-product-sync.event");
59
58
  const _1 = require(".");
60
59
  const enum_2 = require("@lyxa.ai/core/dist/utilities/enum");
61
60
  const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
62
61
  const mongo_stream_changes_batch_process_shops_event_1 = require("@lyxa.ai/core/dist/libraries/event/events/mongo-stream-changes-batch-process-shops-event");
63
62
  const MarketingMetricsRepository_1 = require("../patterns/repository/MarketingMetricsRepository");
64
63
  const marketing_product_sync_queue_1 = require("../queues/marketing-product-sync.queue");
65
- const limited_time_offer_participant_service_1 = require("../../limited-time-offer/participant/services/limited-time-offer-participant.service");
66
64
  let MarketingService = class MarketingService {
67
65
  model;
68
66
  shopModel;
@@ -79,16 +77,12 @@ let MarketingService = class MarketingService {
79
77
  }
80
78
  async create(data, admin) {
81
79
  const now = (0, dayjs_1.dayjs)().toDate();
82
- if (data.marketingType === enum_2.MarketingType.DISCOUNT && (await limited_time_offer_participant_service_1.ltoParticipantService.isActiveParticipant(data.shop))) {
83
- (0, error_common_1.forbiddenError)('You are currently participating in a Limited Time Offer. Please manage your discount from the Limited Time Offer section or withdraw first.');
84
- }
85
80
  const existingRecord = await this.model.findOne({
86
81
  shop: data.shop,
87
82
  marketingType: data.marketingType,
88
83
  'duration.end': { $gt: now },
89
84
  status: enum_1.MarketingStatus.ACTIVE,
90
85
  isAppliedByCompany: data.isAppliedByCompany,
91
- campaignType: data.campaignType,
92
86
  });
93
87
  if (existingRecord) {
94
88
  throw new server_1.TRPCError({
@@ -120,17 +114,12 @@ let MarketingService = class MarketingService {
120
114
  message: `Product list contains duplicate products`,
121
115
  });
122
116
  }
123
- if (data.campaignType === enum_1.MarketingCampaignType.LIMITED_TIME_OFFER) {
124
- await _1.productMarketingService.pauseConflictingMarketings(productIds);
125
- }
126
- else {
127
- const isAvailable = await _1.productMarketingService.checkProductMarketingAvailability(productIds, data.isAppliedByCompany);
128
- if (!isAvailable) {
129
- throw new server_1.TRPCError({
130
- code: 'CONFLICT',
131
- message: `Product list contains products which already have marketing applied`,
132
- });
133
- }
117
+ const isAvailable = await _1.productMarketingService.checkProductMarketingAvailability(productIds, data.isAppliedByCompany);
118
+ if (!isAvailable) {
119
+ throw new server_1.TRPCError({
120
+ code: 'CONFLICT',
121
+ message: `Product list contains products which already have marketing applied`,
122
+ });
134
123
  }
135
124
  }
136
125
  if (admin) {
@@ -240,10 +229,6 @@ let MarketingService = class MarketingService {
240
229
  if (data.status &&
241
230
  data.status === enum_1.MarketingStatus.ACTIVE &&
242
231
  oldMarketing.status === enum_1.MarketingStatus.PAUSED) {
243
- if (oldMarketing.marketingType === enum_2.MarketingType.DISCOUNT &&
244
- (await limited_time_offer_participant_service_1.ltoParticipantService.isActiveParticipant(oldMarketing.shop._id))) {
245
- (0, error_common_1.forbiddenError)('You are currently participating in a Limited Time Offer. Please manage your discount from the Limited Time Offer section or withdraw first.');
246
- }
247
232
  await this.verifyUnpauseConditions(_id);
248
233
  }
249
234
  switch (oldMarketing.marketingType) {
@@ -509,34 +494,31 @@ let MarketingService = class MarketingService {
509
494
  await this.expireMarketingsExceedingSpendLimits(marketingIds);
510
495
  await this.unExpireMarketingsBelowSpendLimits(marketingIds);
511
496
  }
512
- async publishEntireMenuSeedEvents(marketing) {
513
- const PAGE_SIZE = 500;
514
- const marketingId = marketing._id.toString();
515
- const shopId = (marketing.shop?._id ?? marketing.shop).toString();
516
- const products = await models_1.ProductModel.find({ shop: marketing.shop }).select('_id').lean();
517
- const productIds = products.map((p) => p._id.toString());
518
- for (let i = 0; i < productIds.length; i += PAGE_SIZE) {
519
- await (0, event_1.publishEvent)(new marketing_product_seed_event_1.MarketingEntireMenuSeedEvent({
520
- marketingId,
521
- shopId,
522
- isAppliedByCompany: marketing.isAppliedByCompany ?? false,
523
- isBuy1Get1: marketing.marketingType === enum_2.MarketingType.BUY1GET1,
524
- value: marketing.value,
525
- valueType: marketing.valueType,
526
- productIds: productIds.slice(i, i + PAGE_SIZE),
527
- }));
528
- }
529
- return productIds.length;
530
- }
531
497
  async reseedEntireMenuMarketing(marketingId) {
532
498
  const logger = (0, core_1.getLibraries)().getLoggerKit();
533
499
  const marketing = await this.model.findOne({ _id: marketingId, deletedAt: null });
534
500
  if (!marketing)
535
501
  (0, error_common_1.internalServerError)('Marketing not found');
536
- const productCount = await this.publishEntireMenuSeedEvents(marketing);
537
- logger.debug(`entire-menu reseed dispatched — ${productCount} products`, {
502
+ const PAGE_SIZE = 500;
503
+ const mid = marketingId.toString();
504
+ const shopId = (marketing.shop?._id ?? marketing.shop).toString();
505
+ const count = await models_1.ProductModel.countDocuments({ shop: marketing.shop });
506
+ const pages = Math.ceil(count / PAGE_SIZE);
507
+ if (!pages)
508
+ return;
509
+ await Promise.all(Array.from({ length: pages }, (_, page) => (0, event_1.publishEvent)(new marketing_product_seed_event_1.MarketingEntireMenuSeedEvent({
510
+ marketingId: mid,
511
+ shopId,
512
+ isAppliedByCompany: marketing.isAppliedByCompany ?? false,
513
+ isBuy1Get1: marketing.marketingType === enum_2.MarketingType.BUY1GET1,
514
+ value: marketing.value,
515
+ valueType: marketing.valueType,
516
+ page,
517
+ pageSize: PAGE_SIZE,
518
+ }))));
519
+ logger.debug(`entire-menu reseed dispatched — ${pages} pages for ${count} products`, {
538
520
  tag: 'marketing.seed.entire-menu',
539
- data: { marketingId: marketingId.toString(), productCount },
521
+ data: { marketingId: mid, shopId, pages, productCount: count },
540
522
  });
541
523
  }
542
524
  async assignMarketingToProducts(marketing) {
@@ -546,27 +528,31 @@ let MarketingService = class MarketingService {
546
528
  }
547
529
  if (marketing.isEntireMenu) {
548
530
  const logger = (0, core_1.getLibraries)().getLoggerKit();
549
- const productCount = await this.publishEntireMenuSeedEvents(marketing);
550
- logger.debug(`entire-menu marketing seed dispatched — ${productCount} products`, {
551
- tag: 'marketing.seed.entire-menu',
552
- data: { marketingId: marketing._id.toString(), productCount },
553
- });
554
- }
555
- else {
556
- const shopId = (marketing.shop?._id ?? marketing.shop).toString();
557
- const pms = await models_1.ProductMarketingModel.find({ marketing: marketing._id, deletedAt: null })
558
- .select('product')
559
- .lean();
560
- const productIds = pms.map((p) => p.product.toString());
561
531
  const PAGE_SIZE = 500;
562
- for (let i = 0; i < productIds.length; i += PAGE_SIZE) {
563
- await (0, event_1.publishEvent)(new marketing_product_sync_event_1.MarketingProductSyncEvent({
564
- marketingId: marketing._id.toString(),
532
+ const marketingId = marketing._id.toString();
533
+ const shopId = (marketing.shop?._id ?? marketing.shop).toString();
534
+ const count = await models_1.ProductModel.countDocuments({ shop: marketing.shop });
535
+ const pages = Math.ceil(count / PAGE_SIZE);
536
+ if (pages > 0) {
537
+ await Promise.all(Array.from({ length: pages }, (_, page) => (0, event_1.publishEvent)(new marketing_product_seed_event_1.MarketingEntireMenuSeedEvent({
538
+ marketingId,
565
539
  shopId,
566
- productIds: productIds.slice(i, i + PAGE_SIZE),
567
- }));
540
+ isAppliedByCompany: marketing.isAppliedByCompany ?? false,
541
+ isBuy1Get1: marketing.marketingType === enum_2.MarketingType.BUY1GET1,
542
+ value: marketing.value,
543
+ valueType: marketing.valueType,
544
+ page,
545
+ pageSize: PAGE_SIZE,
546
+ }))));
547
+ logger.debug(`entire-menu marketing seed dispatched — ${pages} pages for ${count} products`, {
548
+ tag: 'marketing.seed.entire-menu',
549
+ data: { marketingId, shopId, pages, productCount: count },
550
+ });
568
551
  }
569
552
  }
553
+ else {
554
+ await _1.productMarketingService.syncProductMarketingInfo(marketing._id);
555
+ }
570
556
  }
571
557
  };
572
558
  exports.MarketingService = MarketingService;