@lyxa.ai/marketing 1.0.41 → 1.0.43
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.
- package/dist/lib/event/event-initializations.d.ts.map +1 -1
- package/dist/lib/event/event-initializations.js +3 -0
- package/dist/lib/event/event-initializations.js.map +1 -1
- package/dist/lib/event/event-listeners/event-listeners.d.ts +1 -0
- package/dist/lib/event/event-listeners/event-listeners.d.ts.map +1 -1
- package/dist/lib/event/event-listeners/event-listeners.js +52 -0
- package/dist/lib/event/event-listeners/event-listeners.js.map +1 -1
- package/dist/lib/event/events/marketing-product-seed.event.d.ts +17 -0
- package/dist/lib/event/events/marketing-product-seed.event.d.ts.map +1 -0
- package/dist/lib/event/events/marketing-product-seed.event.js +12 -0
- package/dist/lib/event/events/marketing-product-seed.event.js.map +1 -0
- package/dist/lib/index.d.ts +730 -5
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +6 -6
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts +116 -0
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js +33 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.d.ts +1 -0
- package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.js +61 -40
- package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/helper.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/helper.service.js +11 -6
- package/dist/lib/modules/coupon/services/helper.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts +32 -0
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -0
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js +503 -0
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js.map +1 -0
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +108 -149
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.js +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js +5 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +407 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js +39 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
- package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts +1118 -0
- package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -0
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js +13 -0
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js.map +1 -0
- package/dist/lib/modules/coupon/validations/index.d.ts +1 -0
- package/dist/lib/modules/coupon/validations/index.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/index.js +1 -0
- package/dist/lib/modules/coupon/validations/index.js.map +1 -1
- package/dist/lib/modules/deal-setting/routers/deal-setting.router.d.ts.map +1 -1
- package/dist/lib/modules/featured-setting/routers/featured-setting.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts +296 -0
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js +64 -0
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.d.ts +4 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js +24 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.producer.d.ts +12 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.producer.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.producer.js +29 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.producer.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +8 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js +79 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +36 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js +48 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +22 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js +131 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +851 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js +100 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +10 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js +70 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +9 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js +42 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +43 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js +185 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.builder.d.ts +8 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.builder.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.builder.js +13 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.builder.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.repository.d.ts +14 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.repository.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.repository.js +77 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.repository.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts +11 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.js +87 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.validation.d.ts +189 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.validation.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.validation.js +24 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.validation.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer.router.d.ts +122 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer.router.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer.router.js +37 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer.router.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +601 -0
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.js +13 -0
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +53 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js +55 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +18 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js +126 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +170 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js +50 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js +2 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +603 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js +85 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +14 -0
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js +73 -0
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +32 -0
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js +125 -0
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js.map +1 -0
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts +2 -1
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -1
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js +23 -15
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts +12 -3
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.js +7 -0
- package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.d.ts +0 -2
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js +20 -39
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/discount-marketing.service.d.ts +0 -3
- package/dist/lib/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/discount-marketing.service.js +28 -52
- package/dist/lib/modules/marketing/services/discount-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.d.ts +2 -0
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +111 -31
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +20 -2
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.js +155 -7
- package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js +36 -55
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +3 -0
- package/dist/lib/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts.map +1 -1
- package/dist/lib/modules/marketing/transformers/discount-marketing.transformer.d.ts +3 -0
- package/dist/lib/modules/marketing/transformers/discount-marketing.transformer.d.ts.map +1 -1
- package/dist/lib/modules/marketing/transformers/product-marketing.transformer.d.ts +1 -0
- package/dist/lib/modules/marketing/transformers/product-marketing.transformer.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +30 -0
- package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts +45 -9
- package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.d.ts +2 -2
- package/dist/lib/modules/marketing/validations/product-marketing.validation.d.ts +77 -0
- package/dist/lib/modules/marketing/validations/product-marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/product-marketing.validation.js +20 -1
- package/dist/lib/modules/marketing/validations/product-marketing.validation.js.map +1 -1
- package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +2 -2
- package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts.map +1 -1
- package/dist/lib/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +4 -4
- package/dist/types/event/event-initializations.d.ts.map +1 -1
- package/dist/types/event/event-listeners/event-listeners.d.ts +1 -0
- package/dist/types/event/event-listeners/event-listeners.d.ts.map +1 -1
- package/dist/types/event/events/marketing-product-seed.event.d.ts +17 -0
- package/dist/types/event/events/marketing-product-seed.event.d.ts.map +1 -0
- package/dist/types/index.d.ts +730 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts +116 -0
- package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/coupon.service.d.ts +1 -0
- package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/helper.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts +32 -0
- package/dist/types/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -0
- package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts +407 -1
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts +1118 -0
- package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -0
- package/dist/types/modules/coupon/validations/index.d.ts +1 -0
- package/dist/types/modules/coupon/validations/index.d.ts.map +1 -1
- package/dist/types/modules/deal-setting/routers/deal-setting.router.d.ts.map +1 -1
- package/dist/types/modules/featured-setting/routers/featured-setting.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts +296 -0
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/jobs/index.d.ts +4 -0
- package/dist/types/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.producer.d.ts +12 -0
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.producer.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +8 -0
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +36 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +22 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +851 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +10 -0
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +9 -0
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +43 -0
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.builder.d.ts +8 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.builder.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.repository.d.ts +14 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.repository.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts +11 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.validation.d.ts +189 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.validation.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer.router.d.ts +122 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer.router.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +601 -0
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +53 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +18 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +170 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts +1 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +603 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +14 -0
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +32 -0
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -0
- package/dist/types/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts +2 -1
- package/dist/types/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -1
- package/dist/types/modules/marketing/routers/marketing.router.d.ts +12 -3
- package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/buy1-get1-marketing.service.d.ts +0 -2
- package/dist/types/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/discount-marketing.service.d.ts +0 -3
- package/dist/types/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/marketing.service.d.ts +2 -0
- package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts +24 -2
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +3 -0
- package/dist/types/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts.map +1 -1
- package/dist/types/modules/marketing/transformers/discount-marketing.transformer.d.ts +3 -0
- package/dist/types/modules/marketing/transformers/discount-marketing.transformer.d.ts.map +1 -1
- package/dist/types/modules/marketing/transformers/product-marketing.transformer.d.ts +1 -0
- package/dist/types/modules/marketing/transformers/product-marketing.transformer.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +30 -0
- package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts +45 -9
- package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/marketing.validation.d.ts +2 -2
- package/dist/types/modules/marketing/validations/product-marketing.validation.d.ts +77 -0
- package/dist/types/modules/marketing/validations/product-marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +2 -2
- package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts.map +1 -1
- package/dist/types/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +4 -4
- package/package.json +3 -3
- package/dist/lib/events/event-initializations.d.ts +0 -2
- package/dist/lib/events/event-initializations.d.ts.map +0 -1
- package/dist/lib/events/event-initializations.js +0 -5
- package/dist/lib/events/event-initializations.js.map +0 -1
- package/dist/types/events/event-initializations.d.ts +0 -2
- package/dist/types/events/event-initializations.d.ts.map +0 -1
|
@@ -46,12 +46,15 @@ exports.marketingService = exports.MarketingService = void 0;
|
|
|
46
46
|
const typedi_1 = __importStar(require("typedi"));
|
|
47
47
|
const server_1 = require("@trpc/server");
|
|
48
48
|
const dayjs_1 = require("@lyxa.ai/core/dist/utilities/dayjs");
|
|
49
|
+
const core_1 = require("@lyxa.ai/core");
|
|
50
|
+
const typegoose_1 = require("@typegoose/typegoose");
|
|
49
51
|
const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models");
|
|
50
52
|
const pagination_1 = require("@lyxa.ai/core/dist/utilities/pagination");
|
|
51
53
|
const events_common_methods_1 = require("@lyxa.ai/core/dist/utilities/events-common-methods");
|
|
52
54
|
const admin_logs_event_1 = require("@lyxa.ai/core/dist/libraries/event/events/admin-logs-event");
|
|
53
55
|
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
54
56
|
const event_1 = require("@lyxa.ai/core/dist/libraries/event");
|
|
57
|
+
const marketing_product_seed_event_1 = require("../../../event/events/marketing-product-seed.event");
|
|
55
58
|
const _1 = require(".");
|
|
56
59
|
const enum_2 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
57
60
|
const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
|
|
@@ -75,6 +78,7 @@ let MarketingService = class MarketingService {
|
|
|
75
78
|
marketingType: data.marketingType,
|
|
76
79
|
'duration.end': { $gt: now },
|
|
77
80
|
status: enum_1.MarketingStatus.ACTIVE,
|
|
81
|
+
isAppliedByCompany: data.isAppliedByCompany,
|
|
78
82
|
});
|
|
79
83
|
if (existingRecord) {
|
|
80
84
|
throw new server_1.TRPCError({
|
|
@@ -88,7 +92,7 @@ let MarketingService = class MarketingService {
|
|
|
88
92
|
'duration.start': { $lt: now },
|
|
89
93
|
'duration.end': { $gt: now },
|
|
90
94
|
status: enum_1.MarketingStatus.ACTIVE,
|
|
91
|
-
marketingType: { $in: [enum_2.MarketingType.BUY1GET1, enum_2.MarketingType.DISCOUNT] },
|
|
95
|
+
marketingType: { $in: [enum_2.MarketingType.BUY1GET1, enum_2.MarketingType.DISCOUNT], $ne: data.marketingType },
|
|
92
96
|
});
|
|
93
97
|
if (existingMarketing) {
|
|
94
98
|
throw new server_1.TRPCError({
|
|
@@ -106,7 +110,7 @@ let MarketingService = class MarketingService {
|
|
|
106
110
|
message: `Product list contains duplicate products`,
|
|
107
111
|
});
|
|
108
112
|
}
|
|
109
|
-
const isAvailable = await _1.productMarketingService.checkProductMarketingAvailability(productIds);
|
|
113
|
+
const isAvailable = await _1.productMarketingService.checkProductMarketingAvailability(productIds, data.isAppliedByCompany);
|
|
110
114
|
if (!isAvailable) {
|
|
111
115
|
throw new server_1.TRPCError({
|
|
112
116
|
code: 'CONFLICT',
|
|
@@ -149,6 +153,33 @@ let MarketingService = class MarketingService {
|
|
|
149
153
|
marketing = await this.model.create(data, admin);
|
|
150
154
|
}
|
|
151
155
|
}
|
|
156
|
+
if (data.isEntireMenu) {
|
|
157
|
+
const logger = (0, core_1.getLibraries)().getLoggerKit();
|
|
158
|
+
const PAGE_SIZE = 500;
|
|
159
|
+
const marketingId = marketing._id.toString();
|
|
160
|
+
const shopId = data.shop.toString();
|
|
161
|
+
const count = await models_1.ProductModel.countDocuments({ shop: data.shop });
|
|
162
|
+
const pages = Math.ceil(count / PAGE_SIZE);
|
|
163
|
+
if (pages > 0) {
|
|
164
|
+
await Promise.all(Array.from({ length: pages }, (_, page) => (0, event_1.publishEvent)(new marketing_product_seed_event_1.MarketingEntireMenuSeedEvent({
|
|
165
|
+
marketingId,
|
|
166
|
+
shopId,
|
|
167
|
+
isAppliedByCompany: data.isAppliedByCompany ?? false,
|
|
168
|
+
isBuy1Get1: data.marketingType === enum_2.MarketingType.BUY1GET1,
|
|
169
|
+
value: data.value,
|
|
170
|
+
valueType: data.valueType,
|
|
171
|
+
page,
|
|
172
|
+
pageSize: PAGE_SIZE,
|
|
173
|
+
}))));
|
|
174
|
+
logger.debug(`entire-menu marketing seed dispatched — ${pages} pages for ${count} products`, {
|
|
175
|
+
tag: 'marketing.seed.entire-menu',
|
|
176
|
+
data: { marketingId, shopId, pages, productCount: count },
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
await _1.productMarketingService.syncProductMarketingInfo(marketing._id);
|
|
182
|
+
}
|
|
152
183
|
await this.model.populate(marketing, {
|
|
153
184
|
path: 'shop',
|
|
154
185
|
model: this.shopModel,
|
|
@@ -157,7 +188,7 @@ let MarketingService = class MarketingService {
|
|
|
157
188
|
if (admin) {
|
|
158
189
|
this.logMarketingAdminAction(admin, enum_1.AdminLogsUpdatedFieldsType.ACTIVATED_MARKETING_PROMOTIONS, '', marketing);
|
|
159
190
|
}
|
|
160
|
-
if (marketing)
|
|
191
|
+
if (marketing && !data.isEntireMenu)
|
|
161
192
|
(0, events_common_methods_1.publishSyncSingleShopSectionsInCacheProcessEvent)({
|
|
162
193
|
shopId: data.shop,
|
|
163
194
|
operation: mongo_stream_changes_batch_process_shops_event_1.ChangeStreamOperationTypes.UPDATE,
|
|
@@ -271,9 +302,7 @@ let MarketingService = class MarketingService {
|
|
|
271
302
|
}
|
|
272
303
|
this.logMarketingAdminAction(admin, enum_1.AdminLogsUpdatedFieldsType.EDITED_MARKETING_PROMOTIONS, oldMarketing, marketing);
|
|
273
304
|
}
|
|
274
|
-
|
|
275
|
-
await _1.productMarketingService.syncProductMarketingInfo(_id);
|
|
276
|
-
}
|
|
305
|
+
await _1.productMarketingService.syncProductMarketingInfo(_id);
|
|
277
306
|
(0, events_common_methods_1.publishSyncSingleShopSectionsInCacheProcessEvent)({
|
|
278
307
|
shopId: marketing.shop,
|
|
279
308
|
operation: mongo_stream_changes_batch_process_shops_event_1.ChangeStreamOperationTypes.UPDATE,
|
|
@@ -287,7 +316,7 @@ let MarketingService = class MarketingService {
|
|
|
287
316
|
if ([enum_2.MarketingType.BUY1GET1, enum_2.MarketingType.DISCOUNT].includes(marketing.marketingType)) {
|
|
288
317
|
const typedMarketing = marketing;
|
|
289
318
|
const productIds = typedMarketing.products.map((product) => product.product);
|
|
290
|
-
const isAvailable = await _1.productMarketingService.checkProductMarketingAvailability(productIds);
|
|
319
|
+
const isAvailable = await _1.productMarketingService.checkProductMarketingAvailability(productIds, marketing.isAppliedByCompany);
|
|
291
320
|
if (!isAvailable) {
|
|
292
321
|
(0, error_common_1.conflictError)("You can't activate discount and B1G1 on the same items at the same time");
|
|
293
322
|
}
|
|
@@ -333,6 +362,32 @@ let MarketingService = class MarketingService {
|
|
|
333
362
|
});
|
|
334
363
|
return 'Record deleted successfully';
|
|
335
364
|
}
|
|
365
|
+
async deleteManyByIds(marketingIds, softDelete = true) {
|
|
366
|
+
if (marketingIds.length === 0)
|
|
367
|
+
return;
|
|
368
|
+
const marketings = await this.model
|
|
369
|
+
.find({ _id: { $in: marketingIds } })
|
|
370
|
+
.select('shop')
|
|
371
|
+
.lean();
|
|
372
|
+
await this.model.updateMany({ _id: { $in: marketingIds } }, { $set: { status: enum_1.MarketingStatus.DELETED } });
|
|
373
|
+
await this.model.deleteRecords({ _id: { $in: marketingIds } }, softDelete);
|
|
374
|
+
await _1.productMarketingService.deleteManyByMarketingIds(marketingIds, softDelete);
|
|
375
|
+
const uniqueShopIds = [
|
|
376
|
+
...new Map(marketings
|
|
377
|
+
.map((m) => m.shop)
|
|
378
|
+
.filter(Boolean)
|
|
379
|
+
.map((s) => {
|
|
380
|
+
const id = s instanceof typegoose_1.mongoose.Types.ObjectId ? s : new typegoose_1.mongoose.Types.ObjectId(s);
|
|
381
|
+
return [id.toString(), id];
|
|
382
|
+
})).values(),
|
|
383
|
+
];
|
|
384
|
+
for (const shopId of uniqueShopIds) {
|
|
385
|
+
(0, events_common_methods_1.publishSyncSingleShopSectionsInCacheProcessEvent)({
|
|
386
|
+
shopId,
|
|
387
|
+
operation: mongo_stream_changes_batch_process_shops_event_1.ChangeStreamOperationTypes.DELETE,
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
336
391
|
async handleNewProductForEntireMenuMarketing(data) {
|
|
337
392
|
const existingMarketing = await this.model.findOne({
|
|
338
393
|
shop: data.shop,
|
|
@@ -342,29 +397,29 @@ let MarketingService = class MarketingService {
|
|
|
342
397
|
isEntireMenu: true,
|
|
343
398
|
});
|
|
344
399
|
if (existingMarketing) {
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
productMarketingData.value = existingMarketing.value;
|
|
356
|
-
productMarketingData.valueType = existingMarketing.valueType;
|
|
357
|
-
}
|
|
358
|
-
const result = await _1.productMarketingService.create(productMarketingData);
|
|
359
|
-
console.log(`Created product marketing: ${result}`);
|
|
400
|
+
const productMarketingData = {
|
|
401
|
+
product: data.product,
|
|
402
|
+
marketing: existingMarketing._id,
|
|
403
|
+
};
|
|
404
|
+
if (existingMarketing.marketingType == enum_2.MarketingType.BUY1GET1) {
|
|
405
|
+
productMarketingData.isBuy1Get1 = true;
|
|
406
|
+
}
|
|
407
|
+
if (existingMarketing.marketingType == enum_2.MarketingType.DISCOUNT) {
|
|
408
|
+
productMarketingData.value = existingMarketing.value;
|
|
409
|
+
productMarketingData.valueType = existingMarketing.valueType;
|
|
360
410
|
}
|
|
411
|
+
await _1.productMarketingService.create(productMarketingData);
|
|
412
|
+
await _1.synchronizeProductMarketingService.syncProductMarketingInfoByProductId(data.product);
|
|
361
413
|
}
|
|
362
414
|
return 'Product handled successfully';
|
|
363
415
|
}
|
|
364
416
|
async incrementMarketingSpentFromOrder(orderId) {
|
|
365
417
|
const order = (await this.orderModel
|
|
366
418
|
.findById(orderId)
|
|
367
|
-
.populate(
|
|
419
|
+
.populate([
|
|
420
|
+
{ path: 'lineItems' },
|
|
421
|
+
{ path: 'marketings', select: 'isAppliedByCompany' },
|
|
422
|
+
]));
|
|
368
423
|
if (!order || !order.marketings?.length) {
|
|
369
424
|
return;
|
|
370
425
|
}
|
|
@@ -384,7 +439,10 @@ let MarketingService = class MarketingService {
|
|
|
384
439
|
async decrementMarketingSpentFromOrder(orderId) {
|
|
385
440
|
const order = (await this.orderModel
|
|
386
441
|
.findById(orderId)
|
|
387
|
-
.populate(
|
|
442
|
+
.populate([
|
|
443
|
+
{ path: 'lineItems' },
|
|
444
|
+
{ path: 'marketings', select: 'isAppliedByCompany' },
|
|
445
|
+
]));
|
|
388
446
|
if (!order || !order.marketings?.length) {
|
|
389
447
|
return;
|
|
390
448
|
}
|
|
@@ -407,7 +465,7 @@ let MarketingService = class MarketingService {
|
|
|
407
465
|
isSpendLimitEnabled: true,
|
|
408
466
|
status: { $ne: enum_1.MarketingStatus.EXPIRED },
|
|
409
467
|
$expr: { $gte: ['$amountSpent', '$spendLimit'] },
|
|
410
|
-
}, { $set: { status: enum_1.MarketingStatus.EXPIRED } });
|
|
468
|
+
}, { $set: { status: enum_1.MarketingStatus.EXPIRED, expiredAt: (0, dayjs_1.dayjs)().toDate() } });
|
|
411
469
|
}
|
|
412
470
|
async unExpireMarketingsBelowSpendLimits(marketingIds) {
|
|
413
471
|
await this.model.updateMany({
|
|
@@ -415,10 +473,9 @@ let MarketingService = class MarketingService {
|
|
|
415
473
|
isSpendLimitEnabled: true,
|
|
416
474
|
status: enum_1.MarketingStatus.EXPIRED,
|
|
417
475
|
$expr: { $lt: ['$amountSpent', '$spendLimit'] },
|
|
418
|
-
}, { $set: { status: enum_1.MarketingStatus.ACTIVE } });
|
|
476
|
+
}, { $set: { status: enum_1.MarketingStatus.ACTIVE }, $unset: { expiredAt: 1 } });
|
|
419
477
|
}
|
|
420
478
|
async recomputeAndSyncAllMarketingSpent() {
|
|
421
|
-
console.time('Recomputing all marketing spend');
|
|
422
479
|
const cursor = this.model
|
|
423
480
|
.find({ marketingType: { $ne: enum_2.MarketingType.FEATURED } }, { _id: 1 })
|
|
424
481
|
.lean()
|
|
@@ -426,7 +483,6 @@ let MarketingService = class MarketingService {
|
|
|
426
483
|
const bulkOps = [];
|
|
427
484
|
const marketingIds = [];
|
|
428
485
|
for await (const marketing of cursor) {
|
|
429
|
-
console.log(`Recomputing marketing spend for marketing ID: ${marketing._id}`);
|
|
430
486
|
const { amount } = await this.marketingMetricsRepository.calculateMarketingSpent(marketing._id);
|
|
431
487
|
bulkOps.push({
|
|
432
488
|
updateOne: {
|
|
@@ -438,18 +494,42 @@ let MarketingService = class MarketingService {
|
|
|
438
494
|
});
|
|
439
495
|
marketingIds.push(marketing._id);
|
|
440
496
|
if (bulkOps.length >= 500) {
|
|
441
|
-
console.log(`Flushing 500 marketing spend updates...`);
|
|
442
497
|
await this.model.bulkWrite(bulkOps);
|
|
443
498
|
bulkOps.length = 0;
|
|
444
499
|
}
|
|
445
500
|
}
|
|
446
501
|
if (bulkOps.length) {
|
|
447
|
-
console.log(`Flushing remaining ${bulkOps.length} marketing spend updates...`);
|
|
448
502
|
await this.model.bulkWrite(bulkOps);
|
|
449
503
|
}
|
|
450
504
|
await this.expireMarketingsExceedingSpendLimits(marketingIds);
|
|
451
505
|
await this.unExpireMarketingsBelowSpendLimits(marketingIds);
|
|
452
|
-
|
|
506
|
+
}
|
|
507
|
+
async reseedEntireMenuMarketing(marketingId) {
|
|
508
|
+
const logger = (0, core_1.getLibraries)().getLoggerKit();
|
|
509
|
+
const marketing = await this.model.findOne({ _id: marketingId, deletedAt: null });
|
|
510
|
+
if (!marketing)
|
|
511
|
+
(0, error_common_1.internalServerError)('Marketing not found');
|
|
512
|
+
const PAGE_SIZE = 500;
|
|
513
|
+
const mid = marketingId.toString();
|
|
514
|
+
const shopId = marketing.shop.toString();
|
|
515
|
+
const count = await models_1.ProductModel.countDocuments({ shop: marketing.shop });
|
|
516
|
+
const pages = Math.ceil(count / PAGE_SIZE);
|
|
517
|
+
if (!pages)
|
|
518
|
+
return;
|
|
519
|
+
await Promise.all(Array.from({ length: pages }, (_, page) => (0, event_1.publishEvent)(new marketing_product_seed_event_1.MarketingEntireMenuSeedEvent({
|
|
520
|
+
marketingId: mid,
|
|
521
|
+
shopId,
|
|
522
|
+
isAppliedByCompany: marketing.isAppliedByCompany ?? false,
|
|
523
|
+
isBuy1Get1: marketing.marketingType === enum_2.MarketingType.BUY1GET1,
|
|
524
|
+
value: marketing.value,
|
|
525
|
+
valueType: marketing.valueType,
|
|
526
|
+
page,
|
|
527
|
+
pageSize: PAGE_SIZE,
|
|
528
|
+
}))));
|
|
529
|
+
logger.debug(`entire-menu reseed dispatched — ${pages} pages for ${count} products`, {
|
|
530
|
+
tag: 'marketing.seed.entire-menu',
|
|
531
|
+
data: { marketingId: mid, shopId, pages, productCount: count },
|
|
532
|
+
});
|
|
453
533
|
}
|
|
454
534
|
};
|
|
455
535
|
exports.MarketingService = MarketingService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,8DAA2D;AAE3D,sEAUmD;AAenD,wEAA6G;AAE7G,8FAI4D;AAC5D,iGAAoG;AACpG,4DAI2C;AAC3C,8DAAkE;AAElE,wBAOW;AACX,4DAAkE;AAClE,4EAKmD;AACnD,6JAAsI;AACtI,kGAG2D;AAGpD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACpB,KAAK,CAAiD;IACtD,SAAS,CAA2C;IACpD,UAAU,CAA2D;IACrE,0BAA0B,CAA6B;IAE/D;QACC,IAAI,CAAC,KAAK,GAAG,uBAAgE,CAAC;QAC9E,IAAI,CAAC,SAAS,GAAG,kBAAqD,CAAC;QACvE,IAAI,CAAC,UAAU,GAAG,0BAA6E,CAAC;QAChG,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,EAAE,CAAC;gBAC3B,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;gBACvD,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBACpC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;YACpB,CAAC;QACF,CAAC;QAGD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,sBAAsB,OAAO,CAAC,MAAM,6BAA6B,CAAC,CAAC;YAC/E,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;QAGD,MAAM,IAAI,CAAC,oCAAoC,CAAC,YAAY,CAAC,CAAC;QAC9D,MAAM,IAAI,CAAC,kCAAkC,CAAC,YAAY,CAAC,CAAC;QAE5D,OAAO,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;IACpD,CAAC;CACD,CAAA;AA1hBY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,gBAAO,GAAE;;GACG,gBAAgB,CA0hB5B;AAEY,QAAA,gBAAgB,GAAG,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport {\n\tBuy1Get1Marketing,\n\tDiscountMarketing,\n\tLineItem,\n\tMarketingModel,\n\tMarketing as Model,\n\tRegularOrder,\n\tRegularOrderModel,\n\tShop,\n\tShopModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tAllMarketingsDTO,\n\tAllMarketingsValidationDTO,\n\tCreateProductMarketingDTO,\n\tProductEntireMenuMarketingHandlerDTO,\n\tUpdateMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport {\n\tFilterDTO,\n\tPaginatedResponse,\n\tDeleteDTO,\n\tGetByIdInputDTO,\n} from '@lyxa.ai/core/dist/utilities/validation';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport {\n\tfilterRelevantChanges,\n\tgetChangedFields,\n\tpublishSyncSingleShopSectionsInCacheProcessEvent,\n} from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport {\n\tAdminLogsUpdatedFieldsType,\n\tMarketingStatus,\n\tRegularOrderStatus,\n} from '@lyxa.ai/core/dist/utilities/enum';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\nimport {\n\tbuy1Get1MarketingService,\n\tdiscountMarketingService,\n\tfeaturedMarketingService,\n\tfreeDeliveryMarketingService,\n\tproductMarketingService,\n\tpunchMarketingService,\n} from '.';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tconflictError,\n\tinternalServerError,\n\tnotFoundError,\n\tunauthorizedError,\n} from '@lyxa.ai/core/dist/utilities/error-common';\nimport { ChangeStreamOperationTypes } from '@lyxa.ai/core/dist/libraries/event/events/mongo-stream-changes-batch-process-shops-event';\nimport {\n\tMarketingMetricsRepository,\n\tmarketingMetricsRepository,\n} from '../patterns/repository/MarketingMetricsRepository';\n\n@Service()\nexport class MarketingService {\n\tprivate model: typeof MarketingModel & SoftDeleteModel<Model>;\n\tprivate shopModel: typeof ShopModel & SoftDeleteModel<Shop>;\n\tprivate orderModel: typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\tprivate marketingMetricsRepository: MarketingMetricsRepository;\n\n\tconstructor() {\n\t\tthis.model = MarketingModel as typeof MarketingModel & SoftDeleteModel<Model>;\n\t\tthis.shopModel = ShopModel as typeof ShopModel & SoftDeleteModel<Shop>;\n\t\tthis.orderModel = RegularOrderModel as typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\t\tthis.marketingMetricsRepository = marketingMetricsRepository;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(\n\t\tdata: AllMarketingsValidationDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tconst now = dayjs().toDate();\n\n\t\tconst existingRecord = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: data.marketingType,\n\t\t\t'duration.end': { $gt: now },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t});\n\n\t\tif (existingRecord) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `This shop already has a ${data.marketingType} marketing`,\n\t\t\t});\n\t\t}\n\n\t\tif (data.isEntireMenu) {\n\t\t\tconst existingMarketing = await this.model.findOne({\n\t\t\t\tshop: data.shop,\n\t\t\t\t'duration.start': { $lt: now },\n\t\t\t\t'duration.end': { $gt: now },\n\t\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\t\tmarketingType: { $in: [MarketingType.BUY1GET1, MarketingType.DISCOUNT] },\n\t\t\t});\n\n\t\t\tif (existingMarketing) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Cannot create marketing for entire menu while another product based marketing exists for the shop`,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (data.products && data.products.length > 0) {\n\t\t\tconst productIds = data.products.map((product: CreateProductMarketingDTO) => product.product);\n\n\t\t\tconst hasDuplicates = new Set(productIds.map(String)).size !== productIds.length;\n\n\t\t\tif (hasDuplicates) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'BAD_REQUEST',\n\t\t\t\t\tmessage: `Product list contains duplicate products`,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability(productIds);\n\n\t\t\tif (!isAvailable) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Product list contains products which already have marketing applied`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (admin) {\n\t\t\tdata.admin = admin;\n\t\t}\n\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tswitch (data.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: 'UNAUTHORIZED',\n\t\t\t\t\t\tmessage: `Only admin is allowed to create ${data.marketingType} marketing`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.create(data, admin);\n\t\t\t}\n\t\t}\n\n\t\tawait this.model.populate(marketing, {\n\t\t\tpath: 'shop',\n\t\t\tmodel: this.shopModel,\n\t\t\tselect: '_id name shopId',\n\t\t});\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.ACTIVATED_MARKETING_PROMOTIONS,\n\t\t\t\t'',\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\t\tif (marketing)\n\t\t\tpublishSyncSingleShopSectionsInCacheProcessEvent({\n\t\t\t\tshopId: data.shop,\n\t\t\t\toperation: ChangeStreamOperationTypes.UPDATE,\n\t\t\t});\n\t\treturn marketing;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(data: GetByIdInputDTO): Promise<DocumentType<Model>> {\n\t\tconst select = data.select || '';\n\t\tconst populate = data.populate || [];\n\t\tconst result = await this.model\n\t\t\t.findOne({\n\t\t\t\t_id: data._id,\n\t\t\t})\n\t\t\t.select(select)\n\t\t\t.populate(populate);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(\n\t\t_id: mongoose.Types.ObjectId,\n\t\tdata: UpdateDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tconst oldMarketing = await this.model.findById(_id).populate({\n\t\t\tpath: 'shop',\n\t\t\tselect: '_id name shopId',\n\t\t});\n\n\t\tif (!oldMarketing) {\n\t\t\tnotFoundError('Could not find marketing');\n\t\t}\n\n\t\tif (\n\t\t\tdata.status &&\n\t\t\tdata.status === MarketingStatus.ACTIVE &&\n\t\t\toldMarketing.status === MarketingStatus.PAUSED\n\t\t) {\n\t\t\tawait this.verifyUnpauseConditions(_id);\n\t\t}\n\n\t\tswitch (oldMarketing.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tunauthorizedError(`Only admin is allowed to update ${data.marketingType} marketing`);\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model\n\t\t\t\t\t.findOneAndUpdate(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_id: _id,\n\t\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tnew: true,\n\t\t\t\t\t\t\trunValidators: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t\t.populate({\n\t\t\t\t\t\tpath: 'shop',\n\t\t\t\t\t\tselect: '_id name shopId',\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (!marketing) {\n\t\t\tinternalServerError('Could not update marketing');\n\t\t}\n\n\t\tif (admin) {\n\t\t\tconst allChanges = getChangedFields(oldMarketing, marketing);\n\t\t\tconst relevantChanges = filterRelevantChanges(allChanges, data);\n\n\t\t\tif (Object.keys(relevantChanges).includes('status')) {\n\t\t\t\tif (data.status == MarketingStatus.ACTIVE) {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.CONTINUED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t} else if (data.status == MarketingStatus.PAUSED) {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.PAUSED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.EDITED_MARKETING_PROMOTIONS,\n\t\t\t\toldMarketing,\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\tif (data.status) {\n\t\t\tawait productMarketingService.syncProductMarketingInfo(_id);\n\t\t}\n\n\t\tpublishSyncSingleShopSectionsInCacheProcessEvent({\n\t\t\tshopId: marketing.shop,\n\t\t\toperation: ChangeStreamOperationTypes.UPDATE,\n\t\t});\n\n\t\treturn marketing;\n\t}\n\n\tprivate async verifyUnpauseConditions(marketingId: mongoose.Types.ObjectId): Promise<void> {\n\t\tconst marketing = await this.model.findOne({ _id: marketingId, deletedAt: null }).populate('products');\n\t\tif (!marketing) return;\n\n\t\tif ([MarketingType.BUY1GET1, MarketingType.DISCOUNT].includes(marketing.marketingType)) {\n\t\t\tconst typedMarketing = marketing as DocumentType<DiscountMarketing | Buy1Get1Marketing>;\n\t\t\tconst productIds = typedMarketing.products.map((product: any) => product.product);\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability(productIds);\n\n\t\t\tif (!isAvailable) {\n\t\t\t\tconflictError(\"You can't activate discount and B1G1 on the same items at the same time\");\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async logMarketingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: mongoose.Types.ObjectId): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tconst record = await this.model.findById(_id).populate({\n\t\t\tpath: 'shop',\n\t\t\tselect: '_id name shopId',\n\t\t});\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\n\t\trecord.status = MarketingStatus.DELETED;\n\t\tawait record.save();\n\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete marketing',\n\t\t\t});\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(admin, AdminLogsUpdatedFieldsType.DELETED_MARKETING_PROMOTIONS, record);\n\t\t}\n\n\t\tproductMarketingService.deleteMany({ marketing: data._id }, data.softDelete);\n\t\tpublishSyncSingleShopSectionsInCacheProcessEvent({\n\t\t\tshopId: record.shop._id,\n\t\t\toperation: ChangeStreamOperationTypes.DELETE,\n\t\t});\n\t\treturn 'Record deleted successfully';\n\t}\n\n\tpublic async handleNewProductForEntireMenuMarketing(data: ProductEntireMenuMarketingHandlerDTO) {\n\t\tconst existingMarketing = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: { $in: [MarketingType.BUY1GET1, MarketingType.DISCOUNT] },\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\tisEntireMenu: true,\n\t\t});\n\n\t\t// check if existing marketing\n\t\tif (existingMarketing) {\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability([data.product]);\n\t\t\tif (isAvailable) {\n\t\t\t\tconst productMarketingData: CreateProductMarketingDTO = {\n\t\t\t\t\tproduct: data.product,\n\t\t\t\t\tmarketing: existingMarketing._id,\n\t\t\t\t};\n\t\t\t\tif (existingMarketing.marketingType == MarketingType.BUY1GET1) {\n\t\t\t\t\tproductMarketingData.isBuy1Get1 = true;\n\t\t\t\t}\n\t\t\t\tif (existingMarketing.marketingType == MarketingType.DISCOUNT) {\n\t\t\t\t\tproductMarketingData.value = (existingMarketing as DocumentType<DiscountMarketing>).value;\n\t\t\t\t\tproductMarketingData.valueType = (existingMarketing as DocumentType<DiscountMarketing>).valueType;\n\t\t\t\t}\n\t\t\t\tconst result = await productMarketingService.create(productMarketingData);\n\n\t\t\t\tconsole.log(`Created product marketing: ${result}`);\n\t\t\t}\n\t\t}\n\n\t\treturn 'Product handled successfully';\n\t}\n\n\tpublic async incrementMarketingSpentFromOrder(orderId: mongoose.Types.ObjectId): Promise<any> {\n\t\tconst order = (await this.orderModel\n\t\t\t.findById(orderId)\n\t\t\t.populate('lineItems')) as DocumentType<RegularOrder> & { lineItems: DocumentType<LineItem>[] };\n\n\t\tif (!order || !order.marketings?.length) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst marketingSpendMap = this.marketingMetricsRepository.calculateMarketingSpendPerOrder(order);\n\n\t\tconst bulkOps = [...marketingSpendMap.entries()].map(([marketingId, amountSpent]) => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { _id: marketingId },\n\t\t\t\tupdate: { $inc: { amountSpent } },\n\t\t\t},\n\t\t}));\n\n\t\tif (bulkOps.length) {\n\t\t\tawait this.model.bulkWrite(bulkOps);\n\t\t}\n\n\t\tawait this.expireMarketingsExceedingSpendLimits(Array.from(marketingSpendMap.keys()));\n\n\t\treturn 'Marketing amount spent incremented successfully';\n\t}\n\n\tpublic async decrementMarketingSpentFromOrder(orderId: mongoose.Types.ObjectId): Promise<any> {\n\t\tconst order = (await this.orderModel\n\t\t\t.findById(orderId)\n\t\t\t.populate('lineItems')) as DocumentType<RegularOrder> & { lineItems: DocumentType<LineItem>[] };\n\n\t\tif (!order || !order.marketings?.length) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst marketingSpendMap = this.marketingMetricsRepository.calculateMarketingSpendPerOrder(order);\n\n\t\tconst bulkOps = [...marketingSpendMap.entries()].map(([marketingId, amountSpent]) => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { _id: marketingId },\n\t\t\t\tupdate: { $inc: { amountSpent: -amountSpent } },\n\t\t\t},\n\t\t}));\n\n\t\tif (bulkOps.length) {\n\t\t\tawait this.model.bulkWrite(bulkOps);\n\t\t}\n\n\t\tawait this.unExpireMarketingsBelowSpendLimits(Array.from(marketingSpendMap.keys()));\n\n\t\treturn 'Marketing amount spent decremented successfully';\n\t}\n\n\tprivate async expireMarketingsExceedingSpendLimits(marketingIds: mongoose.Types.ObjectId[]) {\n\t\tawait this.model.updateMany(\n\t\t\t{\n\t\t\t\t_id: { $in: marketingIds },\n\t\t\t\tisSpendLimitEnabled: true,\n\t\t\t\tstatus: { $ne: MarketingStatus.EXPIRED },\n\t\t\t\t$expr: { $gte: ['$amountSpent', '$spendLimit'] },\n\t\t\t},\n\t\t\t{ $set: { status: MarketingStatus.EXPIRED } }\n\t\t);\n\t}\n\n\tprivate async unExpireMarketingsBelowSpendLimits(marketingIds: mongoose.Types.ObjectId[]) {\n\t\tawait this.model.updateMany(\n\t\t\t{\n\t\t\t\t_id: { $in: marketingIds },\n\t\t\t\tisSpendLimitEnabled: true,\n\t\t\t\tstatus: MarketingStatus.EXPIRED,\n\t\t\t\t$expr: { $lt: ['$amountSpent', '$spendLimit'] },\n\t\t\t},\n\t\t\t{ $set: { status: MarketingStatus.ACTIVE } }\n\t\t);\n\t}\n\n\tpublic async recomputeAndSyncAllMarketingSpent(): Promise<void> {\n\t\tconsole.time('Recomputing all marketing spend');\n\n\t\tconst cursor = this.model\n\t\t\t.find({ marketingType: { $ne: MarketingType.FEATURED } }, { _id: 1 })\n\t\t\t.lean()\n\t\t\t.cursor();\n\n\t\tconst bulkOps: mongoose.AnyBulkWriteOperation[] = [];\n\t\tconst marketingIds: mongoose.Types.ObjectId[] = [];\n\n\t\tfor await (const marketing of cursor) {\n\t\t\tconsole.log(`Recomputing marketing spend for marketing ID: ${marketing._id}`);\n\t\t\tconst { amount } = await this.marketingMetricsRepository.calculateMarketingSpent(marketing._id);\n\n\t\t\tbulkOps.push({\n\t\t\t\tupdateOne: {\n\t\t\t\t\tfilter: { _id: marketing._id },\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\t$set: { amountSpent: amount },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tmarketingIds.push(marketing._id);\n\n\t\t\t// Flush periodically to keep memory + locks under control\n\t\t\tif (bulkOps.length >= 500) {\n\t\t\t\tconsole.log(`Flushing 500 marketing spend updates...`);\n\t\t\t\tawait this.model.bulkWrite(bulkOps);\n\t\t\t\tbulkOps.length = 0;\n\t\t\t}\n\t\t}\n\n\t\t// Flush remaining updates\n\t\tif (bulkOps.length) {\n\t\t\tconsole.log(`Flushing remaining ${bulkOps.length} marketing spend updates...`);\n\t\t\tawait this.model.bulkWrite(bulkOps);\n\t\t}\n\n\t\t// Re-evaluate spend limits AFTER all amounts are correct\n\t\tawait this.expireMarketingsExceedingSpendLimits(marketingIds);\n\t\tawait this.unExpireMarketingsBelowSpendLimits(marketingIds);\n\n\t\tconsole.timeEnd('Recomputing all marketing spend');\n\t}\n}\n\nexport const marketingService = Container.get(MarketingService);\n"]}
|
|
1
|
+
{"version":3,"file":"marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,8DAA2D;AAC3D,wCAA6C;AAC7C,oDAA+E;AAC/E,sEAYmD;AAenD,wEAA6G;AAE7G,8FAI4D;AAC5D,iGAAoG;AACpG,4DAI2C;AAC3C,8DAAkE;AAElE,8FAGqD;AACrD,wBAQW;AACX,4DAAkE;AAClE,4EAKmD;AACnD,6JAAsI;AACtI,kGAG2D;AAGpD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACpB,KAAK,CAAiD;IACtD,SAAS,CAA2C;IACpD,UAAU,CAA2D;IACrE,0BAA0B,CAA6B;IAE/D;QACC,IAAI,CAAC,KAAK,GAAG,uBAAgE,CAAC;QAC9E,IAAI,CAAC,SAAS,GAAG,kBAAqD,CAAC;QACvE,IAAI,CAAC,UAAU,GAAG,0BAA6E,CAAC;QAChG,IAAI,CAAC,0BAA0B,GAAG,uDAA0B,CAAC;IAC9D,CAAC;IAMM,KAAK,CAAC,MAAM,CAClB,IAAgC,EAChC,KAA+B;QAE/B,MAAM,GAAG,GAAG,IAAA,aAAK,GAAE,CAAC,MAAM,EAAE,CAAC;QAE7B,MAAM,cAAc,GAAG,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,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CACzC,IAAA,oBAAY,EACX,IAAI,2DAA4B,CAAC;YAChC,WAAW,EAAE,GAAG;YAChB,MAAM;YACN,kBAAkB,EAAE,SAAS,CAAC,kBAAkB,IAAI,KAAK;YACzD,UAAU,EAAE,SAAS,CAAC,aAAa,KAAK,oBAAa,CAAC,QAAQ;YAC9D,KAAK,EAAG,SAAiB,CAAC,KAAK;YAC/B,SAAS,EAAG,SAAiB,CAAC,SAAS;YACvC,IAAI;YACJ,QAAQ,EAAE,SAAS;SACnB,CAAC,CACF,CACD,CACD,CAAC;QAEF,MAAM,CAAC,KAAK,CAAC,mCAAmC,KAAK,cAAc,KAAK,WAAW,EAAE;YACpF,GAAG,EAAE,4BAA4B;YACjC,IAAI,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE;SAC9D,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AA3oBY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,gBAAO,GAAE;;GACG,gBAAgB,CA2oB5B;AAEY,QAAA,gBAAgB,GAAG,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\nimport { getLibraries } from '@lyxa.ai/core';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport {\n\tBuy1Get1Marketing,\n\tDiscountMarketing,\n\tLineItem,\n\tMarketing,\n\tMarketingModel,\n\tMarketing as Model,\n\tProductModel,\n\tRegularOrder,\n\tRegularOrderModel,\n\tShop,\n\tShopModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tAllMarketingsDTO,\n\tAllMarketingsValidationDTO,\n\tCreateProductMarketingDTO,\n\tProductEntireMenuMarketingHandlerDTO,\n\tUpdateMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport {\n\tFilterDTO,\n\tPaginatedResponse,\n\tDeleteDTO,\n\tGetByIdInputDTO,\n} from '@lyxa.ai/core/dist/utilities/validation';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport {\n\tfilterRelevantChanges,\n\tgetChangedFields,\n\tpublishSyncSingleShopSectionsInCacheProcessEvent,\n} from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport {\n\tAdminLogsUpdatedFieldsType,\n\tMarketingStatus,\n\tRegularOrderStatus,\n} from '@lyxa.ai/core/dist/utilities/enum';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\nimport {\n\tMarketingEntireMenuSeedEvent,\n\tMarketingProductSeedPayload,\n} from '@events/events/marketing-product-seed.event';\nimport {\n\tbuy1Get1MarketingService,\n\tdiscountMarketingService,\n\tfeaturedMarketingService,\n\tfreeDeliveryMarketingService,\n\tproductMarketingService,\n\tpunchMarketingService,\n\tsynchronizeProductMarketingService,\n} from '.';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tconflictError,\n\tinternalServerError,\n\tnotFoundError,\n\tunauthorizedError,\n} from '@lyxa.ai/core/dist/utilities/error-common';\nimport { ChangeStreamOperationTypes } from '@lyxa.ai/core/dist/libraries/event/events/mongo-stream-changes-batch-process-shops-event';\nimport {\n\tMarketingMetricsRepository,\n\tmarketingMetricsRepository,\n} from '../patterns/repository/MarketingMetricsRepository';\n\n@Service()\nexport class MarketingService {\n\tprivate model: typeof MarketingModel & SoftDeleteModel<Model>;\n\tprivate shopModel: typeof ShopModel & SoftDeleteModel<Shop>;\n\tprivate orderModel: typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\tprivate marketingMetricsRepository: MarketingMetricsRepository;\n\n\tconstructor() {\n\t\tthis.model = MarketingModel as typeof MarketingModel & SoftDeleteModel<Model>;\n\t\tthis.shopModel = ShopModel as typeof ShopModel & SoftDeleteModel<Shop>;\n\t\tthis.orderModel = RegularOrderModel as typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\t\tthis.marketingMetricsRepository = marketingMetricsRepository;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(\n\t\tdata: AllMarketingsValidationDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tconst now = dayjs().toDate();\n\n\t\tconst existingRecord = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: data.marketingType,\n\t\t\t'duration.end': { $gt: now },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\tisAppliedByCompany: data.isAppliedByCompany,\n\t\t});\n\n\t\tif (existingRecord) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `This shop already has a ${data.marketingType} marketing`,\n\t\t\t});\n\t\t}\n\n\t\tif (data.isEntireMenu) {\n\t\t\tconst existingMarketing = await this.model.findOne({\n\t\t\t\tshop: data.shop,\n\t\t\t\t'duration.start': { $lt: now },\n\t\t\t\t'duration.end': { $gt: now },\n\t\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\t\tmarketingType: { $in: [MarketingType.BUY1GET1, MarketingType.DISCOUNT], $ne: data.marketingType },\n\t\t\t});\n\n\t\t\tif (existingMarketing) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Cannot create marketing for entire menu while another product based marketing exists for the shop`,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (data.products && data.products.length > 0) {\n\t\t\tconst productIds = data.products.map((product: CreateProductMarketingDTO) => product.product);\n\n\t\t\tconst hasDuplicates = new Set(productIds.map(String)).size !== productIds.length;\n\n\t\t\tif (hasDuplicates) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'BAD_REQUEST',\n\t\t\t\t\tmessage: `Product list contains duplicate products`,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability(\n\t\t\t\tproductIds,\n\t\t\t\tdata.isAppliedByCompany\n\t\t\t);\n\n\t\t\tif (!isAvailable) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Product list contains products which already have marketing applied`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (admin) {\n\t\t\tdata.admin = admin;\n\t\t}\n\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tswitch (data.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: 'UNAUTHORIZED',\n\t\t\t\t\t\tmessage: `Only admin is allowed to create ${data.marketingType} marketing`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.create(data, admin);\n\t\t\t}\n\t\t}\n\n\t\tif (data.isEntireMenu) {\n\t\t\tconst logger = getLibraries().getLoggerKit();\n\t\t\tconst PAGE_SIZE = 500;\n\t\t\tconst marketingId = marketing._id.toString();\n\t\t\tconst shopId = data.shop.toString();\n\n\t\t\tconst count = await ProductModel.countDocuments({ shop: data.shop });\n\t\t\tconst pages = Math.ceil(count / PAGE_SIZE);\n\n\t\t\tif (pages > 0) {\n\t\t\t\tawait Promise.all(\n\t\t\t\t\tArray.from({ length: pages }, (_, page) =>\n\t\t\t\t\t\tpublishEvent(\n\t\t\t\t\t\t\tnew MarketingEntireMenuSeedEvent({\n\t\t\t\t\t\t\t\tmarketingId,\n\t\t\t\t\t\t\t\tshopId,\n\t\t\t\t\t\t\t\tisAppliedByCompany: data.isAppliedByCompany ?? false,\n\t\t\t\t\t\t\t\tisBuy1Get1: data.marketingType === MarketingType.BUY1GET1,\n\t\t\t\t\t\t\t\tvalue: (data as any).value,\n\t\t\t\t\t\t\t\tvalueType: (data as any).valueType,\n\t\t\t\t\t\t\t\tpage,\n\t\t\t\t\t\t\t\tpageSize: PAGE_SIZE,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t);\n\n\t\t\t\tlogger.debug(`entire-menu marketing seed dispatched — ${pages} pages for ${count} products`, {\n\t\t\t\t\ttag: 'marketing.seed.entire-menu',\n\t\t\t\t\tdata: { marketingId, shopId, pages, productCount: count },\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tawait productMarketingService.syncProductMarketingInfo(marketing._id);\n\t\t}\n\n\t\tawait this.model.populate(marketing, {\n\t\t\tpath: 'shop',\n\t\t\tmodel: this.shopModel,\n\t\t\tselect: '_id name shopId',\n\t\t});\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.ACTIVATED_MARKETING_PROMOTIONS,\n\t\t\t\t'',\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\t\tif (marketing && !data.isEntireMenu)\n\t\t\tpublishSyncSingleShopSectionsInCacheProcessEvent({\n\t\t\t\tshopId: data.shop,\n\t\t\t\toperation: ChangeStreamOperationTypes.UPDATE,\n\t\t\t});\n\t\treturn marketing;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(data: GetByIdInputDTO): Promise<DocumentType<Model>> {\n\t\tconst select = data.select || '';\n\t\tconst populate = data.populate || [];\n\t\tconst result = await this.model\n\t\t\t.findOne({\n\t\t\t\t_id: data._id,\n\t\t\t})\n\t\t\t.select(select)\n\t\t\t.populate(populate);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(\n\t\t_id: mongoose.Types.ObjectId,\n\t\tdata: UpdateDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tconst oldMarketing = await this.model.findById(_id).populate({\n\t\t\tpath: 'shop',\n\t\t\tselect: '_id name shopId',\n\t\t});\n\n\t\tif (!oldMarketing) {\n\t\t\tnotFoundError('Could not find marketing');\n\t\t}\n\n\t\tif (\n\t\t\tdata.status &&\n\t\t\tdata.status === MarketingStatus.ACTIVE &&\n\t\t\toldMarketing.status === MarketingStatus.PAUSED\n\t\t) {\n\t\t\tawait this.verifyUnpauseConditions(_id);\n\t\t}\n\n\t\tswitch (oldMarketing.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tunauthorizedError(`Only admin is allowed to update ${data.marketingType} marketing`);\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model\n\t\t\t\t\t.findOneAndUpdate(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t_id: _id,\n\t\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tnew: true,\n\t\t\t\t\t\t\trunValidators: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t\t.populate({\n\t\t\t\t\t\tpath: 'shop',\n\t\t\t\t\t\tselect: '_id name shopId',\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (!marketing) {\n\t\t\tinternalServerError('Could not update marketing');\n\t\t}\n\n\t\tif (admin) {\n\t\t\tconst allChanges = getChangedFields(oldMarketing, marketing);\n\t\t\tconst relevantChanges = filterRelevantChanges(allChanges, data);\n\n\t\t\tif (Object.keys(relevantChanges).includes('status')) {\n\t\t\t\tif (data.status == MarketingStatus.ACTIVE) {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.CONTINUED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t} else if (data.status == MarketingStatus.PAUSED) {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.PAUSED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.EDITED_MARKETING_PROMOTIONS,\n\t\t\t\toldMarketing,\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\tawait productMarketingService.syncProductMarketingInfo(_id);\n\n\t\tpublishSyncSingleShopSectionsInCacheProcessEvent({\n\t\t\tshopId: marketing.shop,\n\t\t\toperation: ChangeStreamOperationTypes.UPDATE,\n\t\t});\n\n\t\treturn marketing;\n\t}\n\n\tprivate async verifyUnpauseConditions(marketingId: mongoose.Types.ObjectId): Promise<void> {\n\t\tconst marketing = await this.model.findOne({ _id: marketingId, deletedAt: null }).populate('products');\n\t\tif (!marketing) return;\n\n\t\tif ([MarketingType.BUY1GET1, MarketingType.DISCOUNT].includes(marketing.marketingType)) {\n\t\t\tconst typedMarketing = marketing as DocumentType<DiscountMarketing | Buy1Get1Marketing>;\n\t\t\tconst productIds = typedMarketing.products.map((product: any) => product.product);\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability(\n\t\t\t\tproductIds,\n\t\t\t\tmarketing.isAppliedByCompany\n\t\t\t);\n\n\t\t\tif (!isAvailable) {\n\t\t\t\tconflictError(\"You can't activate discount and B1G1 on the same items at the same time\");\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async logMarketingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: mongoose.Types.ObjectId): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tconst record = await this.model.findById(_id).populate({\n\t\t\tpath: 'shop',\n\t\t\tselect: '_id name shopId',\n\t\t});\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\n\t\trecord.status = MarketingStatus.DELETED;\n\t\tawait record.save();\n\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete marketing',\n\t\t\t});\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(admin, AdminLogsUpdatedFieldsType.DELETED_MARKETING_PROMOTIONS, record);\n\t\t}\n\n\t\tproductMarketingService.deleteMany({ marketing: data._id }, data.softDelete);\n\t\tpublishSyncSingleShopSectionsInCacheProcessEvent({\n\t\t\tshopId: record.shop._id,\n\t\t\toperation: ChangeStreamOperationTypes.DELETE,\n\t\t});\n\t\treturn 'Record deleted successfully';\n\t}\n\n\tpublic async deleteManyByIds(marketingIds: mongoose.Types.ObjectId[], softDelete = true): Promise<void> {\n\t\tif (marketingIds.length === 0) return;\n\n\t\tconst marketings = await this.model\n\t\t\t.find({ _id: { $in: marketingIds } })\n\t\t\t.select('shop')\n\t\t\t.lean();\n\n\t\tawait this.model.updateMany(\n\t\t\t{ _id: { $in: marketingIds } },\n\t\t\t{ $set: { status: MarketingStatus.DELETED } },\n\t\t);\n\t\tawait this.model.deleteRecords({ _id: { $in: marketingIds } }, softDelete);\n\n\t\tawait productMarketingService.deleteManyByMarketingIds(marketingIds, softDelete);\n\n\t\tconst uniqueShopIds = [\n\t\t\t...new Map(\n\t\t\t\tmarketings\n\t\t\t\t\t.map((m: any) => m.shop)\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.map((s: any) => {\n\t\t\t\t\t\tconst id = s instanceof mongoose.Types.ObjectId ? s : new mongoose.Types.ObjectId(s);\n\t\t\t\t\t\treturn [id.toString(), id] as [string, mongoose.Types.ObjectId];\n\t\t\t\t\t})\n\t\t\t).values(),\n\t\t];\n\n\t\tfor (const shopId of uniqueShopIds) {\n\t\t\tpublishSyncSingleShopSectionsInCacheProcessEvent({\n\t\t\t\tshopId,\n\t\t\t\toperation: ChangeStreamOperationTypes.DELETE,\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic async handleNewProductForEntireMenuMarketing(data: ProductEntireMenuMarketingHandlerDTO) {\n\t\tconst existingMarketing = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: { $in: [MarketingType.BUY1GET1, MarketingType.DISCOUNT] },\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\tisEntireMenu: true,\n\t\t});\n\n\t\t// check if existing marketing\n\t\tif (existingMarketing) {\n\t\t\tconst productMarketingData: CreateProductMarketingDTO = {\n\t\t\t\tproduct: data.product,\n\t\t\t\tmarketing: existingMarketing._id,\n\t\t\t};\n\t\t\tif (existingMarketing.marketingType == MarketingType.BUY1GET1) {\n\t\t\t\tproductMarketingData.isBuy1Get1 = true;\n\t\t\t}\n\t\t\tif (existingMarketing.marketingType == MarketingType.DISCOUNT) {\n\t\t\t\tproductMarketingData.value = (existingMarketing as DocumentType<DiscountMarketing>).value;\n\t\t\t\tproductMarketingData.valueType = (existingMarketing as DocumentType<DiscountMarketing>).valueType;\n\t\t\t}\n\n\t\t\tawait productMarketingService.create(productMarketingData);\n\t\t\tawait synchronizeProductMarketingService.syncProductMarketingInfoByProductId(data.product);\n\t\t}\n\n\t\treturn 'Product handled successfully';\n\t}\n\n\tpublic async incrementMarketingSpentFromOrder(orderId: mongoose.Types.ObjectId): Promise<any> {\n\t\tconst order = (await this.orderModel\n\t\t\t.findById(orderId)\n\t\t\t.populate([\n\t\t\t\t{ path: 'lineItems' },\n\t\t\t\t{ path: 'marketings', select: 'isAppliedByCompany' },\n\t\t\t])) as DocumentType<RegularOrder> & {\n\t\t\tlineItems: DocumentType<LineItem>[];\n\t\t\tmarketings: DocumentType<Marketing>[];\n\t\t};\n\n\t\tif (!order || !order.marketings?.length) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst marketingSpendMap = this.marketingMetricsRepository.calculateMarketingSpendPerOrder(order);\n\n\t\tconst bulkOps = [...marketingSpendMap.entries()].map(([marketingId, amountSpent]) => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { _id: marketingId },\n\t\t\t\tupdate: { $inc: { amountSpent } },\n\t\t\t},\n\t\t}));\n\n\t\tif (bulkOps.length) {\n\t\t\tawait this.model.bulkWrite(bulkOps);\n\t\t}\n\n\t\tawait this.expireMarketingsExceedingSpendLimits(Array.from(marketingSpendMap.keys()));\n\n\t\treturn 'Marketing amount spent incremented successfully';\n\t}\n\n\tpublic async decrementMarketingSpentFromOrder(orderId: mongoose.Types.ObjectId): Promise<any> {\n\t\tconst order = (await this.orderModel\n\t\t\t.findById(orderId)\n\t\t\t.populate([\n\t\t\t\t{ path: 'lineItems' },\n\t\t\t\t{ path: 'marketings', select: 'isAppliedByCompany' },\n\t\t\t])) as DocumentType<RegularOrder> & {\n\t\t\tlineItems: DocumentType<LineItem>[];\n\t\t\tmarketings: DocumentType<Marketing>[];\n\t\t};\n\n\t\tif (!order || !order.marketings?.length) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst marketingSpendMap = this.marketingMetricsRepository.calculateMarketingSpendPerOrder(order);\n\n\t\tconst bulkOps = [...marketingSpendMap.entries()].map(([marketingId, amountSpent]) => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { _id: marketingId },\n\t\t\t\tupdate: { $inc: { amountSpent: -amountSpent } },\n\t\t\t},\n\t\t}));\n\n\t\tif (bulkOps.length) {\n\t\t\tawait this.model.bulkWrite(bulkOps);\n\t\t}\n\n\t\tawait this.unExpireMarketingsBelowSpendLimits(Array.from(marketingSpendMap.keys()));\n\n\t\treturn 'Marketing amount spent decremented successfully';\n\t}\n\n\tprivate async expireMarketingsExceedingSpendLimits(marketingIds: mongoose.Types.ObjectId[]) {\n\t\tawait this.model.updateMany(\n\t\t\t{\n\t\t\t\t_id: { $in: marketingIds },\n\t\t\t\tisSpendLimitEnabled: true,\n\t\t\t\tstatus: { $ne: MarketingStatus.EXPIRED },\n\t\t\t\t$expr: { $gte: ['$amountSpent', '$spendLimit'] },\n\t\t\t},\n\t\t\t{ $set: { status: MarketingStatus.EXPIRED, expiredAt: dayjs().toDate() } }\n\t\t);\n\t}\n\n\tprivate async unExpireMarketingsBelowSpendLimits(marketingIds: mongoose.Types.ObjectId[]) {\n\t\tawait this.model.updateMany(\n\t\t\t{\n\t\t\t\t_id: { $in: marketingIds },\n\t\t\t\tisSpendLimitEnabled: true,\n\t\t\t\tstatus: MarketingStatus.EXPIRED,\n\t\t\t\t$expr: { $lt: ['$amountSpent', '$spendLimit'] },\n\t\t\t},\n\t\t\t{ $set: { status: MarketingStatus.ACTIVE }, $unset: { expiredAt: 1 } }\n\t\t);\n\t}\n\n\tpublic async recomputeAndSyncAllMarketingSpent(): Promise<void> {\n\t\tconst cursor = this.model\n\t\t\t.find({ marketingType: { $ne: MarketingType.FEATURED } }, { _id: 1 })\n\t\t\t.lean()\n\t\t\t.cursor();\n\n\t\tconst bulkOps: mongoose.AnyBulkWriteOperation[] = [];\n\t\tconst marketingIds: mongoose.Types.ObjectId[] = [];\n\n\t\tfor await (const marketing of cursor) {\n\t\t\tconst { amount } = await this.marketingMetricsRepository.calculateMarketingSpent(marketing._id);\n\n\t\t\tbulkOps.push({\n\t\t\t\tupdateOne: {\n\t\t\t\t\tfilter: { _id: marketing._id },\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\t$set: { amountSpent: amount },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tmarketingIds.push(marketing._id);\n\n\t\t\tif (bulkOps.length >= 500) {\n\t\t\t\tawait this.model.bulkWrite(bulkOps);\n\t\t\t\tbulkOps.length = 0;\n\t\t\t}\n\t\t}\n\n\t\tif (bulkOps.length) {\n\t\t\tawait this.model.bulkWrite(bulkOps);\n\t\t}\n\n\t\tawait this.expireMarketingsExceedingSpendLimits(marketingIds);\n\t\tawait this.unExpireMarketingsBelowSpendLimits(marketingIds);\n\t}\n\n\tpublic async reseedEntireMenuMarketing(marketingId: mongoose.Types.ObjectId): Promise<void> {\n\t\tconst logger = getLibraries().getLoggerKit();\n\n\t\tconst marketing = await this.model.findOne({ _id: marketingId, deletedAt: null });\n\t\tif (!marketing) internalServerError('Marketing not found');\n\n\t\tconst PAGE_SIZE = 500;\n\t\tconst mid = marketingId.toString();\n\t\tconst shopId = marketing.shop.toString();\n\t\tconst count = await ProductModel.countDocuments({ shop: marketing.shop });\n\t\tconst pages = Math.ceil(count / PAGE_SIZE);\n\n\t\tif (!pages) return;\n\n\t\tawait Promise.all(\n\t\t\tArray.from({ length: pages }, (_, page) =>\n\t\t\t\tpublishEvent(\n\t\t\t\t\tnew MarketingEntireMenuSeedEvent({\n\t\t\t\t\t\tmarketingId: mid,\n\t\t\t\t\t\tshopId,\n\t\t\t\t\t\tisAppliedByCompany: marketing.isAppliedByCompany ?? false,\n\t\t\t\t\t\tisBuy1Get1: marketing.marketingType === MarketingType.BUY1GET1,\n\t\t\t\t\t\tvalue: (marketing as any).value,\n\t\t\t\t\t\tvalueType: (marketing as any).valueType,\n\t\t\t\t\t\tpage,\n\t\t\t\t\t\tpageSize: PAGE_SIZE,\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t)\n\t\t);\n\n\t\tlogger.debug(`entire-menu reseed dispatched — ${pages} pages for ${count} products`, {\n\t\t\ttag: 'marketing.seed.entire-menu',\n\t\t\tdata: { marketingId: mid, shopId, pages, productCount: count },\n\t\t});\n\t}\n}\n\nexport const marketingService = Container.get(MarketingService);\n"]}
|
|
@@ -1,20 +1,38 @@
|
|
|
1
1
|
import { DocumentType, mongoose } from '@typegoose/typegoose';
|
|
2
2
|
import { ProductMarketing as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/';
|
|
3
|
-
import { CreateProductMarketingDTO as CreateDTO, QueryProductMarketingDTO as QueryDTO, QueryMultipleProductMarketingDTO, UpdateProductMarketingDTO as UpdateDTO } from '../../marketing/validations';
|
|
3
|
+
import { BatchCreateProductMarketingsInputDTO, CreateProductMarketingDTO as CreateDTO, QueryProductMarketingDTO as QueryDTO, QueryMultipleProductMarketingDTO, UpdateProductMarketingDTO as UpdateDTO } from '../../marketing/validations';
|
|
4
4
|
import { FilterDTO, PaginatedResponse } from '@lyxa.ai/core/dist/utilities/validation';
|
|
5
5
|
import { ModelType } from '@typegoose/typegoose/lib/types';
|
|
6
|
+
import { ValueType } from '@lyxa.ai/core/dist/utilities/enum';
|
|
6
7
|
export declare class ProductMarketingService {
|
|
7
8
|
private model;
|
|
9
|
+
private productModel;
|
|
8
10
|
private syncProductsMarketingInfoService;
|
|
9
11
|
constructor();
|
|
10
12
|
create(data: CreateDTO): Promise<DocumentType<Model>>;
|
|
13
|
+
bulkCreate(data: CreateDTO[]): Promise<void>;
|
|
14
|
+
bulkCreateFromCursor<T>(cursor: AsyncIterable<T>, mapper: (item: T) => any): Promise<void>;
|
|
15
|
+
bulkCreateFromArray<T>(items: Iterable<T>, mapper: (item: T) => any): Promise<void>;
|
|
16
|
+
private buildProductsMap;
|
|
17
|
+
createProductMarketings(data: BatchCreateProductMarketingsInputDTO): Promise<void>;
|
|
11
18
|
findById(id: string | mongoose.Types.ObjectId): Promise<DocumentType<Model>>;
|
|
12
19
|
find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>>;
|
|
13
20
|
updateOne(query: QueryDTO, data: UpdateDTO): Promise<string>;
|
|
14
21
|
deleteMany(filter: QueryDTO, softDelete: boolean): Promise<string>;
|
|
22
|
+
deleteManyByMarketingIds(marketingIds: mongoose.Types.ObjectId[], softDelete: boolean): Promise<void>;
|
|
15
23
|
syncProductMarketingInfo(marketingId: mongoose.Types.ObjectId): Promise<void>;
|
|
16
24
|
deleteMultipleProducts(filter: QueryMultipleProductMarketingDTO, softDelete: boolean): Promise<string>;
|
|
17
|
-
checkProductMarketingAvailability(products: mongoose.Types.ObjectId[]): Promise<boolean>;
|
|
25
|
+
checkProductMarketingAvailability(products: mongoose.Types.ObjectId[], isAppliedByCompany?: boolean): Promise<boolean>;
|
|
26
|
+
upsertProductMarketingsForPage(data: {
|
|
27
|
+
shop: mongoose.Types.ObjectId;
|
|
28
|
+
marketingId: mongoose.Types.ObjectId;
|
|
29
|
+
page: number;
|
|
30
|
+
pageSize: number;
|
|
31
|
+
isAppliedByCompany: boolean;
|
|
32
|
+
isBuy1Get1: boolean;
|
|
33
|
+
value?: number;
|
|
34
|
+
valueType?: ValueType;
|
|
35
|
+
}): Promise<mongoose.Types.ObjectId[]>;
|
|
18
36
|
countDocuments(filter: QueryDTO): Promise<number>;
|
|
19
37
|
}
|
|
20
38
|
export declare const productMarketingService: ProductMarketingService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/product-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,
|
|
1
|
+
{"version":3,"file":"product-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/product-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAEN,gBAAgB,IAAI,KAAK,EAEzB,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,oCAAoC,EACpC,yBAAyB,IAAI,SAAS,EACtC,wBAAwB,IAAI,QAAQ,EACpC,gCAAgC,EAChC,yBAAyB,IAAI,SAAS,EACtC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAEvF,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAAmB,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAO/E,qBACa,uBAAuB;IACnC,OAAO,CAAC,KAAK,CAAwD;IACrE,OAAO,CAAC,YAAY,CAAsB;IAE1C,OAAO,CAAC,gCAAgC,CAAqC;;IAahE,MAAM,CAAC,IAAI,EAAE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