@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
|
@@ -53,18 +53,118 @@ const synchronize_product_marketing_service_1 = require("./synchronize-product-m
|
|
|
53
53
|
const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
|
|
54
54
|
let ProductMarketingService = class ProductMarketingService {
|
|
55
55
|
model;
|
|
56
|
+
productModel;
|
|
56
57
|
syncProductsMarketingInfoService;
|
|
57
58
|
constructor() {
|
|
58
59
|
this.model = models_1.ProductMarketingModel;
|
|
60
|
+
this.productModel = models_1.ProductModel;
|
|
59
61
|
this.syncProductsMarketingInfoService = synchronize_product_marketing_service_1.synchronizeProductMarketingService;
|
|
60
62
|
}
|
|
61
63
|
async create(data) {
|
|
62
64
|
const result = await this.model.create(data);
|
|
63
65
|
if (!result)
|
|
64
66
|
(0, error_common_1.badRequestError)('Product marketing creation failed');
|
|
65
|
-
await this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductId(data.product);
|
|
66
67
|
return result;
|
|
67
68
|
}
|
|
69
|
+
async bulkCreate(data) {
|
|
70
|
+
await this.model.insertMany(data, { ordered: false });
|
|
71
|
+
}
|
|
72
|
+
async bulkCreateFromCursor(cursor, mapper) {
|
|
73
|
+
const BATCH_SIZE = 500;
|
|
74
|
+
const batch = [];
|
|
75
|
+
for await (const item of cursor) {
|
|
76
|
+
batch.push(mapper(item));
|
|
77
|
+
if (batch.length === BATCH_SIZE) {
|
|
78
|
+
await this.bulkCreate(batch);
|
|
79
|
+
batch.length = 0;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (batch.length) {
|
|
83
|
+
await this.bulkCreate(batch);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async bulkCreateFromArray(items, mapper) {
|
|
87
|
+
const BATCH_SIZE = 500;
|
|
88
|
+
const batch = [];
|
|
89
|
+
for (const item of items) {
|
|
90
|
+
batch.push(mapper(item));
|
|
91
|
+
if (batch.length === BATCH_SIZE) {
|
|
92
|
+
await this.bulkCreate(batch);
|
|
93
|
+
batch.length = 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (batch.length) {
|
|
97
|
+
await this.bulkCreate(batch);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async buildProductsMap(data) {
|
|
101
|
+
const map = {};
|
|
102
|
+
for (const p of data.products || []) {
|
|
103
|
+
if (data.isBuy1Get1) {
|
|
104
|
+
map[p.product.toString()] = {
|
|
105
|
+
isBuy1Get1: true,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
else if (p.value !== undefined && p.valueType) {
|
|
109
|
+
map[p.product.toString()] = {
|
|
110
|
+
value: Number(p.value),
|
|
111
|
+
valueType: p.valueType,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (data.categories?.length) {
|
|
116
|
+
const categoryProducts = await this.productModel
|
|
117
|
+
.find({ shopCategory: { $in: data.categories } })
|
|
118
|
+
.select('_id')
|
|
119
|
+
.lean();
|
|
120
|
+
for (const p of categoryProducts) {
|
|
121
|
+
const id = p._id.toString();
|
|
122
|
+
if (!map[id]) {
|
|
123
|
+
if (data.isBuy1Get1) {
|
|
124
|
+
map[id.toString()] = {
|
|
125
|
+
isBuy1Get1: true,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
else if (data.categoryValue !== undefined && data.categoryValueType) {
|
|
129
|
+
map[id] = {
|
|
130
|
+
value: Number(data.categoryValue),
|
|
131
|
+
valueType: data.categoryValueType,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return map;
|
|
138
|
+
}
|
|
139
|
+
async createProductMarketings(data) {
|
|
140
|
+
const { shop, marketingId, products, categories, isEntireMenu, isAppliedByCompany, categoryValue, categoryValueType, value, valueType, isBuy1Get1, } = data;
|
|
141
|
+
if (isEntireMenu) {
|
|
142
|
+
await this.bulkCreateFromCursor(this.productModel.find({ shop }).select('_id').lean().cursor(), product => ({
|
|
143
|
+
marketing: marketingId,
|
|
144
|
+
product: product._id,
|
|
145
|
+
value,
|
|
146
|
+
valueType,
|
|
147
|
+
isAppliedByCompany,
|
|
148
|
+
isBuy1Get1,
|
|
149
|
+
}));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const productsMap = await this.buildProductsMap({
|
|
153
|
+
products: data.products,
|
|
154
|
+
isBuy1Get1: data.isBuy1Get1,
|
|
155
|
+
categories: data.categories,
|
|
156
|
+
categoryValue: data.categoryValue,
|
|
157
|
+
categoryValueType: data.categoryValueType,
|
|
158
|
+
});
|
|
159
|
+
await this.bulkCreateFromArray(Object.entries(productsMap), ([productId, info]) => ({
|
|
160
|
+
marketing: marketingId,
|
|
161
|
+
product: new typegoose_1.mongoose.Types.ObjectId(productId),
|
|
162
|
+
value: info.value,
|
|
163
|
+
valueType: info.valueType,
|
|
164
|
+
isAppliedByCompany,
|
|
165
|
+
isBuy1Get1: info.isBuy1Get1,
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
68
168
|
async findById(id) {
|
|
69
169
|
const result = await this.model.findOne({
|
|
70
170
|
_id: id,
|
|
@@ -123,6 +223,27 @@ let ProductMarketingService = class ProductMarketingService {
|
|
|
123
223
|
await this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(uniqueProductIds);
|
|
124
224
|
return 'Record deleted successfully';
|
|
125
225
|
}
|
|
226
|
+
async deleteManyByMarketingIds(marketingIds, softDelete) {
|
|
227
|
+
if (marketingIds.length === 0)
|
|
228
|
+
return;
|
|
229
|
+
const productMarketings = await this.model
|
|
230
|
+
.find({ marketing: { $in: marketingIds } })
|
|
231
|
+
.select('product')
|
|
232
|
+
.lean();
|
|
233
|
+
await this.model.deleteRecords({ marketing: { $in: marketingIds } }, softDelete);
|
|
234
|
+
const uniqueProductIds = [
|
|
235
|
+
...new Map(productMarketings
|
|
236
|
+
.map((r) => r.product)
|
|
237
|
+
.filter(Boolean)
|
|
238
|
+
.map((p) => {
|
|
239
|
+
const id = p instanceof typegoose_1.mongoose.Types.ObjectId ? p : new typegoose_1.mongoose.Types.ObjectId(p);
|
|
240
|
+
return [id.toString(), id];
|
|
241
|
+
})).values(),
|
|
242
|
+
];
|
|
243
|
+
if (uniqueProductIds.length) {
|
|
244
|
+
await this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(uniqueProductIds);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
126
247
|
async syncProductMarketingInfo(marketingId) {
|
|
127
248
|
const productMarketings = await this.model.find({ marketing: marketingId });
|
|
128
249
|
const productIds = productMarketings
|
|
@@ -138,8 +259,16 @@ let ProductMarketingService = class ProductMarketingService {
|
|
|
138
259
|
}, softDelete);
|
|
139
260
|
return 'Record deleted successfully';
|
|
140
261
|
}
|
|
141
|
-
async checkProductMarketingAvailability(products) {
|
|
262
|
+
async checkProductMarketingAvailability(products, isAppliedByCompany) {
|
|
142
263
|
const now = new Date();
|
|
264
|
+
const marketingMatch = {
|
|
265
|
+
'marketingDoc.status': enum_1.MarketingStatus.ACTIVE,
|
|
266
|
+
'marketingDoc.duration.start': { $lt: now },
|
|
267
|
+
'marketingDoc.duration.end': { $gt: now },
|
|
268
|
+
};
|
|
269
|
+
if (typeof isAppliedByCompany === 'boolean') {
|
|
270
|
+
marketingMatch['marketingDoc.isAppliedByCompany'] = isAppliedByCompany;
|
|
271
|
+
}
|
|
143
272
|
const result = await this.model.aggregate([
|
|
144
273
|
{
|
|
145
274
|
$match: { product: { $in: products }, deletedAt: null },
|
|
@@ -154,17 +283,36 @@ let ProductMarketingService = class ProductMarketingService {
|
|
|
154
283
|
},
|
|
155
284
|
{ $unwind: '$marketingDoc' },
|
|
156
285
|
{
|
|
157
|
-
$match:
|
|
158
|
-
'marketingDoc.status': enum_1.MarketingStatus.ACTIVE,
|
|
159
|
-
'marketingDoc.duration.start': { $lt: now },
|
|
160
|
-
'marketingDoc.duration.end': { $gt: now },
|
|
161
|
-
},
|
|
286
|
+
$match: marketingMatch,
|
|
162
287
|
},
|
|
163
288
|
{ $limit: 1 },
|
|
164
289
|
]);
|
|
165
290
|
const anyExist = result.length > 0;
|
|
166
291
|
return !anyExist;
|
|
167
292
|
}
|
|
293
|
+
async upsertProductMarketingsForPage(data) {
|
|
294
|
+
const { shop, marketingId, page, pageSize, isAppliedByCompany, isBuy1Get1, value, valueType } = data;
|
|
295
|
+
const products = await this.productModel
|
|
296
|
+
.find({ shop })
|
|
297
|
+
.select('_id')
|
|
298
|
+
.skip(page * pageSize)
|
|
299
|
+
.limit(pageSize)
|
|
300
|
+
.lean();
|
|
301
|
+
if (!products.length)
|
|
302
|
+
return [];
|
|
303
|
+
const ops = products.map(product => ({
|
|
304
|
+
updateOne: {
|
|
305
|
+
filter: { marketing: marketingId, product: product._id, deletedAt: null },
|
|
306
|
+
update: {
|
|
307
|
+
$set: { value, valueType, isAppliedByCompany, isBuy1Get1 },
|
|
308
|
+
$setOnInsert: { marketing: marketingId, product: product._id },
|
|
309
|
+
},
|
|
310
|
+
upsert: true,
|
|
311
|
+
},
|
|
312
|
+
}));
|
|
313
|
+
await this.model.bulkWrite(ops);
|
|
314
|
+
return products.map(p => p._id);
|
|
315
|
+
}
|
|
168
316
|
async countDocuments(filter) {
|
|
169
317
|
const count = await this.model.countDocuments({ ...filter, deletedAt: null });
|
|
170
318
|
return count ?? 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/product-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA+E;AAC/E,uEAA8G;AAS9G,wEAA6G;AAE7G,4DAAoE;AACpE,mGAGiD;AACjD,4EAA4E;AAGrE,IAAM,uBAAuB,GAA7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PCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport { ProductMarketingModel, ProductMarketing as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateProductMarketingDTO as CreateDTO,\n\tQueryProductMarketingDTO as QueryDTO,\n\tQueryMultipleProductMarketingDTO,\n\tUpdateProductMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { FilterDTO, PaginatedResponse } from '@lyxa.ai/core/dist/utilities/validation';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { MarketingStatus } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tSynchronizeProductMarketingService,\n\tsynchronizeProductMarketingService,\n} from './synchronize-product-marketing.service';\nimport { badRequestError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class ProductMarketingService {\n\tprivate model: typeof ProductMarketingModel & SoftDeleteModel<Model>;\n\n\tprivate syncProductsMarketingInfoService: SynchronizeProductMarketingService;\n\n\tconstructor() {\n\t\tthis.model = ProductMarketingModel as typeof ProductMarketingModel & SoftDeleteModel<Model>;\n\n\t\tthis.syncProductsMarketingInfoService = synchronizeProductMarketingService;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\t\tif (!result) badRequestError('Product marketing creation failed');\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductId(data.product);\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(id: string | mongoose.Types.ObjectId): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.findOne({\n\t\t\t_id: id,\n\t\t\tdeletedAt: null,\n\t\t});\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update single record based on query\n\t * @param query Query to find the record\n\t * @param data Data to update\n\t */\n\tpublic async updateOne(query: QueryDTO, data: UpdateDTO): Promise<string> {\n\t\tconst record = await this.model.findOneAndUpdate(query, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\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\treturn 'Records updated successfully';\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteMany(filter: QueryDTO, softDelete: boolean): Promise<string> {\n\t\tconst productMarketings = await this.model.find(filter);\n\n\t\tawait this.model.deleteRecords(filter, softDelete);\n\n\t\tconst productIds: mongoose.Types.ObjectId[] = productMarketings\n\t\t\t.map((r: any) => r.product)\n\t\t\t.filter((p: any): p is mongoose.Types.ObjectId | string => !!p) // filter out null/undefined\n\t\t\t.map((p: any) => (p instanceof mongoose.Types.ObjectId ? p : new mongoose.Types.ObjectId(p))); // convert to ObjectId\n\n\t\tconst uniqueProductIds = [...new Set(productIds.map((id: any) => new mongoose.Types.ObjectId(id)))];\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(uniqueProductIds);\n\n\t\treturn 'Record deleted successfully';\n\t}\n\n\tpublic async syncProductMarketingInfo(marketingId: mongoose.Types.ObjectId) {\n\t\tconst productMarketings = await this.model.find({ marketing: marketingId });\n\n\t\tconst productIds: mongoose.Types.ObjectId[] = productMarketings\n\t\t\t.map((r: any) => r.product)\n\t\t\t.filter((p: any): p is mongoose.Types.ObjectId | string => !!p) // filter out null/undefined\n\t\t\t.map((p: any) => (p instanceof mongoose.Types.ObjectId ? p : new mongoose.Types.ObjectId(p))); // convert to ObjectId\n\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(productIds);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteMultipleProducts(\n\t\tfilter: QueryMultipleProductMarketingDTO,\n\t\tsoftDelete: boolean\n\t): Promise<string> {\n\t\tconst result = await this.model.deleteRecords(\n\t\t\t{\n\t\t\t\tmarketing: filter.marketing,\n\t\t\t\tproduct: { $in: filter.products },\n\t\t\t},\n\t\t\tsoftDelete\n\t\t);\n\t\t// sync\n\t\treturn 'Record deleted successfully';\n\t}\n\n\t/**\n\t * Check if products are available for marketing\n\t * @param products Array of product IDs\n\t */\n\tpublic async checkProductMarketingAvailability(products: mongoose.Types.ObjectId[]): Promise<boolean> {\n\t\tconst now = new Date();\n\n\t\tconst result = await this.model.aggregate([\n\t\t\t{\n\t\t\t\t$match: { product: { $in: products }, deletedAt: null },\n\t\t\t},\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'marketings',\n\t\t\t\t\tlocalField: 'marketing',\n\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\tas: 'marketingDoc',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $unwind: '$marketingDoc' },\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t'marketingDoc.status': MarketingStatus.ACTIVE,\n\t\t\t\t\t'marketingDoc.duration.start': { $lt: now },\n\t\t\t\t\t'marketingDoc.duration.end': { $gt: now },\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $limit: 1 }, // stop as soon as one match is found\n\t\t]);\n\n\t\tconst anyExist = result.length > 0;\n\n\t\treturn !anyExist;\n\t}\n\n\tpublic async countDocuments(filter: QueryDTO): Promise<number> {\n\t\tconst count = await this.model.countDocuments({ ...filter, deletedAt: null });\n\t\treturn count ?? 0;\n\t}\n}\n\nexport const productMarketingService = Container.get(ProductMarketingService);\n"]}
|
|
1
|
+
{"version":3,"file":"product-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/product-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA+E;AAC/E,uEAIoD;AAUpD,wEAA6G;AAE7G,4DAA+E;AAC/E,mGAGiD;AACjD,4EAA4E;AAGrE,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAC3B,KAAK,CAAwD;IAC7D,YAAY,CAAsB;IAElC,gCAAgC,CAAqC;IAE7E;QACC,IAAI,CAAC,KAAK,GAAG,8BAA8E,CAAC;QAC5F,IAAI,CAAC,YAAY,GAAG,qBAAY,CAAC;QAEjC,IAAI,CAAC,gCAAgC,GAAG,0EAAkC,CAAC;IAC5E,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM;YAAE,IAAA,8BAAe,EAAC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MAAM,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE;gBACzE,MAAM,EAAE;oBACP,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE;oBAC1D,YAAY,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;iBAC9D;gBACD,MAAM,EAAE,IAAI;aACZ;SACD,CAAC,CAAC,CAAC;QAEJ,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QAEhC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAA8B,CAAC,CAAC;IAC5D,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,MAAgB;QAC3C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9E,OAAO,KAAK,IAAI,CAAC,CAAC;IACnB,CAAC;CACD,CAAA;AA5YY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,gBAAO,GAAE;;GACG,uBAAuB,CA4YnC;AAEY,QAAA,uBAAuB,GAAG,gBAAS,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport {\n\tProductMarketingModel,\n\tProductMarketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tBatchCreateProductMarketingsInputDTO,\n\tCreateProductMarketingDTO as CreateDTO,\n\tQueryProductMarketingDTO as QueryDTO,\n\tQueryMultipleProductMarketingDTO,\n\tUpdateProductMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { FilterDTO, PaginatedResponse } from '@lyxa.ai/core/dist/utilities/validation';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { MarketingStatus, ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tSynchronizeProductMarketingService,\n\tsynchronizeProductMarketingService,\n} from './synchronize-product-marketing.service';\nimport { badRequestError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class ProductMarketingService {\n\tprivate model: typeof ProductMarketingModel & SoftDeleteModel<Model>;\n\tprivate productModel: typeof ProductModel;\n\n\tprivate syncProductsMarketingInfoService: SynchronizeProductMarketingService;\n\n\tconstructor() {\n\t\tthis.model = ProductMarketingModel as typeof ProductMarketingModel & SoftDeleteModel<Model>;\n\t\tthis.productModel = ProductModel;\n\n\t\tthis.syncProductsMarketingInfoService = synchronizeProductMarketingService;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\t\tif (!result) badRequestError('Product marketing creation failed');\n\t\treturn result;\n\t}\n\n\t/**\n\t * Bulk create new records\n\t * @param data Data for the new records\n\t */\n\tpublic async bulkCreate(data: CreateDTO[]): Promise<void> {\n\t\tawait this.model.insertMany(data, { ordered: false });\n\t}\n\n\tpublic async bulkCreateFromCursor<T>(cursor: AsyncIterable<T>, mapper: (item: T) => any) {\n\t\tconst BATCH_SIZE = 500;\n\t\tconst batch = [];\n\n\t\tfor await (const item of cursor) {\n\t\t\tbatch.push(mapper(item));\n\n\t\t\tif (batch.length === BATCH_SIZE) {\n\t\t\t\tawait this.bulkCreate(batch);\n\t\t\t\tbatch.length = 0;\n\t\t\t}\n\t\t}\n\n\t\tif (batch.length) {\n\t\t\tawait this.bulkCreate(batch);\n\t\t}\n\t}\n\n\tpublic async bulkCreateFromArray<T>(items: Iterable<T>, mapper: (item: T) => any) {\n\t\tconst BATCH_SIZE = 500;\n\t\tconst batch = [];\n\n\t\tfor (const item of items) {\n\t\t\tbatch.push(mapper(item));\n\n\t\t\tif (batch.length === BATCH_SIZE) {\n\t\t\t\tawait this.bulkCreate(batch);\n\t\t\t\tbatch.length = 0;\n\t\t\t}\n\t\t}\n\n\t\tif (batch.length) {\n\t\t\tawait this.bulkCreate(batch);\n\t\t}\n\t}\n\n\tprivate async buildProductsMap(data: {\n\t\tproducts: {\n\t\t\tproduct: mongoose.Types.ObjectId;\n\t\t\tvalue?: number;\n\t\t\tvalueType?: ValueType | null;\n\t\t}[];\n\t\tisBuy1Get1: boolean;\n\t\tcategories?: mongoose.Types.ObjectId[];\n\t\tcategoryValue?: number;\n\t\tcategoryValueType?: ValueType;\n\t}): Promise<Record<string, { value?: number; valueType?: ValueType; isBuy1Get1?: boolean }>> {\n\t\tconst map: Record<string, { value?: number; valueType?: ValueType; isBuy1Get1?: boolean }> = {};\n\n\t\t// explicit products\n\t\tfor (const p of data.products || []) {\n\t\t\tif (data.isBuy1Get1) {\n\t\t\t\tmap[p.product.toString()] = {\n\t\t\t\t\tisBuy1Get1: true,\n\t\t\t\t};\n\t\t\t} else if (p.value !== undefined && p.valueType) {\n\t\t\t\tmap[p.product.toString()] = {\n\t\t\t\t\tvalue: Number(p.value),\n\t\t\t\t\tvalueType: p.valueType,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// category products\n\t\tif (data.categories?.length) {\n\t\t\tconst categoryProducts = await this.productModel\n\t\t\t\t.find({ shopCategory: { $in: data.categories } })\n\t\t\t\t.select('_id')\n\t\t\t\t.lean();\n\n\t\t\tfor (const p of categoryProducts) {\n\t\t\t\tconst id = p._id.toString();\n\t\t\t\tif (!map[id]) {\n\t\t\t\t\tif (data.isBuy1Get1) {\n\t\t\t\t\t\tmap[id.toString()] = {\n\t\t\t\t\t\t\tisBuy1Get1: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t} else if (data.categoryValue !== undefined && data.categoryValueType) {\n\t\t\t\t\t\tmap[id] = {\n\t\t\t\t\t\t\tvalue: Number(data.categoryValue),\n\t\t\t\t\t\t\tvalueType: data.categoryValueType,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn map;\n\t}\n\n\tpublic async createProductMarketings(data: BatchCreateProductMarketingsInputDTO): Promise<void> {\n\t\tconst {\n\t\t\tshop,\n\t\t\tmarketingId,\n\t\t\tproducts,\n\t\t\tcategories,\n\t\t\tisEntireMenu,\n\t\t\tisAppliedByCompany,\n\t\t\tcategoryValue,\n\t\t\tcategoryValueType,\n\t\t\tvalue,\n\t\t\tvalueType,\n\t\t\tisBuy1Get1,\n\t\t} = data;\n\n\t\tif (isEntireMenu) {\n\t\t\tawait this.bulkCreateFromCursor(\n\t\t\t\tthis.productModel.find({ shop }).select('_id').lean().cursor(),\n\t\t\t\tproduct => ({\n\t\t\t\t\tmarketing: marketingId,\n\t\t\t\t\tproduct: product._id,\n\t\t\t\t\tvalue,\n\t\t\t\t\tvalueType,\n\t\t\t\t\tisAppliedByCompany,\n\t\t\t\t\tisBuy1Get1,\n\t\t\t\t})\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst productsMap = await this.buildProductsMap({\n\t\t\tproducts: data.products,\n\t\t\tisBuy1Get1: data.isBuy1Get1,\n\t\t\tcategories: data.categories,\n\t\t\tcategoryValue: data.categoryValue,\n\t\t\tcategoryValueType: data.categoryValueType,\n\t\t});\n\n\t\tawait this.bulkCreateFromArray(Object.entries(productsMap), ([productId, info]) => ({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: new mongoose.Types.ObjectId(productId),\n\t\t\tvalue: info.value,\n\t\t\tvalueType: info.valueType,\n\t\t\tisAppliedByCompany,\n\t\t\tisBuy1Get1: info.isBuy1Get1,\n\t\t}));\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(id: string | mongoose.Types.ObjectId): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.findOne({\n\t\t\t_id: id,\n\t\t\tdeletedAt: null,\n\t\t});\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update single record based on query\n\t * @param query Query to find the record\n\t * @param data Data to update\n\t */\n\tpublic async updateOne(query: QueryDTO, data: UpdateDTO): Promise<string> {\n\t\tconst record = await this.model.findOneAndUpdate(query, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\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\treturn 'Records updated successfully';\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteMany(filter: QueryDTO, softDelete: boolean): Promise<string> {\n\t\tconst productMarketings = await this.model.find(filter);\n\n\t\tawait this.model.deleteRecords(filter, softDelete);\n\n\t\tconst productIds: mongoose.Types.ObjectId[] = productMarketings\n\t\t\t.map((r: any) => r.product)\n\t\t\t.filter((p: any): p is mongoose.Types.ObjectId | string => !!p) // filter out null/undefined\n\t\t\t.map((p: any) => (p instanceof mongoose.Types.ObjectId ? p : new mongoose.Types.ObjectId(p))); // convert to ObjectId\n\n\t\tconst uniqueProductIds = [...new Set(productIds.map((id: any) => new mongoose.Types.ObjectId(id)))];\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(uniqueProductIds);\n\n\t\treturn 'Record deleted successfully';\n\t}\n\n\tpublic async deleteManyByMarketingIds(marketingIds: mongoose.Types.ObjectId[], softDelete: boolean): Promise<void> {\n\t\tif (marketingIds.length === 0) return;\n\n\t\tconst productMarketings = await this.model\n\t\t\t.find({ marketing: { $in: marketingIds } })\n\t\t\t.select('product')\n\t\t\t.lean();\n\n\t\tawait this.model.deleteRecords({ marketing: { $in: marketingIds } }, softDelete);\n\n\t\tconst uniqueProductIds = [\n\t\t\t...new Map(\n\t\t\t\tproductMarketings\n\t\t\t\t\t.map((r: any) => r.product)\n\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t.map((p: any) => {\n\t\t\t\t\t\tconst id = p instanceof mongoose.Types.ObjectId ? p : new mongoose.Types.ObjectId(p);\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\tif (uniqueProductIds.length) {\n\t\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(uniqueProductIds);\n\t\t}\n\t}\n\n\tpublic async syncProductMarketingInfo(marketingId: mongoose.Types.ObjectId) {\n\t\tconst productMarketings = await this.model.find({ marketing: marketingId });\n\n\t\tconst productIds: mongoose.Types.ObjectId[] = productMarketings\n\t\t\t.map((r: any) => r.product)\n\t\t\t.filter((p: any): p is mongoose.Types.ObjectId | string => !!p) // filter out null/undefined\n\t\t\t.map((p: any) => (p instanceof mongoose.Types.ObjectId ? p : new mongoose.Types.ObjectId(p))); // convert to ObjectId\n\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(productIds);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteMultipleProducts(\n\t\tfilter: QueryMultipleProductMarketingDTO,\n\t\tsoftDelete: boolean\n\t): Promise<string> {\n\t\tconst result = await this.model.deleteRecords(\n\t\t\t{\n\t\t\t\tmarketing: filter.marketing,\n\t\t\t\tproduct: { $in: filter.products },\n\t\t\t},\n\t\t\tsoftDelete\n\t\t);\n\t\t// sync\n\t\treturn 'Record deleted successfully';\n\t}\n\n\t/**\n\t * Check if products are available for marketing\n\t * @param products Array of product IDs\n\t */\n\tpublic async checkProductMarketingAvailability(\n\t\tproducts: mongoose.Types.ObjectId[],\n\t\tisAppliedByCompany?: boolean\n\t): Promise<boolean> {\n\t\tconst now = new Date();\n\n\t\tconst marketingMatch: any = {\n\t\t\t'marketingDoc.status': MarketingStatus.ACTIVE,\n\t\t\t'marketingDoc.duration.start': { $lt: now },\n\t\t\t'marketingDoc.duration.end': { $gt: now },\n\t\t};\n\n\t\t// Only add this filter if explicitly provided\n\t\tif (typeof isAppliedByCompany === 'boolean') {\n\t\t\tmarketingMatch['marketingDoc.isAppliedByCompany'] = isAppliedByCompany;\n\t\t}\n\n\t\tconst result = await this.model.aggregate([\n\t\t\t{\n\t\t\t\t$match: { product: { $in: products }, deletedAt: null },\n\t\t\t},\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'marketings',\n\t\t\t\t\tlocalField: 'marketing',\n\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\tas: 'marketingDoc',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $unwind: '$marketingDoc' },\n\t\t\t{\n\t\t\t\t$match: marketingMatch,\n\t\t\t},\n\t\t\t{ $limit: 1 }, // stop as soon as one match is found\n\t\t]);\n\n\t\tconst anyExist = result.length > 0;\n\n\t\treturn !anyExist;\n\t}\n\n\tpublic async upsertProductMarketingsForPage(data: {\n\t\tshop: mongoose.Types.ObjectId;\n\t\tmarketingId: mongoose.Types.ObjectId;\n\t\tpage: number;\n\t\tpageSize: number;\n\t\tisAppliedByCompany: boolean;\n\t\tisBuy1Get1: boolean;\n\t\tvalue?: number;\n\t\tvalueType?: ValueType;\n\t}): Promise<mongoose.Types.ObjectId[]> {\n\t\tconst { shop, marketingId, page, pageSize, isAppliedByCompany, isBuy1Get1, value, valueType } = data;\n\n\t\tconst products = await this.productModel\n\t\t\t.find({ shop })\n\t\t\t.select('_id')\n\t\t\t.skip(page * pageSize)\n\t\t\t.limit(pageSize)\n\t\t\t.lean();\n\n\t\tif (!products.length) return [];\n\n\t\tconst ops = products.map(product => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { marketing: marketingId, product: product._id, deletedAt: null },\n\t\t\t\tupdate: {\n\t\t\t\t\t$set: { value, valueType, isAppliedByCompany, isBuy1Get1 },\n\t\t\t\t\t$setOnInsert: { marketing: marketingId, product: product._id },\n\t\t\t\t},\n\t\t\t\tupsert: true,\n\t\t\t},\n\t\t}));\n\n\t\tawait this.model.bulkWrite(ops);\n\n\t\treturn products.map(p => p._id as mongoose.Types.ObjectId);\n\t}\n\n\tpublic async countDocuments(filter: QueryDTO): Promise<number> {\n\t\tconst count = await this.model.countDocuments({ ...filter, deletedAt: null });\n\t\treturn count ?? 0;\n\t}\n}\n\nexport const productMarketingService = Container.get(ProductMarketingService);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronize-product-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/synchronize-product-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAKhD,OAAO,EAAE,6CAA6C,EAAE,MAAM,0FAA0F,CAAC;
|
|
1
|
+
{"version":3,"file":"synchronize-product-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/synchronize-product-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAKhD,OAAO,EAAE,6CAA6C,EAAE,MAAM,0FAA0F,CAAC;AAIzJ,qBACa,kCAAkC;IAC9C,OAAO,CAAC,YAAY,CAA+C;;IAMtD,kDAAkD;IAKxD,2CAA2C,CACjD,OAAO,EAAE,6CAA6C,GACpD,MAAM;IAKF,4BAA4B,QAAa,OAAO,CAAC,GAAG,CAAC,CAqC1D;YAEY,oBAAoB;YA2CpB,kCAAkC;IAsCnC,mCAAmC,CAAC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ;IAqCtE,oCAAoC,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE;CA6DvF;AAED,eAAO,MAAM,kCAAkC,oCAAoD,CAAC"}
|
|
@@ -48,6 +48,7 @@ const core_1 = require("@lyxa.ai/core");
|
|
|
48
48
|
const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models");
|
|
49
49
|
const product_pipeline_stages_1 = require("@lyxa.ai/core/dist/utilities/pipelines/product-pipeline-stages");
|
|
50
50
|
const events_common_methods_1 = require("@lyxa.ai/core/dist/utilities/events-common-methods");
|
|
51
|
+
const TAG = 'marketing.seed.entire-menu';
|
|
51
52
|
let SynchronizeProductMarketingService = class SynchronizeProductMarketingService {
|
|
52
53
|
productModel;
|
|
53
54
|
constructor() {
|
|
@@ -62,9 +63,8 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
62
63
|
return 'Processing all products product marketing information! ';
|
|
63
64
|
}
|
|
64
65
|
syncAllProductsMarketingInfo = async () => {
|
|
66
|
+
const logger = (0, core_1.getLibraries)().getLoggerKit();
|
|
65
67
|
const CHUNK_SIZE = 500;
|
|
66
|
-
console.time('TOTAL_SYNC_TIME');
|
|
67
|
-
console.log('[SYNC] Starting product marketing info sync');
|
|
68
68
|
const cursor = this.productModel.find().select('_id shop price priceBreakdowns').lean().cursor();
|
|
69
69
|
const adminSettings = (await (0, core_1.getLibraries)().getCachedSettingsService().getSettings());
|
|
70
70
|
const exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;
|
|
@@ -77,28 +77,23 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
77
77
|
if (batch.length === CHUNK_SIZE) {
|
|
78
78
|
batchIndex++;
|
|
79
79
|
totalProcessed += batch.length;
|
|
80
|
-
console.log(`[SYNC][BATCH ${batchIndex}] Processing ${batch.length} products (Total processed: ${totalProcessed})`);
|
|
81
|
-
console.time(`[BATCH ${batchIndex}] TIME`);
|
|
82
80
|
await this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);
|
|
83
|
-
console.timeEnd(`[BATCH ${batchIndex}] TIME`);
|
|
84
81
|
batch = [];
|
|
85
82
|
}
|
|
86
83
|
}
|
|
87
84
|
if (batch.length) {
|
|
88
85
|
batchIndex++;
|
|
89
86
|
totalProcessed += batch.length;
|
|
90
|
-
console.log(`[SYNC][BATCH ${batchIndex}] Processing remaining ${batch.length} products (Total processed: ${totalProcessed})`);
|
|
91
|
-
console.time(`[BATCH ${batchIndex}] TIME`);
|
|
92
87
|
await this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);
|
|
93
|
-
console.timeEnd(`[BATCH ${batchIndex}] TIME`);
|
|
94
88
|
}
|
|
95
|
-
|
|
96
|
-
|
|
89
|
+
logger.debug('full product marketing sync complete', {
|
|
90
|
+
tag: TAG,
|
|
91
|
+
data: { totalProducts: totalProcessed },
|
|
92
|
+
});
|
|
97
93
|
return 'Bulk product marketing info sync completed';
|
|
98
94
|
};
|
|
99
95
|
async processProductsBatch(productsBatch, exchangeRate, secondaryCurrencyName, batchIndex) {
|
|
100
96
|
const productIds = productsBatch.map(p => p._id);
|
|
101
|
-
console.log(`[BATCH ${batchIndex}] Aggregating marketing info for ${productIds.length} products`, `| First ID: ${productIds[0]}`, `| Last ID: ${productIds[productIds.length - 1]}`);
|
|
102
97
|
const results = await this.productModel.aggregate([
|
|
103
98
|
{ $match: { _id: { $in: productIds } } },
|
|
104
99
|
...(0, product_pipeline_stages_1.addProductMarketingInfo)(exchangeRate, secondaryCurrencyName),
|
|
@@ -109,7 +104,6 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
109
104
|
},
|
|
110
105
|
},
|
|
111
106
|
]);
|
|
112
|
-
console.log(`[BATCH ${batchIndex}] Aggregation completed. Result count: ${results.length}`);
|
|
113
107
|
const bulkOps = results.map(r => ({
|
|
114
108
|
updateOne: {
|
|
115
109
|
filter: { _id: r._id },
|
|
@@ -122,18 +116,14 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
122
116
|
value: pm.value,
|
|
123
117
|
secondaryCurrencyValue: pm.secondaryCurrencyValue,
|
|
124
118
|
label: pm.label,
|
|
119
|
+
isAppliedByCompany: pm.isAppliedByCompany ?? false,
|
|
125
120
|
})),
|
|
126
121
|
},
|
|
127
122
|
},
|
|
128
123
|
},
|
|
129
124
|
}));
|
|
130
125
|
if (bulkOps.length) {
|
|
131
|
-
console.log(`[BATCH ${batchIndex}] bulkWrite started (${bulkOps.length} ops)`);
|
|
132
126
|
await this.productModel.bulkWrite(bulkOps, { ordered: false });
|
|
133
|
-
console.log(`[BATCH ${batchIndex}] bulkWrite completed`);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
console.log(`[BATCH ${batchIndex}] No bulk operations to write`);
|
|
137
127
|
}
|
|
138
128
|
}
|
|
139
129
|
async getProductMarketingInfoByProductId(productId) {
|
|
@@ -163,6 +153,7 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
163
153
|
value: result?.[0].productMarketing.value,
|
|
164
154
|
secondaryCurrencyValue: result?.[0].productMarketing.secondaryCurrencyValue,
|
|
165
155
|
label: result?.[0].productMarketing.label,
|
|
156
|
+
isAppliedByCompany: result?.[0].productMarketing.isAppliedByCompany ?? false,
|
|
166
157
|
},
|
|
167
158
|
]
|
|
168
159
|
: [];
|
|
@@ -180,18 +171,17 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
180
171
|
},
|
|
181
172
|
...(0, product_pipeline_stages_1.addProductMarketingInfo)(exchangeRate, secondaryCurrencyName),
|
|
182
173
|
]);
|
|
183
|
-
const productMarketingInfo = result
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
: [];
|
|
174
|
+
const productMarketingInfo = (result || [])
|
|
175
|
+
.filter(item => item?.productMarketing)
|
|
176
|
+
.map(item => ({
|
|
177
|
+
marketing: item.productMarketing.marketingInfo,
|
|
178
|
+
isBuy1Get1: item.productMarketing.isBuy1Get1,
|
|
179
|
+
valueType: item.productMarketing.valueType,
|
|
180
|
+
value: item.productMarketing.value,
|
|
181
|
+
secondaryCurrencyValue: item.productMarketing.secondaryCurrencyValue,
|
|
182
|
+
label: item.productMarketing.label,
|
|
183
|
+
isAppliedByCompany: item.productMarketing.isAppliedByCompany ?? false,
|
|
184
|
+
}));
|
|
195
185
|
await this.productModel.updateOne({ _id: productId }, {
|
|
196
186
|
$set: {
|
|
197
187
|
productMarketingInfo,
|
|
@@ -200,8 +190,6 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
200
190
|
return 'Synchronized product marketing info';
|
|
201
191
|
}
|
|
202
192
|
async syncProductMarketingInfoByProductIds(productIds) {
|
|
203
|
-
console.time('SYNC_PRODUCT_IDS_TIME');
|
|
204
|
-
console.log(`Starting sync for ${productIds.length} product IDs`);
|
|
205
193
|
if (!productIds.length)
|
|
206
194
|
return 'No products to sync';
|
|
207
195
|
const adminSettings = (await (0, core_1.getLibraries)().getCachedSettingsService().getSettings());
|
|
@@ -210,13 +198,8 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
210
198
|
const BATCH_SIZE = 500;
|
|
211
199
|
const results = [];
|
|
212
200
|
const totalBatches = Math.ceil(productIds.length / BATCH_SIZE);
|
|
213
|
-
console.time('[ProductAggregate] Total Execution');
|
|
214
201
|
for (let i = 0; i < productIds.length; i += BATCH_SIZE) {
|
|
215
|
-
const batchIndex = i / BATCH_SIZE + 1;
|
|
216
202
|
const batchIds = productIds.slice(i, i + BATCH_SIZE);
|
|
217
|
-
const label = `[ProductAggregate] Batch ${batchIndex}/${totalBatches}`;
|
|
218
|
-
console.log(`${label} → starting (${batchIds.length} ids)`);
|
|
219
|
-
console.time(label);
|
|
220
203
|
const batchResults = await this.productModel.aggregate([
|
|
221
204
|
{
|
|
222
205
|
$match: {
|
|
@@ -224,28 +207,29 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
224
207
|
},
|
|
225
208
|
},
|
|
226
209
|
...(0, product_pipeline_stages_1.addProductMarketingInfo)(exchangeRate, secondaryCurrencyName),
|
|
210
|
+
{
|
|
211
|
+
$group: {
|
|
212
|
+
_id: '$_id',
|
|
213
|
+
productMarketingInfo: {
|
|
214
|
+
$push: '$productMarketing',
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
227
218
|
]);
|
|
228
|
-
console.timeEnd(label);
|
|
229
|
-
console.log(`${label} → completed (${batchResults.length} docs)`);
|
|
230
219
|
results.push(...batchResults);
|
|
231
220
|
}
|
|
232
|
-
console.timeEnd('[ProductAggregate] Total Execution');
|
|
233
|
-
console.log(`[ProductAggregate] Total results: ${results.length}`);
|
|
234
221
|
if (!results.length)
|
|
235
222
|
return 'No matching products found';
|
|
236
223
|
const bulkOps = results.map(product => {
|
|
237
|
-
const productMarketingInfo = product
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
},
|
|
247
|
-
]
|
|
248
|
-
: [];
|
|
224
|
+
const productMarketingInfo = (product.productMarketingInfo || []).map((pm) => ({
|
|
225
|
+
marketing: pm.marketingInfo,
|
|
226
|
+
isBuy1Get1: pm.isBuy1Get1,
|
|
227
|
+
valueType: pm.valueType,
|
|
228
|
+
value: pm.value,
|
|
229
|
+
secondaryCurrencyValue: pm.secondaryCurrencyValue,
|
|
230
|
+
label: pm.label,
|
|
231
|
+
isAppliedByCompany: pm.isAppliedByCompany ?? false,
|
|
232
|
+
}));
|
|
249
233
|
return {
|
|
250
234
|
updateOne: {
|
|
251
235
|
filter: { _id: product._id },
|
|
@@ -255,10 +239,7 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
255
239
|
},
|
|
256
240
|
};
|
|
257
241
|
});
|
|
258
|
-
console.timeEnd('SYNC_PRODUCT_IDS_TIME');
|
|
259
|
-
console.time('BULK_WRITE_TIME');
|
|
260
242
|
await this.productModel.bulkWrite(bulkOps);
|
|
261
|
-
console.timeEnd('BULK_WRITE_TIME');
|
|
262
243
|
return `Synchronized product marketing info for ${bulkOps.length} products`;
|
|
263
244
|
}
|
|
264
245
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronize-product-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/synchronize-product-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,wCAA6C;AAG7C,sEAAoG;AACpG,4GAAyG;AACzG,8FAAwH;AAGjH,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IACtC,YAAY,CAA+C;IAEnE;QACC,IAAI,CAAC,YAAY,GAAG,qBAA4D,CAAC;IAClF,CAAC;IAEM,KAAK,CAAC,kDAAkD;QAC9D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O,CAAC,gBAAgB,CAAC,KAAK;wBACrC,sBAAsB,EAAE,OAAO,CAAC,gBAAgB,CAAC,sBAAsB;wBACvE,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK;qBACrC;iBACD;gBACF,CAAC,CAAC,EAAE,CAAC;YAEN,OAAO;gBACN,SAAS,EAAE;oBACV,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;oBAC5B,MAAM,EAAE;wBACP,IAAI,EAAE,EAAE,oBAAoB,EAAE;qBAC9B;iBACD;aACD,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;QAEzC,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAChC,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAE3C,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAEnC,OAAO,2CAA2C,OAAO,CAAC,MAAM,WAAW,CAAC;IAC7E,CAAC;CACD,CAAA;AA5RY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,gBAAO,GAAE;;GACG,kCAAkC,CA4R9C;AAEY,QAAA,kCAAkC,GAAG,gBAAS,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { getLibraries } from '@lyxa.ai/core';\nimport { mongoose } from '@typegoose/typegoose';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { ProductModel, Product as Model, Setting } from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport { addProductMarketingInfo } from '@lyxa.ai/core/dist/utilities/pipelines/product-pipeline-stages';\nimport { publishAllProductsProductMarketingInfoProcessEvent } from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { SynchronizeAllProductsProductMarketingInfoDTO } from '@lyxa.ai/core/dist/libraries/event/events/sync-all-products-product-marketing-info-event';\n@Service()\nexport class SynchronizeProductMarketingService {\n\tprivate productModel: typeof ProductModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.productModel = ProductModel as typeof ProductModel & SoftDeleteModel<Model>;\n\t}\n\n\tpublic async publishAllProductsProductMarketingInfoProcessEvent() {\n\t\tawait publishAllProductsProductMarketingInfoProcessEvent({});\n\t\treturn 'Processing all products product marketing information! ';\n\t}\n\n\tpublic processAllProductsProductMarketingInfoEvent(\n\t\tpayload: SynchronizeAllProductsProductMarketingInfoDTO\n\t): string {\n\t\tthis.syncAllProductsMarketingInfo();\n\t\treturn 'Processing all products product marketing information! ';\n\t}\n\n\tpublic syncAllProductsMarketingInfo = async (): Promise<any> => {\n\t\tconst CHUNK_SIZE = 500;\n\n\t\tconsole.time('TOTAL_SYNC_TIME');\n\t\tconsole.log('[SYNC] Starting product marketing info sync');\n\n\t\tconst cursor = this.productModel.find().select('_id shop price priceBreakdowns').lean().cursor();\n\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tlet batch: any[] = [];\n\t\tlet batchIndex = 0;\n\t\tlet totalProcessed = 0;\n\n\t\tfor await (const product of cursor) {\n\t\t\tbatch.push(product);\n\n\t\t\tif (batch.length === CHUNK_SIZE) {\n\t\t\t\tbatchIndex++;\n\t\t\t\ttotalProcessed += batch.length;\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[SYNC][BATCH ${batchIndex}] Processing ${batch.length} products (Total processed: ${totalProcessed})`\n\t\t\t\t);\n\n\t\t\t\tconsole.time(`[BATCH ${batchIndex}] TIME`);\n\t\t\t\tawait this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);\n\t\t\t\tconsole.timeEnd(`[BATCH ${batchIndex}] TIME`);\n\n\t\t\t\tbatch = [];\n\t\t\t}\n\t\t}\n\n\t\t// Process remaining products\n\t\tif (batch.length) {\n\t\t\tbatchIndex++;\n\t\t\ttotalProcessed += batch.length;\n\n\t\t\tconsole.log(\n\t\t\t\t`[SYNC][BATCH ${batchIndex}] Processing remaining ${batch.length} products (Total processed: ${totalProcessed})`\n\t\t\t);\n\n\t\t\tconsole.time(`[BATCH ${batchIndex}] TIME`);\n\t\t\tawait this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);\n\t\t\tconsole.timeEnd(`[BATCH ${batchIndex}] TIME`);\n\t\t}\n\n\t\tconsole.log(`[SYNC] Completed. Total batches: ${batchIndex}, Total products: ${totalProcessed}`);\n\t\tconsole.timeEnd('TOTAL_SYNC_TIME');\n\n\t\treturn 'Bulk product marketing info sync completed';\n\t};\n\n\tprivate async processProductsBatch(\n\t\tproductsBatch: any[],\n\t\texchangeRate: number,\n\t\tsecondaryCurrencyName: string,\n\t\tbatchIndex: number\n\t): Promise<void> {\n\t\tconst productIds = productsBatch.map(p => p._id);\n\n\t\tconsole.log(\n\t\t\t`[BATCH ${batchIndex}] Aggregating marketing info for ${productIds.length} products`,\n\t\t\t`| First ID: ${productIds[0]}`,\n\t\t\t`| Last ID: ${productIds[productIds.length - 1]}`\n\t\t);\n\n\t\tconst results = await this.productModel.aggregate([\n\t\t\t{ $match: { _id: { $in: productIds } } },\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$_id',\n\t\t\t\t\tproductMarketingInfo: { $push: '$productMarketing' },\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\tconsole.log(`[BATCH ${batchIndex}] Aggregation completed. Result count: ${results.length}`);\n\n\t\tconst bulkOps = results.map(r => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { _id: r._id },\n\t\t\t\tupdate: {\n\t\t\t\t\t$set: {\n\t\t\t\t\t\tproductMarketingInfo: (r.productMarketingInfo ?? []).filter(Boolean).map((pm: any) => ({\n\t\t\t\t\t\t\tmarketing: pm.marketingInfo,\n\t\t\t\t\t\t\tisBuy1Get1: pm.isBuy1Get1,\n\t\t\t\t\t\t\tvalueType: pm.valueType,\n\t\t\t\t\t\t\tvalue: pm.value,\n\t\t\t\t\t\t\tsecondaryCurrencyValue: pm.secondaryCurrencyValue,\n\t\t\t\t\t\t\tlabel: pm.label,\n\t\t\t\t\t\t})),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}));\n\n\t\tif (bulkOps.length) {\n\t\t\tconsole.log(`[BATCH ${batchIndex}] bulkWrite started (${bulkOps.length} ops)`);\n\t\t\tawait this.productModel.bulkWrite(bulkOps, { ordered: false });\n\t\t\tconsole.log(`[BATCH ${batchIndex}] bulkWrite completed`);\n\t\t} else {\n\t\t\tconsole.log(`[BATCH ${batchIndex}] No bulk operations to write`);\n\t\t}\n\t}\n\n\tprivate async getProductMarketingInfoByProductId(productId: mongoose.Types.ObjectId): Promise<any[]> {\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tconst result = await this.productModel.aggregate([\n\t\t\t{\n\t\t\t\t$match: { _id: productId },\n\t\t\t},\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$_id',\n\t\t\t\t\tproductMarketingInfo: {\n\t\t\t\t\t\t$push: '$productMarketing',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\tconst productMarketingInfo = result?.[0]?.productMarketing\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tmarketing: result?.[0].productMarketing.marketingInfo,\n\t\t\t\t\t\tisBuy1Get1: result?.[0].productMarketing.isBuy1Get1,\n\t\t\t\t\t\tvalueType: result?.[0].productMarketing.valueType,\n\t\t\t\t\t\tvalue: result?.[0].productMarketing.value,\n\t\t\t\t\t\tsecondaryCurrencyValue: result?.[0].productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\tlabel: result?.[0].productMarketing.label,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\n\t\treturn productMarketingInfo;\n\t}\n\n\tpublic async syncProductMarketingInfoByProductId(productId: mongoose.Types.ObjectId) {\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\t\tconst result = await this.productModel.aggregate([\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t_id: productId,\n\t\t\t\t},\n\t\t\t},\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t]);\n\n\t\tconst productMarketingInfo = result?.[0]?.productMarketing\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tmarketing: result?.[0].productMarketing.marketingInfo,\n\t\t\t\t\t\tisBuy1Get1: result?.[0].productMarketing.isBuy1Get1,\n\t\t\t\t\t\tvalueType: result?.[0].productMarketing.valueType,\n\t\t\t\t\t\tvalue: result?.[0].productMarketing.value,\n\t\t\t\t\t\tsecondaryCurrencyValue: result?.[0].productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\tlabel: result?.[0].productMarketing.label,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\n\t\tawait this.productModel.updateOne(\n\t\t\t{ _id: productId },\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tproductMarketingInfo,\n\t\t\t\t},\n\t\t\t}\n\t\t);\n\t\treturn 'Synchronized product marketing info';\n\t}\n\n\tpublic async syncProductMarketingInfoByProductIds(productIds: mongoose.Types.ObjectId[]) {\n\t\tconsole.time('SYNC_PRODUCT_IDS_TIME');\n\t\tconsole.log(`Starting sync for ${productIds.length} product IDs`); // Debug log\n\t\tif (!productIds.length) return 'No products to sync';\n\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tconst BATCH_SIZE = 500;\n\t\tconst results: any[] = [];\n\n\t\tconst totalBatches = Math.ceil(productIds.length / BATCH_SIZE);\n\n\t\tconsole.time('[ProductAggregate] Total Execution');\n\n\t\tfor (let i = 0; i < productIds.length; i += BATCH_SIZE) {\n\t\t\tconst batchIndex = i / BATCH_SIZE + 1;\n\t\t\tconst batchIds = productIds.slice(i, i + BATCH_SIZE);\n\n\t\t\tconst label = `[ProductAggregate] Batch ${batchIndex}/${totalBatches}`;\n\n\t\t\tconsole.log(`${label} → starting (${batchIds.length} ids)`);\n\t\t\tconsole.time(label);\n\n\t\t\tconst batchResults = await this.productModel.aggregate([\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\t_id: { $in: batchIds },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t]);\n\n\t\t\tconsole.timeEnd(label);\n\t\t\tconsole.log(`${label} → completed (${batchResults.length} docs)`);\n\n\t\t\tresults.push(...batchResults);\n\t\t}\n\n\t\tconsole.timeEnd('[ProductAggregate] Total Execution');\n\n\t\tconsole.log(`[ProductAggregate] Total results: ${results.length}`);\n\n\t\tif (!results.length) return 'No matching products found';\n\n\t\tconst bulkOps = results.map(product => {\n\t\t\tconst productMarketingInfo = product?.productMarketing\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmarketing: product.productMarketing.marketingInfo,\n\t\t\t\t\t\t\tisBuy1Get1: product.productMarketing.isBuy1Get1,\n\t\t\t\t\t\t\tvalueType: product.productMarketing.valueType,\n\t\t\t\t\t\t\tvalue: product.productMarketing.value,\n\t\t\t\t\t\t\tsecondaryCurrencyValue: product.productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\t\tlabel: product.productMarketing.label,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [];\n\n\t\t\treturn {\n\t\t\t\tupdateOne: {\n\t\t\t\t\tfilter: { _id: product._id },\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\t$set: { productMarketingInfo },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\n\t\tconsole.timeEnd('SYNC_PRODUCT_IDS_TIME');\n\n\t\tconsole.time('BULK_WRITE_TIME');\n\t\tawait this.productModel.bulkWrite(bulkOps);\n\n\t\tconsole.timeEnd('BULK_WRITE_TIME');\n\n\t\treturn `Synchronized product marketing info for ${bulkOps.length} products`;\n\t}\n}\n\nexport const synchronizeProductMarketingService = Container.get(SynchronizeProductMarketingService);\n"]}
|
|
1
|
+
{"version":3,"file":"synchronize-product-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/synchronize-product-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,wCAA6C;AAG7C,sEAAoG;AACpG,4GAAyG;AACzG,8FAAwH;AAGxH,MAAM,GAAG,GAAG,4BAA4B,CAAC;AAGlC,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IACtC,YAAY,CAA+C;IAEnE;QACC,IAAI,CAAC,YAAY,GAAG,qBAA4D,CAAC;IAClF,CAAC;IAEM,KAAK,CAAC,kDAAkD;QAC9D,MAAM,IAAA,0EAAkD,EAAC,EAAE,CAAC,CAAC;QAC7D,OAAO,yDAAyD,CAAC;IAClE,CAAC;IAEM,2CAA2C,CACjD,OAAsD;QAEtD,IA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AAC,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAE3C,OAAO,2CAA2C,OAAO,CAAC,MAAM,WAAW,CAAC;IAC7E,CAAC;CACD,CAAA;AA7OY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,gBAAO,GAAE;;GACG,kCAAkC,CA6O9C;AAEY,QAAA,kCAAkC,GAAG,gBAAS,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { getLibraries } from '@lyxa.ai/core';\nimport { mongoose } from '@typegoose/typegoose';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { ProductModel, Product as Model, Setting } from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport { addProductMarketingInfo } from '@lyxa.ai/core/dist/utilities/pipelines/product-pipeline-stages';\nimport { publishAllProductsProductMarketingInfoProcessEvent } from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { SynchronizeAllProductsProductMarketingInfoDTO } from '@lyxa.ai/core/dist/libraries/event/events/sync-all-products-product-marketing-info-event';\n\nconst TAG = 'marketing.seed.entire-menu';\n\n@Service()\nexport class SynchronizeProductMarketingService {\n\tprivate productModel: typeof ProductModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.productModel = ProductModel as typeof ProductModel & SoftDeleteModel<Model>;\n\t}\n\n\tpublic async publishAllProductsProductMarketingInfoProcessEvent() {\n\t\tawait publishAllProductsProductMarketingInfoProcessEvent({});\n\t\treturn 'Processing all products product marketing information! ';\n\t}\n\n\tpublic processAllProductsProductMarketingInfoEvent(\n\t\tpayload: SynchronizeAllProductsProductMarketingInfoDTO\n\t): string {\n\t\tthis.syncAllProductsMarketingInfo();\n\t\treturn 'Processing all products product marketing information! ';\n\t}\n\n\tpublic syncAllProductsMarketingInfo = async (): Promise<any> => {\n\t\tconst logger = getLibraries().getLoggerKit();\n\t\tconst CHUNK_SIZE = 500;\n\n\t\tconst cursor = this.productModel.find().select('_id shop price priceBreakdowns').lean().cursor();\n\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tlet batch: any[] = [];\n\t\tlet batchIndex = 0;\n\t\tlet totalProcessed = 0;\n\n\t\tfor await (const product of cursor) {\n\t\t\tbatch.push(product);\n\n\t\t\tif (batch.length === CHUNK_SIZE) {\n\t\t\t\tbatchIndex++;\n\t\t\t\ttotalProcessed += batch.length;\n\t\t\t\tawait this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);\n\t\t\t\tbatch = [];\n\t\t\t}\n\t\t}\n\n\t\tif (batch.length) {\n\t\t\tbatchIndex++;\n\t\t\ttotalProcessed += batch.length;\n\t\t\tawait this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);\n\t\t}\n\n\t\tlogger.debug('full product marketing sync complete', {\n\t\t\ttag: TAG,\n\t\t\tdata: { totalProducts: totalProcessed },\n\t\t});\n\n\t\treturn 'Bulk product marketing info sync completed';\n\t};\n\n\tprivate async processProductsBatch(\n\t\tproductsBatch: any[],\n\t\texchangeRate: number,\n\t\tsecondaryCurrencyName: string,\n\t\tbatchIndex: number\n\t): Promise<void> {\n\t\tconst productIds = productsBatch.map(p => p._id);\n\n\t\tconst results = await this.productModel.aggregate([\n\t\t\t{ $match: { _id: { $in: productIds } } },\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$_id',\n\t\t\t\t\tproductMarketingInfo: { $push: '$productMarketing' },\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\tconst bulkOps = results.map(r => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { _id: r._id },\n\t\t\t\tupdate: {\n\t\t\t\t\t$set: {\n\t\t\t\t\t\tproductMarketingInfo: (r.productMarketingInfo ?? []).filter(Boolean).map((pm: any) => ({\n\t\t\t\t\t\t\tmarketing: pm.marketingInfo,\n\t\t\t\t\t\t\tisBuy1Get1: pm.isBuy1Get1,\n\t\t\t\t\t\t\tvalueType: pm.valueType,\n\t\t\t\t\t\t\tvalue: pm.value,\n\t\t\t\t\t\t\tsecondaryCurrencyValue: pm.secondaryCurrencyValue,\n\t\t\t\t\t\t\tlabel: pm.label,\n\t\t\t\t\t\t\tisAppliedByCompany: pm.isAppliedByCompany ?? false,\n\t\t\t\t\t\t})),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}));\n\n\t\tif (bulkOps.length) {\n\t\t\tawait this.productModel.bulkWrite(bulkOps, { ordered: false });\n\t\t}\n\t}\n\n\tprivate async getProductMarketingInfoByProductId(productId: mongoose.Types.ObjectId): Promise<any[]> {\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tconst result = await this.productModel.aggregate([\n\t\t\t{\n\t\t\t\t$match: { _id: productId },\n\t\t\t},\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$_id',\n\t\t\t\t\tproductMarketingInfo: {\n\t\t\t\t\t\t$push: '$productMarketing',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\tconst productMarketingInfo = result?.[0]?.productMarketing\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tmarketing: result?.[0].productMarketing.marketingInfo,\n\t\t\t\t\t\tisBuy1Get1: result?.[0].productMarketing.isBuy1Get1,\n\t\t\t\t\t\tvalueType: result?.[0].productMarketing.valueType,\n\t\t\t\t\t\tvalue: result?.[0].productMarketing.value,\n\t\t\t\t\t\tsecondaryCurrencyValue: result?.[0].productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\tlabel: result?.[0].productMarketing.label,\n\t\t\t\t\t\tisAppliedByCompany: result?.[0].productMarketing.isAppliedByCompany ?? false,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\n\t\treturn productMarketingInfo;\n\t}\n\n\tpublic async syncProductMarketingInfoByProductId(productId: mongoose.Types.ObjectId) {\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\t\tconst result = await this.productModel.aggregate([\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t_id: productId,\n\t\t\t\t},\n\t\t\t},\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t]);\n\n\t\tconst productMarketingInfo = (result || [])\n\t\t\t.filter(item => item?.productMarketing)\n\t\t\t.map(item => ({\n\t\t\t\tmarketing: item.productMarketing.marketingInfo,\n\t\t\t\tisBuy1Get1: item.productMarketing.isBuy1Get1,\n\t\t\t\tvalueType: item.productMarketing.valueType,\n\t\t\t\tvalue: item.productMarketing.value,\n\t\t\t\tsecondaryCurrencyValue: item.productMarketing.secondaryCurrencyValue,\n\t\t\t\tlabel: item.productMarketing.label,\n\t\t\t\tisAppliedByCompany: item.productMarketing.isAppliedByCompany ?? false,\n\t\t\t}));\n\n\t\tawait this.productModel.updateOne(\n\t\t\t{ _id: productId },\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tproductMarketingInfo,\n\t\t\t\t},\n\t\t\t}\n\t\t);\n\t\treturn 'Synchronized product marketing info';\n\t}\n\n\tpublic async syncProductMarketingInfoByProductIds(productIds: mongoose.Types.ObjectId[]) {\n\t\tif (!productIds.length) return 'No products to sync';\n\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tconst BATCH_SIZE = 500;\n\t\tconst results: any[] = [];\n\t\tconst totalBatches = Math.ceil(productIds.length / BATCH_SIZE);\n\n\t\tfor (let i = 0; i < productIds.length; i += BATCH_SIZE) {\n\t\t\tconst batchIds = productIds.slice(i, i + BATCH_SIZE);\n\n\t\t\tconst batchResults = await this.productModel.aggregate([\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\t_id: { $in: batchIds },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: '$_id',\n\t\t\t\t\t\tproductMarketingInfo: {\n\t\t\t\t\t\t\t$push: '$productMarketing',\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t]);\n\n\t\t\tresults.push(...batchResults);\n\t\t}\n\n\t\tif (!results.length) return 'No matching products found';\n\n\t\tconst bulkOps = results.map(product => {\n\t\t\tconst productMarketingInfo = (product.productMarketingInfo || []).map((pm: any) => ({\n\t\t\t\tmarketing: pm.marketingInfo,\n\t\t\t\tisBuy1Get1: pm.isBuy1Get1,\n\t\t\t\tvalueType: pm.valueType,\n\t\t\t\tvalue: pm.value,\n\t\t\t\tsecondaryCurrencyValue: pm.secondaryCurrencyValue,\n\t\t\t\tlabel: pm.label,\n\t\t\t\tisAppliedByCompany: pm.isAppliedByCompany ?? false,\n\t\t\t}));\n\n\t\t\treturn {\n\t\t\t\tupdateOne: {\n\t\t\t\t\tfilter: { _id: product._id },\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\t$set: { productMarketingInfo },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\n\t\tawait this.productModel.bulkWrite(bulkOps);\n\n\t\treturn `Synchronized product marketing info for ${bulkOps.length} products`;\n\t}\n}\n\nexport const synchronizeProductMarketingService = Container.get(SynchronizeProductMarketingService);\n"]}
|
|
@@ -9,16 +9,19 @@ export declare const buy1Get1MarketingTransformer: import("@lyxa.ai/core/dist/ut
|
|
|
9
9
|
isBuy1Get1: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
10
10
|
valueType: import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNativeEnum<typeof import("@lyxa.ai/core/dist/utilities/enum").ValueType>>>>;
|
|
11
11
|
value: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
12
|
+
isAppliedByCompany: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
12
13
|
}, "strip", import("zod").ZodTypeAny, {
|
|
13
14
|
product: import("mongoose").Types.ObjectId;
|
|
14
15
|
value?: number | undefined;
|
|
15
16
|
valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
|
|
17
|
+
isAppliedByCompany?: boolean | undefined;
|
|
16
18
|
marketing?: import("mongoose").Types.ObjectId | undefined;
|
|
17
19
|
isBuy1Get1?: boolean | undefined;
|
|
18
20
|
}, {
|
|
19
21
|
product: string | import("mongoose").Types.ObjectId;
|
|
20
22
|
value?: number | undefined;
|
|
21
23
|
valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
|
|
24
|
+
isAppliedByCompany?: boolean | undefined;
|
|
22
25
|
marketing?: string | import("mongoose").Types.ObjectId | undefined;
|
|
23
26
|
isBuy1Get1?: boolean | undefined;
|
|
24
27
|
}>, "many">>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buy1-get1-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/buy1-get1-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,+EAA+E,CAAC;AAM3H,eAAO,MAAM,4BAA4B
|
|
1
|
+
{"version":3,"file":"buy1-get1-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/buy1-get1-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,+EAA+E,CAAC;AAM3H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
|
|
@@ -13,16 +13,19 @@ export declare const discountMarketingTransformer: import("@lyxa.ai/core/dist/ut
|
|
|
13
13
|
isBuy1Get1: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
14
14
|
valueType: import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNativeEnum<typeof import("@lyxa.ai/core/dist/utilities/enum").ValueType>>>>;
|
|
15
15
|
value: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
16
|
+
isAppliedByCompany: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
16
17
|
}, "strip", import("zod").ZodTypeAny, {
|
|
17
18
|
product: import("mongoose").Types.ObjectId;
|
|
18
19
|
value?: number | undefined;
|
|
19
20
|
valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
|
|
21
|
+
isAppliedByCompany?: boolean | undefined;
|
|
20
22
|
marketing?: import("mongoose").Types.ObjectId | undefined;
|
|
21
23
|
isBuy1Get1?: boolean | undefined;
|
|
22
24
|
}, {
|
|
23
25
|
product: string | import("mongoose").Types.ObjectId;
|
|
24
26
|
value?: number | undefined;
|
|
25
27
|
valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
|
|
28
|
+
isAppliedByCompany?: boolean | undefined;
|
|
26
29
|
marketing?: string | import("mongoose").Types.ObjectId | undefined;
|
|
27
30
|
isBuy1Get1?: boolean | undefined;
|
|
28
31
|
}>, "many">>>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discount-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/discount-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,8EAA8E,CAAC;AAM1H,eAAO,MAAM,4BAA4B
|
|
1
|
+
{"version":3,"file":"discount-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/discount-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,8EAA8E,CAAC;AAM1H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
|