@lyxa.ai/marketing 1.0.62 → 1.0.63
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 +2 -0
- package/dist/lib/event/event-initializations.js.map +1 -1
- package/dist/lib/event/event-listeners/event-listeners.d.ts +2 -0
- package/dist/lib/event/event-listeners/event-listeners.d.ts.map +1 -1
- package/dist/lib/event/event-listeners/event-listeners.js +69 -12
- package/dist/lib/event/event-listeners/event-listeners.js.map +1 -1
- package/dist/lib/event/events/marketing-product-seed.event.d.ts +1 -2
- package/dist/lib/event/events/marketing-product-seed.event.d.ts.map +1 -1
- package/dist/lib/event/events/marketing-product-seed.event.js.map +1 -1
- package/dist/lib/event/events/marketing-product-sync.event.d.ts +11 -0
- package/dist/lib/event/events/marketing-product-sync.event.d.ts.map +1 -0
- package/dist/lib/event/events/marketing-product-sync.event.js +12 -0
- package/dist/lib/event/events/marketing-product-sync.event.js.map +1 -0
- package/dist/lib/index.d.ts +533 -18
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +5 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js +4 -1
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js.map +1 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.js +4 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.js.map +1 -1
- package/dist/lib/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
- package/dist/lib/modules/featured-setting/services/featured-setting.service.js +3 -0
- package/dist/lib/modules/featured-setting/services/featured-setting.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts +54 -8
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js +11 -0
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js +6 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +0 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js +2 -6
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +16 -3
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js +22 -3
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +2 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js +12 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +242 -35
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js +19 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +8 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js +64 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +3 -0
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js +66 -8
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js +37 -19
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +249 -18
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts +2 -0
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js +15 -3
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
- package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js +1 -1
- package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +24 -3
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js +19 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +10 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js +43 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +195 -10
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js +29 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js.map +1 -1
- 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 +427 -32
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js +16 -6
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +7 -4
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js +42 -7
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +15 -3
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js +84 -18
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts +13 -0
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.js +75 -0
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts +21 -0
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.js +83 -0
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.js.map +1 -0
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts +1 -0
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -1
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js +29 -0
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts +14 -0
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.js +5 -0
- package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
- package/dist/lib/modules/marketing/services/index.d.ts +3 -0
- package/dist/lib/modules/marketing/services/index.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/index.js +3 -0
- package/dist/lib/modules/marketing/services/index.js.map +1 -1
- package/dist/lib/modules/marketing/services/marketing-conflict.repository.d.ts +9 -0
- package/dist/lib/modules/marketing/services/marketing-conflict.repository.d.ts.map +1 -0
- package/dist/lib/modules/marketing/services/marketing-conflict.repository.js +63 -0
- package/dist/lib/modules/marketing/services/marketing-conflict.repository.js.map +1 -0
- package/dist/lib/modules/marketing/services/marketing-conflict.service.d.ts +28 -0
- package/dist/lib/modules/marketing/services/marketing-conflict.service.d.ts.map +1 -0
- package/dist/lib/modules/marketing/services/marketing-conflict.service.js +139 -0
- package/dist/lib/modules/marketing/services/marketing-conflict.service.js.map +1 -0
- package/dist/lib/modules/marketing/services/marketing.service.d.ts +7 -2
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +100 -51
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +2 -3
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.js +42 -13
- package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/spend-to-get-marketing.repository.d.ts +14 -0
- package/dist/lib/modules/marketing/services/spend-to-get-marketing.repository.d.ts.map +1 -0
- package/dist/lib/modules/marketing/services/spend-to-get-marketing.repository.js +82 -0
- package/dist/lib/modules/marketing/services/spend-to-get-marketing.repository.js.map +1 -0
- package/dist/lib/modules/marketing/services/spend-to-get-marketing.service.d.ts +11 -0
- package/dist/lib/modules/marketing/services/spend-to-get-marketing.service.d.ts.map +1 -0
- package/dist/lib/modules/marketing/services/spend-to-get-marketing.service.js +100 -0
- package/dist/lib/modules/marketing/services/spend-to-get-marketing.service.js.map +1 -0
- package/dist/lib/modules/marketing/services/spend-to-get-progress.repository.d.ts +9 -0
- package/dist/lib/modules/marketing/services/spend-to-get-progress.repository.d.ts.map +1 -0
- package/dist/lib/modules/marketing/services/spend-to-get-progress.repository.js +69 -0
- package/dist/lib/modules/marketing/services/spend-to-get-progress.repository.js.map +1 -0
- package/dist/lib/modules/marketing/services/spend-to-get-progress.service.d.ts +31 -0
- package/dist/lib/modules/marketing/services/spend-to-get-progress.service.d.ts.map +1 -0
- package/dist/lib/modules/marketing/services/spend-to-get-progress.service.js +123 -0
- package/dist/lib/modules/marketing/services/spend-to-get-progress.service.js.map +1 -0
- 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 +95 -27
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/validations/all-marketings.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/all-marketings.validation.js +3 -0
- package/dist/lib/modules/marketing/validations/all-marketings.validation.js.map +1 -1
- package/dist/lib/modules/marketing/validations/index.d.ts +1 -0
- package/dist/lib/modules/marketing/validations/index.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/index.js +1 -0
- package/dist/lib/modules/marketing/validations/index.js.map +1 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.d.ts +17 -0
- package/dist/lib/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.js +7 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.js.map +1 -1
- package/dist/lib/modules/marketing/validations/spend-to-get-marketing.validation.d.ts +617 -0
- package/dist/lib/modules/marketing/validations/spend-to-get-marketing.validation.d.ts.map +1 -0
- package/dist/lib/modules/marketing/validations/spend-to-get-marketing.validation.js +119 -0
- package/dist/lib/modules/marketing/validations/spend-to-get-marketing.validation.js.map +1 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.d.ts +24 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.d.ts.map +1 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.js +97 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.js.map +1 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.router.d.ts +271 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.router.d.ts.map +1 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.router.js +62 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.router.js.map +1 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.d.ts +24 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.d.ts.map +1 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.js +116 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.js.map +1 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.d.ts +232 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.d.ts.map +1 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.js +30 -0
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.js.map +1 -0
- package/dist/types/event/event-initializations.d.ts.map +1 -1
- package/dist/types/event/event-listeners/event-listeners.d.ts +2 -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 +1 -2
- package/dist/types/event/events/marketing-product-seed.event.d.ts.map +1 -1
- package/dist/types/event/events/marketing-product-sync.event.d.ts +11 -0
- package/dist/types/event/events/marketing-product-sync.event.d.ts.map +1 -0
- package/dist/types/index.d.ts +533 -18
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
- package/dist/types/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts +54 -8
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +0 -1
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +16 -3
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +2 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +242 -35
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +8 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +3 -0
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +249 -18
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts +2 -0
- package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +24 -3
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +10 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +195 -10
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- 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 +427 -32
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +7 -4
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +15 -3
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts +13 -0
- package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts +21 -0
- package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts.map +1 -0
- package/dist/types/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts +1 -0
- package/dist/types/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -1
- package/dist/types/modules/marketing/routers/marketing.router.d.ts +14 -0
- package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/index.d.ts +3 -0
- package/dist/types/modules/marketing/services/index.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/marketing-conflict.repository.d.ts +9 -0
- package/dist/types/modules/marketing/services/marketing-conflict.repository.d.ts.map +1 -0
- package/dist/types/modules/marketing/services/marketing-conflict.service.d.ts +46 -0
- package/dist/types/modules/marketing/services/marketing-conflict.service.d.ts.map +1 -0
- package/dist/types/modules/marketing/services/marketing.service.d.ts +7 -2
- package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts +7 -3
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/spend-to-get-marketing.repository.d.ts +14 -0
- package/dist/types/modules/marketing/services/spend-to-get-marketing.repository.d.ts.map +1 -0
- package/dist/types/modules/marketing/services/spend-to-get-marketing.service.d.ts +20 -0
- package/dist/types/modules/marketing/services/spend-to-get-marketing.service.d.ts.map +1 -0
- package/dist/types/modules/marketing/services/spend-to-get-progress.repository.d.ts +9 -0
- package/dist/types/modules/marketing/services/spend-to-get-progress.repository.d.ts.map +1 -0
- package/dist/types/modules/marketing/services/spend-to-get-progress.service.d.ts +37 -0
- package/dist/types/modules/marketing/services/spend-to-get-progress.service.d.ts.map +1 -0
- package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/all-marketings.validation.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/index.d.ts +1 -0
- package/dist/types/modules/marketing/validations/index.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/marketing.validation.d.ts +17 -0
- package/dist/types/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/spend-to-get-marketing.validation.d.ts +630 -0
- package/dist/types/modules/marketing/validations/spend-to-get-marketing.validation.d.ts.map +1 -0
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.repository.d.ts +24 -0
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.repository.d.ts.map +1 -0
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.router.d.ts +271 -0
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.router.d.ts.map +1 -0
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.service.d.ts +56 -0
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.service.d.ts.map +1 -0
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.validation.d.ts +241 -0
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.validation.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.ltoCampaignSessionRepository = exports.LtoCampaignSessionRepository = void 0;
|
|
46
|
+
const typedi_1 = __importStar(require("typedi"));
|
|
47
|
+
const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models");
|
|
48
|
+
let LtoCampaignSessionRepository = class LtoCampaignSessionRepository {
|
|
49
|
+
model;
|
|
50
|
+
constructor() {
|
|
51
|
+
this.model = models_1.LimitedTimeOfferCampaignSessionModel;
|
|
52
|
+
}
|
|
53
|
+
async create(data) {
|
|
54
|
+
return this.model.create(data);
|
|
55
|
+
}
|
|
56
|
+
async findByCampaign(campaignId, page, size) {
|
|
57
|
+
const [documents, total] = await Promise.all([
|
|
58
|
+
this.model
|
|
59
|
+
.find({ campaign: campaignId })
|
|
60
|
+
.sort({ archivedAt: -1 })
|
|
61
|
+
.skip((page - 1) * size)
|
|
62
|
+
.limit(size)
|
|
63
|
+
.lean(),
|
|
64
|
+
this.model.countDocuments({ campaign: campaignId }),
|
|
65
|
+
]);
|
|
66
|
+
return { documents, total };
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.LtoCampaignSessionRepository = LtoCampaignSessionRepository;
|
|
70
|
+
exports.LtoCampaignSessionRepository = LtoCampaignSessionRepository = __decorate([
|
|
71
|
+
(0, typedi_1.Service)(),
|
|
72
|
+
__metadata("design:paramtypes", [])
|
|
73
|
+
], LtoCampaignSessionRepository);
|
|
74
|
+
exports.ltoCampaignSessionRepository = typedi_1.default.get(LtoCampaignSessionRepository);
|
|
75
|
+
//# sourceMappingURL=limited-time-offer-campaign-session.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limited-time-offer-campaign-session.repository.js","sourceRoot":"/","sources":["modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,sEAGmD;AAG5C,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAC7B,KAAK,CAA8C;IAE3D;QACI,IAAI,CAAC,KAAK,GAAG,6CAAoC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAY;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAQ,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,cAAc,CAChB,UAAmC,EACnC,IAAY,EACZ,IAAY;QAEZ,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACzC,IAAI,CAAC,KAAK;iBACL,IAAI,CAAC,EAAC,QAAQ,EAAE,UAAU,EAAC,CAAC;iBAC5B,IAAI,CAAC,EAAC,UAAU,EAAE,CAAC,CAAC,EAAC,CAAC;iBACtB,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;iBACvB,KAAK,CAAC,IAAI,CAAC;iBACX,IAAI,EAAS;YAClB,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAC,QAAQ,EAAE,UAAU,EAAC,CAAC;SACpD,CAAC,CAAC;QACH,OAAO,EAAC,SAAS,EAAE,KAAK,EAAC,CAAC;IAC9B,CAAC;CACJ,CAAA;AA3BY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,gBAAO,GAAE;;GACG,4BAA4B,CA2BxC;AAEY,QAAA,4BAA4B,GAAG,gBAAS,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {mongoose} from '@typegoose/typegoose';\nimport {\n LimitedTimeOfferCampaignSession as Model,\n LimitedTimeOfferCampaignSessionModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\n\n@Service()\nexport class LtoCampaignSessionRepository {\n private model: typeof LimitedTimeOfferCampaignSessionModel;\n\n constructor() {\n this.model = LimitedTimeOfferCampaignSessionModel;\n }\n\n async create(data: object): Promise<InstanceType<typeof Model>> {\n return this.model.create(data) as any;\n }\n\n async findByCampaign(\n campaignId: mongoose.Types.ObjectId,\n page: number,\n size: number,\n ): Promise<{documents: InstanceType<typeof Model>[]; total: number}> {\n const [documents, total] = await Promise.all([\n this.model\n .find({campaign: campaignId})\n .sort({archivedAt: -1})\n .skip((page - 1) * size)\n .limit(size)\n .lean() as any,\n this.model.countDocuments({campaign: campaignId}),\n ]);\n return {documents, total};\n }\n}\n\nexport const ltoCampaignSessionRepository = Container.get(LtoCampaignSessionRepository);\n"]}
|
package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DocumentType, mongoose } from '@typegoose/typegoose';
|
|
2
|
+
import { LimitedTimeOfferCampaign } from '@lyxa.ai/core/dist/libraries/mongo/models';
|
|
3
|
+
export interface LtoCampaignSessionItemDTO {
|
|
4
|
+
_id: mongoose.Types.ObjectId;
|
|
5
|
+
campaign: mongoose.Types.ObjectId;
|
|
6
|
+
startDate: Date;
|
|
7
|
+
endDate: Date;
|
|
8
|
+
shopCount: number;
|
|
9
|
+
archivedAt: Date;
|
|
10
|
+
}
|
|
11
|
+
export declare class LtoCampaignSessionService {
|
|
12
|
+
private repository;
|
|
13
|
+
constructor();
|
|
14
|
+
logSession(campaign: DocumentType<LimitedTimeOfferCampaign>, shopCount: number): Promise<void>;
|
|
15
|
+
getSessionsByCampaign(campaignId: mongoose.Types.ObjectId, page: number, size: number): Promise<{
|
|
16
|
+
documents: LtoCampaignSessionItemDTO[];
|
|
17
|
+
total: number;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export declare const ltoCampaignSessionService: LtoCampaignSessionService;
|
|
21
|
+
//# sourceMappingURL=limited-time-offer-campaign-session.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limited-time-offer-campaign-session.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/session/limited-time-offer-campaign-session.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAC,wBAAwB,EAAC,MAAM,2CAA2C,CAAC;AAGnF,MAAM,WAAW,yBAAyB;IACtC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IAC7B,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;IAClC,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,IAAI,CAAC;CACpB;AAED,qBACa,yBAAyB;IAClC,OAAO,CAAC,UAAU,CAA+B;;IAMpC,UAAU,CACnB,QAAQ,EAAE,YAAY,CAAC,wBAAwB,CAAC,EAChD,SAAS,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC;IAUH,qBAAqB,CAC9B,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACnC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACb,OAAO,CAAC;QAAC,SAAS,EAAE,yBAAyB,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAC;CActE;AAED,eAAO,MAAM,yBAAyB,2BAA2C,CAAC"}
|
package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.ltoCampaignSessionService = exports.LtoCampaignSessionService = void 0;
|
|
46
|
+
const typedi_1 = __importStar(require("typedi"));
|
|
47
|
+
const limited_time_offer_campaign_session_repository_1 = require("./limited-time-offer-campaign-session.repository");
|
|
48
|
+
let LtoCampaignSessionService = class LtoCampaignSessionService {
|
|
49
|
+
repository;
|
|
50
|
+
constructor() {
|
|
51
|
+
this.repository = typedi_1.default.get(limited_time_offer_campaign_session_repository_1.LtoCampaignSessionRepository);
|
|
52
|
+
}
|
|
53
|
+
async logSession(campaign, shopCount) {
|
|
54
|
+
await this.repository.create({
|
|
55
|
+
campaign: campaign._id,
|
|
56
|
+
startDate: campaign.startDate,
|
|
57
|
+
endDate: campaign.endDate,
|
|
58
|
+
shopCount,
|
|
59
|
+
archivedAt: new Date(),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async getSessionsByCampaign(campaignId, page, size) {
|
|
63
|
+
const { documents, total } = await this.repository.findByCampaign(campaignId, page, size);
|
|
64
|
+
return {
|
|
65
|
+
documents: documents.map((d) => ({
|
|
66
|
+
_id: d._id,
|
|
67
|
+
campaign: d.campaign,
|
|
68
|
+
startDate: d.startDate,
|
|
69
|
+
endDate: d.endDate,
|
|
70
|
+
shopCount: d.shopCount ?? 0,
|
|
71
|
+
archivedAt: d.archivedAt,
|
|
72
|
+
})),
|
|
73
|
+
total,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
exports.LtoCampaignSessionService = LtoCampaignSessionService;
|
|
78
|
+
exports.LtoCampaignSessionService = LtoCampaignSessionService = __decorate([
|
|
79
|
+
(0, typedi_1.Service)(),
|
|
80
|
+
__metadata("design:paramtypes", [])
|
|
81
|
+
], LtoCampaignSessionService);
|
|
82
|
+
exports.ltoCampaignSessionService = typedi_1.default.get(LtoCampaignSessionService);
|
|
83
|
+
//# sourceMappingURL=limited-time-offer-campaign-session.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limited-time-offer-campaign-session.service.js","sourceRoot":"/","sources":["modules/limited-time-offer/session/limited-time-offer-campaign-session.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAG1C,qHAA8F;AAYvF,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAC1B,UAAU,CAA+B;IAEjD;QACI,IAAI,CAAC,UAAU,GAAG,gBAAS,CAAC,GAAG,CAAC,6EAA4B,CAAC,CAAC;IAClE,CAAC;IAEM,KAAK,CAAC,UAAU,CACnB,QAAgD,EAChD,SAAiB;QAEjB,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YACzB,QAAQ,EAAE,QAAQ,CAAC,GAAG;YACtB,SAAS,EAAE,QAAQ,CAAC,SAAS;YAC7B,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,SAAS;YACT,UAAU,EAAE,IAAI,IAAI,EAAE;SACzB,CAAC,CAAC;IACP,CAAC;IAEM,KAAK,CAAC,qBAAqB,CAC9B,UAAmC,EACnC,IAAY,EACZ,IAAY;QAEZ,MAAM,EAAC,SAAS,EAAE,KAAK,EAAC,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QACxF,OAAO;YACH,SAAS,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC;gBAClC,GAAG,EAAE,CAAC,CAAC,GAAG;gBACV,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC;gBAC3B,UAAU,EAAE,CAAC,CAAC,UAAU;aAC3B,CAAC,CAAC;YACH,KAAK;SACR,CAAC;IACN,CAAC;CACJ,CAAA;AAtCY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,gBAAO,GAAE;;GACG,yBAAyB,CAsCrC;AAEY,QAAA,yBAAyB,GAAG,gBAAS,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {DocumentType, mongoose} from '@typegoose/typegoose';\nimport {LimitedTimeOfferCampaign} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {LtoCampaignSessionRepository} from './limited-time-offer-campaign-session.repository';\n\nexport interface LtoCampaignSessionItemDTO {\n _id: mongoose.Types.ObjectId;\n campaign: mongoose.Types.ObjectId;\n startDate: Date;\n endDate: Date;\n shopCount: number;\n archivedAt: Date;\n}\n\n@Service()\nexport class LtoCampaignSessionService {\n private repository: LtoCampaignSessionRepository;\n\n constructor() {\n this.repository = Container.get(LtoCampaignSessionRepository);\n }\n\n public async logSession(\n campaign: DocumentType<LimitedTimeOfferCampaign>,\n shopCount: number,\n ): Promise<void> {\n await this.repository.create({\n campaign: campaign._id,\n startDate: campaign.startDate,\n endDate: campaign.endDate,\n shopCount,\n archivedAt: new Date(),\n });\n }\n\n public async getSessionsByCampaign(\n campaignId: mongoose.Types.ObjectId,\n page: number,\n size: number,\n ): Promise<{documents: LtoCampaignSessionItemDTO[]; total: number}> {\n const {documents, total} = await this.repository.findByCampaign(campaignId, page, size);\n return {\n documents: documents.map((d: any) => ({\n _id: d._id,\n campaign: d.campaign,\n startDate: d.startDate,\n endDate: d.endDate,\n shopCount: d.shopCount ?? 0,\n archivedAt: d.archivedAt,\n })),\n total,\n };\n }\n}\n\nexport const ltoCampaignSessionService = Container.get(LtoCampaignSessionService);\n"]}
|
|
@@ -17,6 +17,7 @@ export declare class MarketingMetricsRepository {
|
|
|
17
17
|
}>;
|
|
18
18
|
private calculateItemBasedSpent;
|
|
19
19
|
private calculateFreeDeliverySpent;
|
|
20
|
+
private calculateSpendToGetSpent;
|
|
20
21
|
private calculatePunchMarketingSpent;
|
|
21
22
|
private buildBaseMatch;
|
|
22
23
|
private runAggregateAndGetTotal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarketingMetricsRepository.d.ts","sourceRoot":"/","sources":["modules/marketing/patterns/repository/MarketingMetricsRepository.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAEN,QAAQ,EACR,SAAS,EAGT,YAAY,EAEZ,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAEN,sBAAsB,EACtB,mBAAmB,EACnB,6BAA6B,EAC7B,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC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,EACpC,QAAQ,CAAC,EAAE,QAAQ,GACjB,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,aAAa,CAAA;KAAE,CAAC;YA+B9C,uBAAuB;YA2CvB,0BAA0B;YAyB1B,wBAAwB;YAyBxB,4BAA4B;IAsB1C,OAAO,CAAC,cAAc;YAkBR,uBAAuB;IAKxB,UAAU,CAAC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAyC7E,qBAAqB;YAKrB,kCAAkC;YA2BlC,qCAAqC;IAcnD,OAAO,CAAC,iBAAiB;YAWX,sBAAsB;IA8BvB,cAAc,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAwDpF,iBAAiB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAsF3F,mBAAmB,CAC/B,IAAI,EAAE,sBAAsB,GAC1B,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAoL9C;AAED,eAAO,MAAM,0BAA0B,4BAA4C,CAAC"}
|
|
@@ -91,6 +91,11 @@ let MarketingMetricsRepository = class MarketingMetricsRepository {
|
|
|
91
91
|
addSpend(marketingId._id, order.adjustedFinance.pricing.punchMarketingDiscount);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
+
if (order.adjustedFinance?.spendToGet) {
|
|
95
|
+
for (const marketingId of order.marketings ?? []) {
|
|
96
|
+
addSpend(marketingId._id, getRelevantAmount(marketingId._id, order.adjustedFinance.spendToGet.companyCut ?? 0, order.adjustedFinance.spendToGet.shopCut ?? 0));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
94
99
|
return spendMap;
|
|
95
100
|
}
|
|
96
101
|
async calculateMarketingSpent(marketingId, duration) {
|
|
@@ -103,6 +108,7 @@ let MarketingMetricsRepository = class MarketingMetricsRepository {
|
|
|
103
108
|
[enum_2.MarketingType.DISCOUNT]: () => this.calculateItemBasedSpent(marketingId, marketing.isAppliedByCompany, duration),
|
|
104
109
|
[enum_2.MarketingType.BUY1GET1]: () => this.calculateItemBasedSpent(marketingId, marketing.isAppliedByCompany, duration),
|
|
105
110
|
[enum_2.MarketingType.PUNCH_MARKETING]: () => this.calculatePunchMarketingSpent(marketingId, duration),
|
|
111
|
+
[enum_2.MarketingType.SPEND_TO_GET]: () => this.calculateSpendToGetSpent(marketingId, duration),
|
|
106
112
|
[enum_2.MarketingType.FEATURED]: function () {
|
|
107
113
|
return Promise.resolve(marketing.amount || 0);
|
|
108
114
|
},
|
|
@@ -166,6 +172,25 @@ let MarketingMetricsRepository = class MarketingMetricsRepository {
|
|
|
166
172
|
];
|
|
167
173
|
return this.runAggregateAndGetTotal(pipeline, 'totalSpent');
|
|
168
174
|
}
|
|
175
|
+
async calculateSpendToGetSpent(marketingId, duration) {
|
|
176
|
+
const pipeline = [
|
|
177
|
+
this.buildBaseMatch(marketingId, duration),
|
|
178
|
+
{
|
|
179
|
+
$group: {
|
|
180
|
+
_id: null,
|
|
181
|
+
totalSpent: {
|
|
182
|
+
$sum: {
|
|
183
|
+
$add: [
|
|
184
|
+
{ $ifNull: ['$adjustedFinance.spendToGet.companyCut', 0] },
|
|
185
|
+
{ $ifNull: ['$adjustedFinance.spendToGet.shopCut', 0] },
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
];
|
|
192
|
+
return this.runAggregateAndGetTotal(pipeline, 'totalSpent');
|
|
193
|
+
}
|
|
169
194
|
async calculatePunchMarketingSpent(marketingId, duration) {
|
|
170
195
|
const pipeline = [
|
|
171
196
|
this.buildBaseMatch(marketingId, duration),
|
|
@@ -216,6 +241,10 @@ let MarketingMetricsRepository = class MarketingMetricsRepository {
|
|
|
216
241
|
}
|
|
217
242
|
metrics.orderIncreaseWithDiscount = await this.calculateOrderIncreaseWithDiscount(marketingId, marketing.shop._id, currentDuration, previousDuration);
|
|
218
243
|
metrics.customerIncreaseWithDiscount = await this.calculateCustomerIncreaseWithDiscount(marketingId, marketing.shop._id, currentDuration, previousDuration);
|
|
244
|
+
metrics.totalRedemptions = await this.orderModel.countDocuments({
|
|
245
|
+
marketings: marketingId,
|
|
246
|
+
status: { $ne: enum_1.RegularOrderStatus.CANCELLED },
|
|
247
|
+
});
|
|
219
248
|
return metrics;
|
|
220
249
|
}
|
|
221
250
|
async getMarketingItemCount(marketingId) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarketingMetricsRepository.js","sourceRoot":"/","sources":["modules/marketing/patterns/repository/MarketingMetricsRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,8DAA2D;AAC3D,oDAA+E;AAC/E,sEAQmD;AAQnD,4DAA6F;AAC7F,qGAAgG;AAChG,4DAAkE;AAClE,4EAA0E;AAE1E,4DAAiE;AACjE,0CAAoD;AAG7C,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAC9B,KAAK,CAAiD;IACtD,UAAU,CAA2D;IAE7E;QACC,IAAI,CAAC,KAAK,GAAG,uBAAgE,CAAC;QAC9E,IAAI,CAAC,UAAU,GAAG,0BAA6E,CAAC;IACjG,CAAC;IAEM,+BAA+B,CACrC,KAGC;QAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmC,CAAC;QAE5D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAA8B,CAAC;QAGhE,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YAChD,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,SAAS,CAAC,k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CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QAEpF,OAAO,IAAA,0BAAkB,EAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE;YAC3E,MAAM,EAAE,CAAC;SACT,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAtqBY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,gBAAO,GAAE;;GACG,0BAA0B,CAsqBtC;AAEY,QAAA,0BAA0B,GAAG,gBAAS,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport {\n\tFeaturedMarketing,\n\tLineItem,\n\tMarketing,\n\tMarketingModel,\n\tMarketing as Model,\n\tRegularOrder,\n\tRegularOrderModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tIncreaseDuringDiscountDTO,\n\tMarketingGraphInputDTO,\n\tMarketingMetricsDTO,\n\tMarketingOrdersGraphOutputDTO,\n} from '@modules/marketing/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { GraphType, OrderType, RegularOrderStatus } from '@lyxa.ai/core/dist/utilities/enum';\nimport { productMarketingService } from '@modules/marketing/services/product-marketing.service';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\nimport { Duration } from '@lyxa.ai/core/dist/libraries/mongo/models/shared/duration.model';\nimport { LyxaTimezone } from '@lyxa.ai/core/dist/utilities/time';\nimport { fillMissingPeriods } from '@utility/utils';\n\n@Service()\nexport class MarketingMetricsRepository {\n\tprivate model: typeof MarketingModel & SoftDeleteModel<Model>;\n\tprivate orderModel: typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\n\tconstructor() {\n\t\tthis.model = MarketingModel as typeof MarketingModel & SoftDeleteModel<Model>;\n\t\tthis.orderModel = RegularOrderModel as typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\t}\n\n\tpublic calculateMarketingSpendPerOrder(\n\t\torder: DocumentType<RegularOrder> & {\n\t\t\tlineItems: DocumentType<LineItem>[];\n\t\t\tmarketings: DocumentType<Marketing>[];\n\t\t}\n\t): Map<mongoose.Types.ObjectId, number> {\n\t\tconst spendMap = new Map<mongoose.Types.ObjectId, number>();\n\n\t\tconst marketingOwnerMap = new Map<string, 'COMPANY' | 'SHOP'>();\n\n\t\t// Build owner map\n\t\tfor (const marketing of order.marketings ?? []) {\n\t\t\tmarketingOwnerMap.set(marketing._id.toString(), marketing.isAppliedByCompany ? 'COMPANY' : 'SHOP');\n\t\t}\n\n\t\tconst addSpend = (marketingId: mongoose.Types.ObjectId, amount: number) => {\n\t\t\tif (!amount || amount <= 0) return;\n\t\t\tspendMap.set(marketingId, (spendMap.get(marketingId) ?? 0) + amount);\n\t\t};\n\n\t\tconst getRelevantAmount = (\n\t\t\tmarketingId: mongoose.Types.ObjectId,\n\t\t\tcompanyAmount: number,\n\t\t\tshopAmount: number\n\t\t) => {\n\t\t\tconst owner = marketingOwnerMap.get(marketingId.toString());\n\t\t\treturn owner === 'COMPANY' ? companyAmount : shopAmount;\n\t\t};\n\n\t\t/**\n\t\t * ITEM-BASED\n\t\t */\n\t\tfor (const lineItem of order.lineItems ?? []) {\n\t\t\tfor (const marketingId of lineItem.marketings ?? []) {\n\t\t\t\tconst snap = lineItem.calculationSnap ?? {};\n\n\t\t\t\taddSpend(\n\t\t\t\t\tmarketingId._id,\n\t\t\t\t\tgetRelevantAmount(\n\t\t\t\t\t\tmarketingId._id,\n\t\t\t\t\t\t(Number(snap.itemDiscountByCompany) || 0) + (Number(snap.b1g1DiscountByCompany) || 0),\n\t\t\t\t\t\t(Number(snap.itemDiscountByShop) || 0) + (Number(snap.b1g1DiscountByShop) || 0)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * FREE DELIVERY\n\t\t */\n\t\tif (order.adjustedFinance?.freeDelivery) {\n\t\t\tfor (const marketingId of order.marketings ?? []) {\n\t\t\t\taddSpend(\n\t\t\t\t\tmarketingId._id,\n\t\t\t\t\tgetRelevantAmount(\n\t\t\t\t\t\tmarketingId._id,\n\t\t\t\t\t\torder.adjustedFinance.freeDelivery.companyCut ?? 0,\n\t\t\t\t\t\torder.adjustedFinance.freeDelivery.shopCut ?? 0\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * PUNCH MARKETING\n\t\t */\n\t\tif (order.adjustedFinance?.pricing?.punchMarketingDiscount) {\n\t\t\tfor (const marketingId of order.marketings ?? []) {\n\t\t\t\taddSpend(marketingId._id, order.adjustedFinance.pricing.punchMarketingDiscount);\n\t\t\t}\n\t\t}\n\n\t\treturn spendMap;\n\t}\n\n\tpublic async calculateMarketingSpent(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tduration?: Duration\n\t): Promise<{ amount: number; marketingType: MarketingType }> {\n\t\tconst marketing = await this.model.findById(marketingId).lean();\n\n\t\tif (!marketing) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\n\t\tconst calculators: Record<MarketingType, () => Promise<number>> = {\n\t\t\t[MarketingType.FREE_DELIVERY]: () => this.calculateFreeDeliverySpent(marketingId, duration),\n\n\t\t\t[MarketingType.DISCOUNT]: () =>\n\t\t\t\tthis.calculateItemBasedSpent(marketingId, marketing.isAppliedByCompany, duration),\n\n\t\t\t[MarketingType.BUY1GET1]: () =>\n\t\t\t\tthis.calculateItemBasedSpent(marketingId, marketing.isAppliedByCompany, duration),\n\n\t\t\t[MarketingType.PUNCH_MARKETING]: () => this.calculatePunchMarketingSpent(marketingId, duration),\n\t\t\t[MarketingType.FEATURED]: function (): Promise<number> {\n\t\t\t\treturn Promise.resolve((marketing as DocumentType<FeaturedMarketing>).amount || 0);\n\t\t\t},\n\t\t};\n\n\t\tconst amount = calculators[marketing.marketingType] ? await calculators[marketing.marketingType]() : 0;\n\n\t\treturn {\n\t\t\tamount,\n\t\t\tmarketingType: marketing.marketingType,\n\t\t};\n\t}\n\n\tprivate async calculateItemBasedSpent(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tisAppliedByAdmin: boolean,\n\t\tduration?: Duration\n\t): Promise<number> {\n\t\tconst addBlock = isAppliedByAdmin\n\t\t\t? [\n\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.itemDiscountByCompany', 0] },\n\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByCompany', 0] },\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.itemDiscountByShop', 0] },\n\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByShop', 0] },\n\t\t\t\t];\n\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\tthis.buildBaseMatch(marketingId, duration),\n\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'lineItems',\n\t\t\t\t\tlocalField: 'cart',\n\t\t\t\t\tforeignField: 'cart',\n\t\t\t\t\tas: 'lineItems',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $unwind: '$lineItems' },\n\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: null,\n\t\t\t\t\ttotalSpent: {\n\t\t\t\t\t\t$sum: {\n\t\t\t\t\t\t\t$add: addBlock,\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 this.runAggregateAndGetTotal(pipeline, 'totalSpent');\n\t}\n\n\tprivate async calculateFreeDeliverySpent(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tduration?: Duration\n\t): Promise<number> {\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\tthis.buildBaseMatch(marketingId, duration),\n\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: null,\n\t\t\t\t\ttotalSpent: {\n\t\t\t\t\t\t$sum: {\n\t\t\t\t\t\t\t$add: [\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.freeDelivery.companyCut', 0] },\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.freeDelivery.shopCut', 0] },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\treturn this.runAggregateAndGetTotal(pipeline, 'totalSpent');\n\t}\n\n\tprivate async calculatePunchMarketingSpent(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tduration?: Duration\n\t): Promise<number> {\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\tthis.buildBaseMatch(marketingId, duration),\n\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: null,\n\t\t\t\t\ttotalSpent: {\n\t\t\t\t\t\t$sum: {\n\t\t\t\t\t\t\t$ifNull: ['$adjustedFinance.pricing.punchMarketingDiscount', 0],\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 this.runAggregateAndGetTotal(pipeline, 'totalSpent');\n\t}\n\n\tprivate buildBaseMatch(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tduration?: Duration\n\t): mongoose.PipelineStage.Match {\n\t\treturn {\n\t\t\t$match: {\n\t\t\t\tmarketings: marketingId,\n\t\t\t\tstatus: { $ne: RegularOrderStatus.CANCELLED },\n\t\t\t\t...(duration && {\n\t\t\t\t\tprocessedAt: {\n\t\t\t\t\t\t$gte: duration.start,\n\t\t\t\t\t\t$lte: duration.end,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async runAggregateAndGetTotal(pipeline: mongoose.PipelineStage[], field: string): Promise<number> {\n\t\tconst [result] = await this.orderModel.aggregate(pipeline);\n\t\treturn result?.[field] ?? 0;\n\t}\n\n\tpublic async getMetrics(marketingId: mongoose.Types.ObjectId): Promise<MarketingMetricsDTO> {\n\t\tconst marketing = await this.model.findById(marketingId).lean();\n\n\t\tif (!marketing) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\n\t\t//TODO: fix current end and previous start\n\n\t\tconst currentDuration = { start: marketing.duration.start, end: dayjs().toDate() };\n\t\tconst previousDuration = {\n\t\t\tstart: dayjs(marketing.duration.start).subtract(dayjs().diff(marketing.duration.start)).toDate(),\n\t\t\tend: marketing.duration.start,\n\t\t};\n\n\t\tlet metrics: MarketingMetricsDTO = {};\n\n\t\tif ([MarketingType.DISCOUNT, MarketingType.BUY1GET1].includes(marketing.marketingType)) {\n\t\t\tmetrics.numberOfItems = await this.getMarketingItemCount(marketingId);\n\t\t}\n\n\t\tmetrics.orderIncreaseWithDiscount = await this.calculateOrderIncreaseWithDiscount(\n\t\t\tmarketingId,\n\t\t\tmarketing.shop._id,\n\t\t\tcurrentDuration,\n\t\t\tpreviousDuration\n\t\t);\n\t\tmetrics.customerIncreaseWithDiscount = await this.calculateCustomerIncreaseWithDiscount(\n\t\t\tmarketingId,\n\t\t\tmarketing.shop._id,\n\t\t\tcurrentDuration,\n\t\t\tpreviousDuration\n\t\t);\n\n\t\treturn metrics;\n\t}\n\n\tprivate async getMarketingItemCount(marketingId: mongoose.Types.ObjectId): Promise<number> {\n\t\tconst result = await productMarketingService.countDocuments({ marketing: marketingId });\n\t\treturn result ?? 0;\n\t}\n\n\tprivate async calculateOrderIncreaseWithDiscount(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tcurrentDuration: Duration,\n\t\tpreviousDuration: Duration\n\t): Promise<IncreaseDuringDiscountDTO> {\n\t\tconst [currentOrders, previousOrders] = await Promise.all([\n\t\t\tthis.orderModel.countDocuments({\n\t\t\t\tcreatedAt: {\n\t\t\t\t\t$gte: currentDuration.start,\n\t\t\t\t\t$lte: currentDuration.end,\n\t\t\t\t},\n\t\t\t\tmarketings: marketingId, // marketing must be applied\n\t\t\t\tshop: shopId,\n\t\t\t}),\n\t\t\tthis.orderModel.countDocuments({\n\t\t\t\tcreatedAt: {\n\t\t\t\t\t$gte: previousDuration.start,\n\t\t\t\t\t$lte: previousDuration.end,\n\t\t\t\t},\n\t\t\t\tshop: shopId,\n\t\t\t}),\n\t\t]);\n\n\t\treturn this.calculateIncrease(currentOrders, previousOrders);\n\t}\n\n\tprivate async calculateCustomerIncreaseWithDiscount(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tcurrentDuration: Duration,\n\t\tpreviousDuration: Duration\n\t): Promise<IncreaseDuringDiscountDTO> {\n\t\tconst [currentNewCustomers, previousNewCustomers] = await Promise.all([\n\t\t\tthis.getNewCustomersForShop(shopId, currentDuration, { marketings: marketingId }),\n\t\t\tthis.getNewCustomersForShop(shopId, previousDuration),\n\t\t]);\n\n\t\treturn this.calculateIncrease(currentNewCustomers, previousNewCustomers);\n\t}\n\n\tprivate calculateIncrease(current: number, previous: number): IncreaseDuringDiscountDTO {\n\t\tconst count = current - previous;\n\n\t\tconst percentageIncrease = previous === 0 ? (current > 0 ? 100 : 0) : (count / previous) * 100;\n\n\t\treturn {\n\t\t\tcount,\n\t\t\tpercentageIncrease,\n\t\t};\n\t}\n\n\tprivate async getNewCustomersForShop(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tduration: Duration,\n\t\textraMatch: Record<string, any> = {}\n\t): Promise<number> {\n\t\t// Customers who ordered during the period\n\t\tconst customersInPeriod = await this.orderModel.distinct('user', {\n\t\t\tcreatedAt: {\n\t\t\t\t$gte: duration.start,\n\t\t\t\t$lte: duration.end,\n\t\t\t},\n\t\t\tshop: shopId,\n\t\t\t...extraMatch,\n\t\t});\n\n\t\tif (customersInPeriod.length === 0) {\n\t\t\treturn 0;\n\t\t}\n\n\t\t// Customers who had ordered from this shop BEFORE the period\n\t\tconst existingCustomers = await this.orderModel.distinct('user', {\n\t\t\tshop: shopId,\n\t\t\tcreatedAt: { $lt: duration.start },\n\t\t\tuser: { $in: customersInPeriod },\n\t\t});\n\n\t\t// New customers = in period − existing\n\t\treturn customersInPeriod.length - existingCustomers.length;\n\t}\n\n\tpublic async getOrdersGraph(data: MarketingGraphInputDTO): Promise<MarketingOrdersGraphOutputDTO> {\n\t\tconst dateFormat = data.type === GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';\n\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\t// Filter only delivered orders within the given date range\n\t\t\tthis.buildBaseMatch(new mongoose.Types.ObjectId(data.marketingId), {\n\t\t\t\tstart: data.startDate,\n\t\t\t\tend: data.endDate,\n\t\t\t}),\n\n\t\t\t// Extract formatted date from 'processedAt' for grouping\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\tdate: {\n\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\tdate: '$processedAt',\n\t\t\t\t\t\t\ttimezone: LyxaTimezone,\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\t// Group by formatted date and count orders\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$date',\n\t\t\t\t\torders: { $sum: 1 },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Sort results chronologically\n\t\t\t{\n\t\t\t\t$sort: { _id: 1 },\n\t\t\t},\n\n\t\t\t// Format the response to match output DTO structure\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\t_id: 0,\n\t\t\t\t\tdate: '$_id',\n\t\t\t\t\torders: 1,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\t// Execute aggregation pipeline\n\t\tconst results = await this.orderModel.aggregate(pipeline).allowDiskUse(true).exec();\n\n\t\tconst graphData = fillMissingPeriods(results, data.startDate, data.endDate, data.type, {\n\t\t\torders: 0,\n\t\t});\n\n\t\treturn graphData;\n\t}\n\n\tpublic async getCustomersGraph(data: MarketingGraphInputDTO): Promise<{ date: string; users: number }[]> {\n\t\t// 1️⃣ Get shopId from marketing\n\t\tconst marketing = await this.model.findById(data.marketingId).select('shop').lean();\n\n\t\tif (!marketing) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\n\t\tconst shopId = marketing.shop._id;\n\n\t\t// 2️⃣ Fetch users who ordered from this shop BEFORE the start date\n\t\tconst oldUsers = await this.orderModel.distinct('user', {\n\t\t\tshop: shopId,\n\t\t\tstatus: RegularOrderStatus.DELIVERED,\n\t\t\tprocessedAt: { $lt: data.startDate },\n\t\t});\n\n\t\tconst dateFormat = data.type === GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';\n\n\t\t// 3️⃣ Aggregation pipeline\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\t// Orders during the period with this marketing\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\torderType: OrderType.REGULAR,\n\t\t\t\t\tstatus: RegularOrderStatus.DELIVERED,\n\t\t\t\t\tshop: shopId,\n\t\t\t\t\tmarketings: new mongoose.Types.ObjectId(data.marketingId),\n\t\t\t\t\tprocessedAt: { $gte: data.startDate, $lte: data.endDate },\n\t\t\t\t\tuser: { $nin: oldUsers }, // 🚫 exclude old users\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Sort so earliest order per user comes first\n\t\t\t{ $sort: { processedAt: 1 } },\n\n\t\t\t// First order per user (new users only)\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$user',\n\t\t\t\t\tfirstOrderDate: { $first: '$processedAt' },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Format date\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\tdate: {\n\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\tdate: '$firstOrderDate',\n\t\t\t\t\t\t\ttimezone: LyxaTimezone,\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\t// Group by date\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$date',\n\t\t\t\t\tusers: { $sum: 1 },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Sort chronologically\n\t\t\t{ $sort: { _id: 1 } },\n\n\t\t\t// Shape response\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\t_id: 0,\n\t\t\t\t\tdate: '$_id',\n\t\t\t\t\tusers: 1,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\tconst results = await this.orderModel.aggregate(pipeline).allowDiskUse(true).exec();\n\n\t\t// 4️⃣ Fill missing periods\n\t\treturn fillMissingPeriods(results, data.startDate, data.endDate, data.type, {\n\t\t\tusers: 0,\n\t\t});\n\t}\n\n\tpublic async getAmountSpentGraph(\n\t\tdata: MarketingGraphInputDTO\n\t): Promise<{ date: string; amount: number }[]> {\n\t\tconst marketing = await this.model.findById(data.marketingId).lean();\n\n\t\tif (!marketing) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\n\t\tconst marketingId = new mongoose.Types.ObjectId(data.marketingId);\n\t\tconst dateFormat = data.type === GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';\n\n\t\tlet pipeline: mongoose.PipelineStage[] | null = null;\n\n\t\t/**\n\t\t * ITEM-BASED (DISCOUNT / BUY1GET1)\n\t\t */\n\t\tif ([MarketingType.DISCOUNT, MarketingType.BUY1GET1].includes(marketing.marketingType)) {\n\t\t\tpipeline = [\n\t\t\t\tthis.buildBaseMatch(marketingId, {\n\t\t\t\t\tstart: data.startDate,\n\t\t\t\t\tend: data.endDate,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\t$lookup: {\n\t\t\t\t\t\tfrom: 'lineItems',\n\t\t\t\t\t\tlocalField: 'cart',\n\t\t\t\t\t\tforeignField: 'cart',\n\t\t\t\t\t\tas: 'lineItems',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ $unwind: '$lineItems' },\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\t'lineItems.marketings': marketingId,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\tdate: {\n\t\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\t\tdate: '$processedAt',\n\t\t\t\t\t\t\t\ttimezone: LyxaTimezone,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tamount: {\n\t\t\t\t\t\t\t$add: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\tmarketing.isAppliedByCompany,\n\t\t\t\t\t\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.itemDiscountByCompany', 0] },\n\t\t\t\t\t\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.itemDiscountByShop', 0] },\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\tmarketing.isAppliedByCompany,\n\t\t\t\t\t\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByCompany', 0] },\n\t\t\t\t\t\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByShop', 0] },\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: '$date',\n\t\t\t\t\t\tamount: { $sum: '$amount' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ $sort: { _id: 1 } },\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\tdate: '$_id',\n\t\t\t\t\t\tamount: 1,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else if (marketing.marketingType === MarketingType.FREE_DELIVERY) {\n\t\t\t/**\n\t\t\t * FREE DELIVERY\n\t\t\t */\n\t\t\tpipeline = [\n\t\t\t\tthis.buildBaseMatch(marketingId, {\n\t\t\t\t\tstart: data.startDate,\n\t\t\t\t\tend: data.endDate,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\tdate: {\n\t\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\t\tdate: '$processedAt',\n\t\t\t\t\t\t\t\ttimezone: LyxaTimezone,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tamount: {\n\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\tmarketing.isAppliedByCompany,\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.freeDelivery.companyCut', 0] },\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.freeDelivery.shopCut', 0] },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: '$date',\n\t\t\t\t\t\tamount: { $sum: '$amount' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ $sort: { _id: 1 } },\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\tdate: '$_id',\n\t\t\t\t\t\tamount: 1,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else if (marketing.marketingType === MarketingType.PUNCH_MARKETING) {\n\t\t\t/**\n\t\t\t * PUNCH MARKETING\n\t\t\t */\n\t\t\tpipeline = [\n\t\t\t\tthis.buildBaseMatch(marketingId, {\n\t\t\t\t\tstart: data.startDate,\n\t\t\t\t\tend: data.endDate,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\tdate: {\n\t\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\t\tdate: '$processedAt',\n\t\t\t\t\t\t\t\ttimezone: LyxaTimezone,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tamount: {\n\t\t\t\t\t\t\t$ifNull: ['$adjustedFinance.pricing.punchMarketingDiscount', 0],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: '$date',\n\t\t\t\t\t\tamount: { $sum: '$amount' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ $sort: { _id: 1 } },\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\tdate: '$_id',\n\t\t\t\t\t\tamount: 1,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\t// If marketing type doesn't produce spend graph → return empty graph\n\t\tif (!pipeline) {\n\t\t\treturn fillMissingPeriods(\n\t\t\t\t[] as { date: string; amount: number }[],\n\t\t\t\tdata.startDate,\n\t\t\t\tdata.endDate,\n\t\t\t\tdata.type,\n\t\t\t\t{\n\t\t\t\t\tamount: 0,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tconst results = await this.orderModel.aggregate(pipeline).allowDiskUse(true).exec();\n\n\t\treturn fillMissingPeriods(results, data.startDate, data.endDate, data.type, {\n\t\t\tamount: 0,\n\t\t});\n\t}\n}\n\nexport const marketingMetricsRepository = Container.get(MarketingMetricsRepository);\n"]}
|
|
1
|
+
{"version":3,"file":"MarketingMetricsRepository.js","sourceRoot":"/","sources":["modules/marketing/patterns/repository/MarketingMetricsRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,8DAA2D;AAC3D,oDAA+E;AAC/E,sEAQmD;AAQnD,4DAA6F;AAC7F,qGAAgG;AAChG,4DAAkE;AAClE,4EAA0E;AAE1E,4DAAiE;AACjE,0CAAoD;AAG7C,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;IAC9B,KAAK,CAAiD;IACtD,UAAU,CAA2D;IAE7E;QACC,IAAI,CAAC,KAAK,GAAG,uBAAgE,CAAC;QAC9E,IAAI,CAAC,UAAU,GAAG,0BAA6E,CAAC;IACjG,CAAC;IAEM,+BAA+B,CACrC,KAGC;QAED,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmC,CAAC;QAE5D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAA8B,CAAC;QAGhE,KAAK,MAAM,SAAS,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YAChD,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;QACpG,CAAC;QAED,MAAM,QAAQ,GAAG,CAAC,WAAoC,EAAE,MAAc,EAAE,EAAE;YACzE,IAAI,CAAC,MAAM,IAAI,MAAM,IAAI,CAAC;gBAAE,OAAO;YACnC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC;QACtE,CAAC,CAAC;QAEF,MAAM,iBAAiB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ayjs';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport {\n\tFeaturedMarketing,\n\tLineItem,\n\tMarketing,\n\tMarketingModel,\n\tMarketing as Model,\n\tRegularOrder,\n\tRegularOrderModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tIncreaseDuringDiscountDTO,\n\tMarketingGraphInputDTO,\n\tMarketingMetricsDTO,\n\tMarketingOrdersGraphOutputDTO,\n} from '@modules/marketing/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { GraphType, OrderType, RegularOrderStatus } from '@lyxa.ai/core/dist/utilities/enum';\nimport { productMarketingService } from '@modules/marketing/services/product-marketing.service';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\nimport { Duration } from '@lyxa.ai/core/dist/libraries/mongo/models/shared/duration.model';\nimport { LyxaTimezone } from '@lyxa.ai/core/dist/utilities/time';\nimport { fillMissingPeriods } from '@utility/utils';\n\n@Service()\nexport class MarketingMetricsRepository {\n\tprivate model: typeof MarketingModel & SoftDeleteModel<Model>;\n\tprivate orderModel: typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\n\tconstructor() {\n\t\tthis.model = MarketingModel as typeof MarketingModel & SoftDeleteModel<Model>;\n\t\tthis.orderModel = RegularOrderModel as typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\t}\n\n\tpublic calculateMarketingSpendPerOrder(\n\t\torder: DocumentType<RegularOrder> & {\n\t\t\tlineItems: DocumentType<LineItem>[];\n\t\t\tmarketings: DocumentType<Marketing>[];\n\t\t}\n\t): Map<mongoose.Types.ObjectId, number> {\n\t\tconst spendMap = new Map<mongoose.Types.ObjectId, number>();\n\n\t\tconst marketingOwnerMap = new Map<string, 'COMPANY' | 'SHOP'>();\n\n\t\t// Build owner map\n\t\tfor (const marketing of order.marketings ?? []) {\n\t\t\tmarketingOwnerMap.set(marketing._id.toString(), marketing.isAppliedByCompany ? 'COMPANY' : 'SHOP');\n\t\t}\n\n\t\tconst addSpend = (marketingId: mongoose.Types.ObjectId, amount: number) => {\n\t\t\tif (!amount || amount <= 0) return;\n\t\t\tspendMap.set(marketingId, (spendMap.get(marketingId) ?? 0) + amount);\n\t\t};\n\n\t\tconst getRelevantAmount = (\n\t\t\tmarketingId: mongoose.Types.ObjectId,\n\t\t\tcompanyAmount: number,\n\t\t\tshopAmount: number\n\t\t) => {\n\t\t\tconst owner = marketingOwnerMap.get(marketingId.toString());\n\t\t\treturn owner === 'COMPANY' ? companyAmount : shopAmount;\n\t\t};\n\n\t\t/**\n\t\t * ITEM-BASED\n\t\t */\n\t\tfor (const lineItem of order.lineItems ?? []) {\n\t\t\tfor (const marketingId of lineItem.marketings ?? []) {\n\t\t\t\tconst snap = lineItem.calculationSnap ?? {};\n\n\t\t\t\taddSpend(\n\t\t\t\t\tmarketingId._id,\n\t\t\t\t\tgetRelevantAmount(\n\t\t\t\t\t\tmarketingId._id,\n\t\t\t\t\t\t(Number(snap.itemDiscountByCompany) || 0) + (Number(snap.b1g1DiscountByCompany) || 0),\n\t\t\t\t\t\t(Number(snap.itemDiscountByShop) || 0) + (Number(snap.b1g1DiscountByShop) || 0)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * FREE DELIVERY\n\t\t */\n\t\tif (order.adjustedFinance?.freeDelivery) {\n\t\t\tfor (const marketingId of order.marketings ?? []) {\n\t\t\t\taddSpend(\n\t\t\t\t\tmarketingId._id,\n\t\t\t\t\tgetRelevantAmount(\n\t\t\t\t\t\tmarketingId._id,\n\t\t\t\t\t\torder.adjustedFinance.freeDelivery.companyCut ?? 0,\n\t\t\t\t\t\torder.adjustedFinance.freeDelivery.shopCut ?? 0\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * PUNCH MARKETING\n\t\t */\n\t\tif (order.adjustedFinance?.pricing?.punchMarketingDiscount) {\n\t\t\tfor (const marketingId of order.marketings ?? []) {\n\t\t\t\taddSpend(marketingId._id, order.adjustedFinance.pricing.punchMarketingDiscount);\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * SPEND TO GET\n\t\t */\n\t\tif (order.adjustedFinance?.spendToGet) {\n\t\t\tfor (const marketingId of order.marketings ?? []) {\n\t\t\t\taddSpend(\n\t\t\t\t\tmarketingId._id,\n\t\t\t\t\tgetRelevantAmount(\n\t\t\t\t\t\tmarketingId._id,\n\t\t\t\t\t\torder.adjustedFinance.spendToGet.companyCut ?? 0,\n\t\t\t\t\t\torder.adjustedFinance.spendToGet.shopCut ?? 0\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn spendMap;\n\t}\n\n\tpublic async calculateMarketingSpent(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tduration?: Duration\n\t): Promise<{ amount: number; marketingType: MarketingType }> {\n\t\tconst marketing = await this.model.findById(marketingId).lean();\n\n\t\tif (!marketing) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\n\t\tconst calculators: Record<MarketingType, () => Promise<number>> = {\n\t\t\t[MarketingType.FREE_DELIVERY]: () => this.calculateFreeDeliverySpent(marketingId, duration),\n\n\t\t\t[MarketingType.DISCOUNT]: () =>\n\t\t\t\tthis.calculateItemBasedSpent(marketingId, marketing.isAppliedByCompany, duration),\n\n\t\t\t[MarketingType.BUY1GET1]: () =>\n\t\t\t\tthis.calculateItemBasedSpent(marketingId, marketing.isAppliedByCompany, duration),\n\n\t\t\t[MarketingType.PUNCH_MARKETING]: () => this.calculatePunchMarketingSpent(marketingId, duration),\n\t\t\t[MarketingType.SPEND_TO_GET]: () => this.calculateSpendToGetSpent(marketingId, duration),\n\t\t\t[MarketingType.FEATURED]: function (): Promise<number> {\n\t\t\t\treturn Promise.resolve((marketing as DocumentType<FeaturedMarketing>).amount || 0);\n\t\t\t},\n\t\t};\n\n\t\tconst amount = calculators[marketing.marketingType] ? await calculators[marketing.marketingType]() : 0;\n\n\t\treturn {\n\t\t\tamount,\n\t\t\tmarketingType: marketing.marketingType,\n\t\t};\n\t}\n\n\tprivate async calculateItemBasedSpent(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tisAppliedByAdmin: boolean,\n\t\tduration?: Duration\n\t): Promise<number> {\n\t\tconst addBlock = isAppliedByAdmin\n\t\t\t? [\n\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.itemDiscountByCompany', 0] },\n\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByCompany', 0] },\n\t\t\t\t]\n\t\t\t: [\n\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.itemDiscountByShop', 0] },\n\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByShop', 0] },\n\t\t\t\t];\n\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\tthis.buildBaseMatch(marketingId, duration),\n\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'lineItems',\n\t\t\t\t\tlocalField: 'cart',\n\t\t\t\t\tforeignField: 'cart',\n\t\t\t\t\tas: 'lineItems',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $unwind: '$lineItems' },\n\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: null,\n\t\t\t\t\ttotalSpent: {\n\t\t\t\t\t\t$sum: {\n\t\t\t\t\t\t\t$add: addBlock,\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 this.runAggregateAndGetTotal(pipeline, 'totalSpent');\n\t}\n\n\tprivate async calculateFreeDeliverySpent(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tduration?: Duration\n\t): Promise<number> {\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\tthis.buildBaseMatch(marketingId, duration),\n\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: null,\n\t\t\t\t\ttotalSpent: {\n\t\t\t\t\t\t$sum: {\n\t\t\t\t\t\t\t$add: [\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.freeDelivery.companyCut', 0] },\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.freeDelivery.shopCut', 0] },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\treturn this.runAggregateAndGetTotal(pipeline, 'totalSpent');\n\t}\n\n\tprivate async calculateSpendToGetSpent(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tduration?: Duration\n\t): Promise<number> {\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\tthis.buildBaseMatch(marketingId, duration),\n\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: null,\n\t\t\t\t\ttotalSpent: {\n\t\t\t\t\t\t$sum: {\n\t\t\t\t\t\t\t$add: [\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.spendToGet.companyCut', 0] },\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.spendToGet.shopCut', 0] },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\treturn this.runAggregateAndGetTotal(pipeline, 'totalSpent');\n\t}\n\n\tprivate async calculatePunchMarketingSpent(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tduration?: Duration\n\t): Promise<number> {\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\tthis.buildBaseMatch(marketingId, duration),\n\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: null,\n\t\t\t\t\ttotalSpent: {\n\t\t\t\t\t\t$sum: {\n\t\t\t\t\t\t\t$ifNull: ['$adjustedFinance.pricing.punchMarketingDiscount', 0],\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 this.runAggregateAndGetTotal(pipeline, 'totalSpent');\n\t}\n\n\tprivate buildBaseMatch(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tduration?: Duration\n\t): mongoose.PipelineStage.Match {\n\t\treturn {\n\t\t\t$match: {\n\t\t\t\tmarketings: marketingId,\n\t\t\t\tstatus: { $ne: RegularOrderStatus.CANCELLED },\n\t\t\t\t...(duration && {\n\t\t\t\t\tprocessedAt: {\n\t\t\t\t\t\t$gte: duration.start,\n\t\t\t\t\t\t$lte: duration.end,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate async runAggregateAndGetTotal(pipeline: mongoose.PipelineStage[], field: string): Promise<number> {\n\t\tconst [result] = await this.orderModel.aggregate(pipeline);\n\t\treturn result?.[field] ?? 0;\n\t}\n\n\tpublic async getMetrics(marketingId: mongoose.Types.ObjectId): Promise<MarketingMetricsDTO> {\n\t\tconst marketing = await this.model.findById(marketingId).lean();\n\n\t\tif (!marketing) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\n\t\t//TODO: fix current end and previous start\n\n\t\tconst currentDuration = { start: marketing.duration.start, end: dayjs().toDate() };\n\t\tconst previousDuration = {\n\t\t\tstart: dayjs(marketing.duration.start).subtract(dayjs().diff(marketing.duration.start)).toDate(),\n\t\t\tend: marketing.duration.start,\n\t\t};\n\n\t\tlet metrics: MarketingMetricsDTO = {};\n\n\t\tif ([MarketingType.DISCOUNT, MarketingType.BUY1GET1].includes(marketing.marketingType)) {\n\t\t\tmetrics.numberOfItems = await this.getMarketingItemCount(marketingId);\n\t\t}\n\n\t\tmetrics.orderIncreaseWithDiscount = await this.calculateOrderIncreaseWithDiscount(\n\t\t\tmarketingId,\n\t\t\tmarketing.shop._id,\n\t\t\tcurrentDuration,\n\t\t\tpreviousDuration\n\t\t);\n\t\tmetrics.customerIncreaseWithDiscount = await this.calculateCustomerIncreaseWithDiscount(\n\t\t\tmarketingId,\n\t\t\tmarketing.shop._id,\n\t\t\tcurrentDuration,\n\t\t\tpreviousDuration\n\t\t);\n\t\tmetrics.totalRedemptions = await this.orderModel.countDocuments({\n\t\t\tmarketings: marketingId,\n\t\t\tstatus: { $ne: RegularOrderStatus.CANCELLED },\n\t\t});\n\n\t\treturn metrics;\n\t}\n\n\tprivate async getMarketingItemCount(marketingId: mongoose.Types.ObjectId): Promise<number> {\n\t\tconst result = await productMarketingService.countDocuments({ marketing: marketingId });\n\t\treturn result ?? 0;\n\t}\n\n\tprivate async calculateOrderIncreaseWithDiscount(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tcurrentDuration: Duration,\n\t\tpreviousDuration: Duration\n\t): Promise<IncreaseDuringDiscountDTO> {\n\t\tconst [currentOrders, previousOrders] = await Promise.all([\n\t\t\tthis.orderModel.countDocuments({\n\t\t\t\tcreatedAt: {\n\t\t\t\t\t$gte: currentDuration.start,\n\t\t\t\t\t$lte: currentDuration.end,\n\t\t\t\t},\n\t\t\t\tmarketings: marketingId, // marketing must be applied\n\t\t\t\tshop: shopId,\n\t\t\t}),\n\t\t\tthis.orderModel.countDocuments({\n\t\t\t\tcreatedAt: {\n\t\t\t\t\t$gte: previousDuration.start,\n\t\t\t\t\t$lte: previousDuration.end,\n\t\t\t\t},\n\t\t\t\tshop: shopId,\n\t\t\t}),\n\t\t]);\n\n\t\treturn this.calculateIncrease(currentOrders, previousOrders);\n\t}\n\n\tprivate async calculateCustomerIncreaseWithDiscount(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tcurrentDuration: Duration,\n\t\tpreviousDuration: Duration\n\t): Promise<IncreaseDuringDiscountDTO> {\n\t\tconst [currentNewCustomers, previousNewCustomers] = await Promise.all([\n\t\t\tthis.getNewCustomersForShop(shopId, currentDuration, { marketings: marketingId }),\n\t\t\tthis.getNewCustomersForShop(shopId, previousDuration),\n\t\t]);\n\n\t\treturn this.calculateIncrease(currentNewCustomers, previousNewCustomers);\n\t}\n\n\tprivate calculateIncrease(current: number, previous: number): IncreaseDuringDiscountDTO {\n\t\tconst count = current - previous;\n\n\t\tconst percentageIncrease = previous === 0 ? (current > 0 ? 100 : 0) : (count / previous) * 100;\n\n\t\treturn {\n\t\t\tcount,\n\t\t\tpercentageIncrease,\n\t\t};\n\t}\n\n\tprivate async getNewCustomersForShop(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tduration: Duration,\n\t\textraMatch: Record<string, any> = {}\n\t): Promise<number> {\n\t\t// Customers who ordered during the period\n\t\tconst customersInPeriod = await this.orderModel.distinct('user', {\n\t\t\tcreatedAt: {\n\t\t\t\t$gte: duration.start,\n\t\t\t\t$lte: duration.end,\n\t\t\t},\n\t\t\tshop: shopId,\n\t\t\t...extraMatch,\n\t\t});\n\n\t\tif (customersInPeriod.length === 0) {\n\t\t\treturn 0;\n\t\t}\n\n\t\t// Customers who had ordered from this shop BEFORE the period\n\t\tconst existingCustomers = await this.orderModel.distinct('user', {\n\t\t\tshop: shopId,\n\t\t\tcreatedAt: { $lt: duration.start },\n\t\t\tuser: { $in: customersInPeriod },\n\t\t});\n\n\t\t// New customers = in period − existing\n\t\treturn customersInPeriod.length - existingCustomers.length;\n\t}\n\n\tpublic async getOrdersGraph(data: MarketingGraphInputDTO): Promise<MarketingOrdersGraphOutputDTO> {\n\t\tconst dateFormat = data.type === GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';\n\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\t// Filter only delivered orders within the given date range\n\t\t\tthis.buildBaseMatch(new mongoose.Types.ObjectId(data.marketingId), {\n\t\t\t\tstart: data.startDate,\n\t\t\t\tend: data.endDate,\n\t\t\t}),\n\n\t\t\t// Extract formatted date from 'processedAt' for grouping\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\tdate: {\n\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\tdate: '$processedAt',\n\t\t\t\t\t\t\ttimezone: LyxaTimezone,\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\t// Group by formatted date and count orders\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$date',\n\t\t\t\t\torders: { $sum: 1 },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Sort results chronologically\n\t\t\t{\n\t\t\t\t$sort: { _id: 1 },\n\t\t\t},\n\n\t\t\t// Format the response to match output DTO structure\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\t_id: 0,\n\t\t\t\t\tdate: '$_id',\n\t\t\t\t\torders: 1,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\t// Execute aggregation pipeline\n\t\tconst results = await this.orderModel.aggregate(pipeline).allowDiskUse(true).exec();\n\n\t\tconst graphData = fillMissingPeriods(results, data.startDate, data.endDate, data.type, {\n\t\t\torders: 0,\n\t\t});\n\n\t\treturn graphData;\n\t}\n\n\tpublic async getCustomersGraph(data: MarketingGraphInputDTO): Promise<{ date: string; users: number }[]> {\n\t\t// 1️⃣ Get shopId from marketing\n\t\tconst marketing = await this.model.findById(data.marketingId).select('shop').lean();\n\n\t\tif (!marketing) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\n\t\tconst shopId = marketing.shop._id;\n\n\t\t// 2️⃣ Fetch users who ordered from this shop BEFORE the start date\n\t\tconst oldUsers = await this.orderModel.distinct('user', {\n\t\t\tshop: shopId,\n\t\t\tstatus: RegularOrderStatus.DELIVERED,\n\t\t\tprocessedAt: { $lt: data.startDate },\n\t\t});\n\n\t\tconst dateFormat = data.type === GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';\n\n\t\t// 3️⃣ Aggregation pipeline\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\t// Orders during the period with this marketing\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\torderType: OrderType.REGULAR,\n\t\t\t\t\tstatus: RegularOrderStatus.DELIVERED,\n\t\t\t\t\tshop: shopId,\n\t\t\t\t\tmarketings: new mongoose.Types.ObjectId(data.marketingId),\n\t\t\t\t\tprocessedAt: { $gte: data.startDate, $lte: data.endDate },\n\t\t\t\t\tuser: { $nin: oldUsers }, // 🚫 exclude old users\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Sort so earliest order per user comes first\n\t\t\t{ $sort: { processedAt: 1 } },\n\n\t\t\t// First order per user (new users only)\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$user',\n\t\t\t\t\tfirstOrderDate: { $first: '$processedAt' },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Format date\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\tdate: {\n\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\tdate: '$firstOrderDate',\n\t\t\t\t\t\t\ttimezone: LyxaTimezone,\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\t// Group by date\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$date',\n\t\t\t\t\tusers: { $sum: 1 },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Sort chronologically\n\t\t\t{ $sort: { _id: 1 } },\n\n\t\t\t// Shape response\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\t_id: 0,\n\t\t\t\t\tdate: '$_id',\n\t\t\t\t\tusers: 1,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\tconst results = await this.orderModel.aggregate(pipeline).allowDiskUse(true).exec();\n\n\t\t// 4️⃣ Fill missing periods\n\t\treturn fillMissingPeriods(results, data.startDate, data.endDate, data.type, {\n\t\t\tusers: 0,\n\t\t});\n\t}\n\n\tpublic async getAmountSpentGraph(\n\t\tdata: MarketingGraphInputDTO\n\t): Promise<{ date: string; amount: number }[]> {\n\t\tconst marketing = await this.model.findById(data.marketingId).lean();\n\n\t\tif (!marketing) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\n\t\tconst marketingId = new mongoose.Types.ObjectId(data.marketingId);\n\t\tconst dateFormat = data.type === GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';\n\n\t\tlet pipeline: mongoose.PipelineStage[] | null = null;\n\n\t\t/**\n\t\t * ITEM-BASED (DISCOUNT / BUY1GET1)\n\t\t */\n\t\tif ([MarketingType.DISCOUNT, MarketingType.BUY1GET1].includes(marketing.marketingType)) {\n\t\t\tpipeline = [\n\t\t\t\tthis.buildBaseMatch(marketingId, {\n\t\t\t\t\tstart: data.startDate,\n\t\t\t\t\tend: data.endDate,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\t$lookup: {\n\t\t\t\t\t\tfrom: 'lineItems',\n\t\t\t\t\t\tlocalField: 'cart',\n\t\t\t\t\t\tforeignField: 'cart',\n\t\t\t\t\t\tas: 'lineItems',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ $unwind: '$lineItems' },\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\t'lineItems.marketings': marketingId,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\tdate: {\n\t\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\t\tdate: '$processedAt',\n\t\t\t\t\t\t\t\ttimezone: LyxaTimezone,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tamount: {\n\t\t\t\t\t\t\t$add: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\tmarketing.isAppliedByCompany,\n\t\t\t\t\t\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.itemDiscountByCompany', 0] },\n\t\t\t\t\t\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.itemDiscountByShop', 0] },\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\t\t\tmarketing.isAppliedByCompany,\n\t\t\t\t\t\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByCompany', 0] },\n\t\t\t\t\t\t\t\t\t\t{ $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByShop', 0] },\n\t\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: '$date',\n\t\t\t\t\t\tamount: { $sum: '$amount' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ $sort: { _id: 1 } },\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\tdate: '$_id',\n\t\t\t\t\t\tamount: 1,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else if (marketing.marketingType === MarketingType.FREE_DELIVERY) {\n\t\t\t/**\n\t\t\t * FREE DELIVERY\n\t\t\t */\n\t\t\tpipeline = [\n\t\t\t\tthis.buildBaseMatch(marketingId, {\n\t\t\t\t\tstart: data.startDate,\n\t\t\t\t\tend: data.endDate,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\tdate: {\n\t\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\t\tdate: '$processedAt',\n\t\t\t\t\t\t\t\ttimezone: LyxaTimezone,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tamount: {\n\t\t\t\t\t\t\t$cond: [\n\t\t\t\t\t\t\t\tmarketing.isAppliedByCompany,\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.freeDelivery.companyCut', 0] },\n\t\t\t\t\t\t\t\t{ $ifNull: ['$adjustedFinance.freeDelivery.shopCut', 0] },\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: '$date',\n\t\t\t\t\t\tamount: { $sum: '$amount' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ $sort: { _id: 1 } },\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\tdate: '$_id',\n\t\t\t\t\t\tamount: 1,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t} else if (marketing.marketingType === MarketingType.PUNCH_MARKETING) {\n\t\t\t/**\n\t\t\t * PUNCH MARKETING\n\t\t\t */\n\t\t\tpipeline = [\n\t\t\t\tthis.buildBaseMatch(marketingId, {\n\t\t\t\t\tstart: data.startDate,\n\t\t\t\t\tend: data.endDate,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\tdate: {\n\t\t\t\t\t\t\t$dateToString: {\n\t\t\t\t\t\t\t\tformat: dateFormat,\n\t\t\t\t\t\t\t\tdate: '$processedAt',\n\t\t\t\t\t\t\t\ttimezone: LyxaTimezone,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\tamount: {\n\t\t\t\t\t\t\t$ifNull: ['$adjustedFinance.pricing.punchMarketingDiscount', 0],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t$group: {\n\t\t\t\t\t\t_id: '$date',\n\t\t\t\t\t\tamount: { $sum: '$amount' },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{ $sort: { _id: 1 } },\n\t\t\t\t{\n\t\t\t\t\t$project: {\n\t\t\t\t\t\t_id: 0,\n\t\t\t\t\t\tdate: '$_id',\n\t\t\t\t\t\tamount: 1,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\t// If marketing type doesn't produce spend graph → return empty graph\n\t\tif (!pipeline) {\n\t\t\treturn fillMissingPeriods(\n\t\t\t\t[] as { date: string; amount: number }[],\n\t\t\t\tdata.startDate,\n\t\t\t\tdata.endDate,\n\t\t\t\tdata.type,\n\t\t\t\t{\n\t\t\t\t\tamount: 0,\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tconst results = await this.orderModel.aggregate(pipeline).allowDiskUse(true).exec();\n\n\t\treturn fillMissingPeriods(results, data.startDate, data.endDate, data.type, {\n\t\t\tamount: 0,\n\t\t});\n\t}\n}\n\nexport const marketingMetricsRepository = Container.get(MarketingMetricsRepository);\n"]}
|
|
@@ -166,6 +166,7 @@ export declare const marketingRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
166
166
|
count: number;
|
|
167
167
|
percentageIncrease: number;
|
|
168
168
|
} | undefined;
|
|
169
|
+
totalRedemptions?: number | undefined;
|
|
169
170
|
} | undefined;
|
|
170
171
|
};
|
|
171
172
|
meta: object;
|
|
@@ -221,6 +222,19 @@ export declare const marketingRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
221
222
|
};
|
|
222
223
|
meta: object;
|
|
223
224
|
}>;
|
|
225
|
+
getSpendToGetProgress: import("@trpc/server").TRPCQueryProcedure<{
|
|
226
|
+
input: {
|
|
227
|
+
shop: string | mongoose.Types.ObjectId;
|
|
228
|
+
basketTotal: number;
|
|
229
|
+
userId?: string | mongoose.Types.ObjectId | undefined;
|
|
230
|
+
};
|
|
231
|
+
output: {
|
|
232
|
+
success: boolean;
|
|
233
|
+
message: string;
|
|
234
|
+
data: import("../../marketing/services").SpendToGetProgressResult | undefined;
|
|
235
|
+
};
|
|
236
|
+
meta: object;
|
|
237
|
+
}>;
|
|
224
238
|
reseedEntireMenuMarketing: import("@trpc/server").TRPCMutationProcedure<{
|
|
225
239
|
input: string | mongoose.Types.ObjectId;
|
|
226
240
|
output: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.router.d.ts","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"marketing.router.d.ts","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAMxB,CAAD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyJD,CAAC"}
|
|
@@ -5,6 +5,7 @@ const trpc_1 = require("@lyxa.ai/core/dist/libraries/trpc");
|
|
|
5
5
|
const auth_1 = require("@lyxa.ai/core/dist/libraries/trpc/middlewares/auth");
|
|
6
6
|
const services_1 = require("../../marketing/services");
|
|
7
7
|
const services_2 = require("../../marketing/services");
|
|
8
|
+
const services_3 = require("../../marketing/services");
|
|
8
9
|
const validations_1 = require("../../marketing/validations");
|
|
9
10
|
const response_1 = require("@lyxa.ai/core/dist/utilities/response");
|
|
10
11
|
const validation_1 = require("@lyxa.ai/core/dist/utilities/validation");
|
|
@@ -99,6 +100,10 @@ exports.marketingRouter = (0, trpc_1.createTRPCRouter)({
|
|
|
99
100
|
const result = await MarketingMetricsRepository_1.marketingMetricsRepository.getAmountSpentGraph(input);
|
|
100
101
|
return (0, response_1.response)('Marketing amount spent graph data fetched successfully', result);
|
|
101
102
|
})),
|
|
103
|
+
getSpendToGetProgress: trpc_1.publicProcedure.input(validations_1.SpendToGetProgressInputSchema).query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
104
|
+
const result = await services_3.spendToGetProgressService.getProgress(input);
|
|
105
|
+
return (0, response_1.response)('Spend to get progress fetched successfully', result);
|
|
106
|
+
})),
|
|
102
107
|
reseedEntireMenuMarketing: (0, auth_1.createAuthenticatedProcedure)({ entityTypes: [auth_2.AuthEntityType.CRM] })
|
|
103
108
|
.input(validation_1.IdSchema)
|
|
104
109
|
.output(validations_1.MarketingResponseSchema)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.router.js","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":";;;AAAA,4DAAsF;AACtF,6EAAkG;AAClG,0DAA0E;AAC1E,0DAAoH;AACpH,gEAQwC;AACxC,oEAAiE;AACjE,wEAKiD;AACjD,8EAA0E;AAC1E,4DAAmE;AACnE,oDAAgD;AAChD,kGAA+F;AAElF,QAAA,eAAe,GAAG,IAAA,uBAAgB,EAAC;IAC/C,MAAM,EAAE,IAAA,mCAA4B,EAAC,EAAE,WAAW,EAAE,CAAC,qBAAc,CAAC,GAAG,EAAE,qBAAc,CAAC,MAAM,CAAC,EAAE,CAAC;SAChG,KAAK,CAAC,2CAA6B,CAAC;SACpC,MAAM,CAAC,qCAAc,CAAC;SACtB,QAAQ,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAClC,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,IAAI,IAAI,qBAAc,CAAC,GAAG,CAAC;QACvD,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KAAK,CAAC,CAAC;QAC3E,OAAO,IAAA,mBAAQ,EAAC,wDAAwD,EAAE,MAAM,CAAC,CAAC;IACnF,CAAC,CAAC,CACF;IAED,yBAAyB,EAAE,IAAA,mCAA4B,EAAC,EAAE,WAAW,EAAE,CAAC,qBAAc,CAAC,GAAG,CAAC,EAAE,CAAC;SAC5F,KAAK,CAAC,qBAAQ,CAAC;SACf,MAAM,CAAC,qCAAc,CAAC;SACtB,QAAQ,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAC7B,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,2BAAO,CAAC,yBAAyB,CAAC,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5E,OAAO,IAAA,mBAAQ,EAAC,sDAAsD,CAAC,CAAC;IACzE,CAAC,CAAC,CACF;CACF,CAAC,CAAC","sourcesContent":["import { createTRPCRouter, publicProcedure } from '@lyxa.ai/core/dist/libraries/trpc';\nimport { createAuthenticatedProcedure } from '@lyxa.ai/core/dist/libraries/trpc/middlewares/auth';\nimport { marketingService as service } from '@modules/marketing/services';\nimport { synchronizeProductMarketingService as syncMarketingProductInfoService } from '@modules/marketing/services';\nimport {\n\tAllMarketingsValidationSchema,\n\tMarketingResponseSchema as ResponseSchema,\n\tAllMarketingsUpdateSchema,\n\tProductEntireMenuMarketingHandlerSchema,\n\tMarketingSpendLimitsEvaluationSchema,\n\tSyncProductMarketingForMultipleProductsSchema,\n\tMarketingGraphInputSchema,\n} from '@modules/marketing/validations';\nimport { response } from '@lyxa.ai/core/dist/utilities/response';\nimport {\n\tFilterSchema,\n\tDeleteSchema,\n\tGetByIdInputSchema,\n\tIdSchema,\n} from '@lyxa.ai/core/dist/utilities/validation';\nimport { ErrorHandler } from '@lyxa.ai/core/dist/utilities/error-handler';\nimport { AuthEntityType } from '@lyxa.ai/core/dist/libraries/auth';\nimport { mongoose } from '@typegoose/typegoose';\nimport { marketingMetricsRepository } from '../patterns/repository/MarketingMetricsRepository';\n\nexport const marketingRouter = createTRPCRouter({\n\tcreate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsValidationSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.create(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing created successfully');\n\t\t\t})\n\t\t),\n\n\tgetById: publicProcedure.input(GetByIdInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.findById(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tget: publicProcedure.input(FilterSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.find(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tupdate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsUpdateSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst { _id, ...rest } = input;\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\n\t\t\t\tawait service.update(_id, rest, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing updated successfully');\n\t\t\t})\n\t\t),\n\n\tdeleteById: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(DeleteSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.deleteById(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing deleted successfully');\n\t\t\t})\n\t\t),\n\n\thandleNewProductForEntireMenuMarketing: publicProcedure\n\t\t.input(ProductEntireMenuMarketingHandlerSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tawait service.handleNewProductForEntireMenuMarketing(input);\n\t\t\t\treturn response('Product handled successfully');\n\t\t\t})\n\t\t),\n\n\tsyncAllProductsMarketingInfo: publicProcedure.query(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\treturn await syncMarketingProductInfoService.publishAllProductsProductMarketingInfoProcessEvent();\n\t\t})\n\t),\n\n\tsyncAllProductsMarketingInfoLocal: publicProcedure.mutation(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\treturn await syncMarketingProductInfoService.syncAllProductsMarketingInfo();\n\t\t})\n\t),\n\n\t// DEV purpose only\n\tsyncProductMarketingInfoByProductId: publicProcedure.query(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst productId = new mongoose.Types.ObjectId('68f663c355f42c826a129fc6'); // Todo: use productId sent from param\n\t\t\treturn await syncMarketingProductInfoService.syncProductMarketingInfoByProductId(productId);\n\t\t})\n\t),\n\n\tsyncProductMarketingInfoByProductIds: publicProcedure\n\t\t.input(SyncProductMarketingForMultipleProductsSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\treturn await syncMarketingProductInfoService.syncProductMarketingInfoByProductIds(input.productIds);\n\t\t\t})\n\t\t),\n\n\tcalculateMarketingSpent: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.calculateMarketingSpent(input);\n\t\t\treturn response('Marketing amount spent calculated successfully', result);\n\t\t})\n\t),\n\n\tincrementMarketingSpentFromOrder: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.incrementMarketingSpentFromOrder(input);\n\t\t\treturn response('Marketing amount spent incremented successfully', result);\n\t\t})\n\t),\n\n\tdecrementMarketingSpentFromOrder: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.decrementMarketingSpentFromOrder(input);\n\t\t\treturn response('Marketing amount spent decremented successfully', result);\n\t\t})\n\t),\n\n\trecomputeAndSyncAllMarketingSpent: publicProcedure.mutation(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.recomputeAndSyncAllMarketingSpent();\n\t\t\treturn response('Marketing amount spent recomputed and synced successfully', result);\n\t\t})\n\t),\n \n\tgetMetrics: publicProcedure.input(IdSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getMetrics(input);\n\t\t\treturn response('Marketing metrics fetched successfully', result);\n\t\t})\n\t),\n \n\tgetOrdersGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getOrdersGraph(input);\n\t\t\treturn response('Marketing orders graph data fetched successfully', result);\n\t\t})\n\t),\n\n\tgetCustomersGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getCustomersGraph(input);\n\t\t\treturn response('Marketing customers graph data fetched successfully', result);\n\t\t})\n\t),\n\n\tgetAmountSpentGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getAmountSpentGraph(input);\n\t\t\treturn response('Marketing amount spent graph data fetched successfully', result);\n\t\t})\n\t),\n\n\treseedEntireMenuMarketing: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM] })\n\t\t.input(IdSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tawait service.reseedEntireMenuMarketing(new mongoose.Types.ObjectId(input));\n\t\t\t\treturn response('Entire menu marketing reseed dispatched successfully');\n\t\t\t})\n\t\t),\n});\n"]}
|
|
1
|
+
{"version":3,"file":"marketing.router.js","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":";;;AAAA,4DAAsF;AACtF,6EAAkG;AAClG,0DAA0E;AAC1E,0DAAoH;AACpH,0DAAwE;AACxE,gEASwC;AACxC,oEAAiE;AACjE,wEAKiD;AACjD,8EAA0E;AAC1E,4DAAmE;AACnE,oDAAgD;AAChD,kGAA+F;AAElF,QAAA,eAAe,GAAG,IAAA,uBAAgB,EAAC;IAC/C,MAAM,EAAE,IAAA,mCAA4B,EAAC,EAAE,WAAW,EAAE,CAAC,qBAAc,CAAC,GAAG,EAAE,qBAAc,CAAC,MAAM,CAAC,EAAE,CAAC;SAChG,KAAK,CAAC,2CAA6B,CAAC;SACpC,MAAM,CAAC,qCAAc,CAAC;SACtB,QAAQ,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAClC,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,IAAI,IAAI,qBAAc,CAAC,GAAG,CAAC;QACvD,MAAM,2BAAO,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAA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AAC,2CAA6B,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CACrG,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,MAAM,GAAG,MAAM,oCAAyB,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAClE,OAAO,IAAA,mBAAQ,EAAC,4CAA4C,EAAE,MAAM,CAAC,CAAC;IACvE,CAAC,CAAC,CACF;IAED,yBAAyB,EAAE,IAAA,mCAA4B,EAAC,EAAE,WAAW,EAAE,CAAC,qBAAc,CAAC,GAAG,CAAC,EAAE,CAAC;SAC5F,KAAK,CAAC,qBAAQ,CAAC;SACf,MAAM,CAAC,qCAAc,CAAC;SACtB,QAAQ,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAC7B,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,2BAAO,CAAC,yBAAyB,CAAC,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5E,OAAO,IAAA,mBAAQ,EAAC,sDAAsD,CAAC,CAAC;IACzE,CAAC,CAAC,CACF;CACF,CAAC,CAAC","sourcesContent":["import { createTRPCRouter, publicProcedure } from '@lyxa.ai/core/dist/libraries/trpc';\nimport { createAuthenticatedProcedure } from '@lyxa.ai/core/dist/libraries/trpc/middlewares/auth';\nimport { marketingService as service } from '@modules/marketing/services';\nimport { synchronizeProductMarketingService as syncMarketingProductInfoService } from '@modules/marketing/services';\nimport { spendToGetProgressService } from '@modules/marketing/services';\nimport {\n\tAllMarketingsValidationSchema,\n\tMarketingResponseSchema as ResponseSchema,\n\tAllMarketingsUpdateSchema,\n\tProductEntireMenuMarketingHandlerSchema,\n\tMarketingSpendLimitsEvaluationSchema,\n\tSyncProductMarketingForMultipleProductsSchema,\n\tMarketingGraphInputSchema,\n\tSpendToGetProgressInputSchema,\n} from '@modules/marketing/validations';\nimport { response } from '@lyxa.ai/core/dist/utilities/response';\nimport {\n\tFilterSchema,\n\tDeleteSchema,\n\tGetByIdInputSchema,\n\tIdSchema,\n} from '@lyxa.ai/core/dist/utilities/validation';\nimport { ErrorHandler } from '@lyxa.ai/core/dist/utilities/error-handler';\nimport { AuthEntityType } from '@lyxa.ai/core/dist/libraries/auth';\nimport { mongoose } from '@typegoose/typegoose';\nimport { marketingMetricsRepository } from '../patterns/repository/MarketingMetricsRepository';\n\nexport const marketingRouter = createTRPCRouter({\n\tcreate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsValidationSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.create(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing created successfully');\n\t\t\t})\n\t\t),\n\n\tgetById: publicProcedure.input(GetByIdInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.findById(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tget: publicProcedure.input(FilterSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.find(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tupdate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsUpdateSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst { _id, ...rest } = input;\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\n\t\t\t\tawait service.update(_id, rest, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing updated successfully');\n\t\t\t})\n\t\t),\n\n\tdeleteById: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(DeleteSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.deleteById(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing deleted successfully');\n\t\t\t})\n\t\t),\n\n\thandleNewProductForEntireMenuMarketing: publicProcedure\n\t\t.input(ProductEntireMenuMarketingHandlerSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tawait service.handleNewProductForEntireMenuMarketing(input);\n\t\t\t\treturn response('Product handled successfully');\n\t\t\t})\n\t\t),\n\n\tsyncAllProductsMarketingInfo: publicProcedure.query(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\treturn await syncMarketingProductInfoService.publishAllProductsProductMarketingInfoProcessEvent();\n\t\t})\n\t),\n\n\tsyncAllProductsMarketingInfoLocal: publicProcedure.mutation(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\treturn await syncMarketingProductInfoService.syncAllProductsMarketingInfo();\n\t\t})\n\t),\n\n\t// DEV purpose only\n\tsyncProductMarketingInfoByProductId: publicProcedure.query(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst productId = new mongoose.Types.ObjectId('68f663c355f42c826a129fc6'); // Todo: use productId sent from param\n\t\t\treturn await syncMarketingProductInfoService.syncProductMarketingInfoByProductId(productId);\n\t\t})\n\t),\n\n\tsyncProductMarketingInfoByProductIds: publicProcedure\n\t\t.input(SyncProductMarketingForMultipleProductsSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\treturn await syncMarketingProductInfoService.syncProductMarketingInfoByProductIds(input.productIds);\n\t\t\t})\n\t\t),\n\n\tcalculateMarketingSpent: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.calculateMarketingSpent(input);\n\t\t\treturn response('Marketing amount spent calculated successfully', result);\n\t\t})\n\t),\n\n\tincrementMarketingSpentFromOrder: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.incrementMarketingSpentFromOrder(input);\n\t\t\treturn response('Marketing amount spent incremented successfully', result);\n\t\t})\n\t),\n\n\tdecrementMarketingSpentFromOrder: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.decrementMarketingSpentFromOrder(input);\n\t\t\treturn response('Marketing amount spent decremented successfully', result);\n\t\t})\n\t),\n\n\trecomputeAndSyncAllMarketingSpent: publicProcedure.mutation(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.recomputeAndSyncAllMarketingSpent();\n\t\t\treturn response('Marketing amount spent recomputed and synced successfully', result);\n\t\t})\n\t),\n \n\tgetMetrics: publicProcedure.input(IdSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getMetrics(input);\n\t\t\treturn response('Marketing metrics fetched successfully', result);\n\t\t})\n\t),\n \n\tgetOrdersGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getOrdersGraph(input);\n\t\t\treturn response('Marketing orders graph data fetched successfully', result);\n\t\t})\n\t),\n\n\tgetCustomersGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getCustomersGraph(input);\n\t\t\treturn response('Marketing customers graph data fetched successfully', result);\n\t\t})\n\t),\n\n\tgetAmountSpentGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getAmountSpentGraph(input);\n\t\t\treturn response('Marketing amount spent graph data fetched successfully', result);\n\t\t})\n\t),\n\n\tgetSpendToGetProgress: publicProcedure.input(SpendToGetProgressInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await spendToGetProgressService.getProgress(input);\n\t\t\treturn response('Spend to get progress fetched successfully', result);\n\t\t})\n\t),\n\n\treseedEntireMenuMarketing: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM] })\n\t\t.input(IdSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tawait service.reseedEntireMenuMarketing(new mongoose.Types.ObjectId(input));\n\t\t\t\treturn response('Entire menu marketing reseed dispatched successfully');\n\t\t\t})\n\t\t),\n});\n"]}
|
|
@@ -3,6 +3,9 @@ export * from './discount-marketing.service';
|
|
|
3
3
|
export * from './featured-marketing.service';
|
|
4
4
|
export * from './free-delivery-marketing.service';
|
|
5
5
|
export * from './punch-marketing.service';
|
|
6
|
+
export * from './spend-to-get-marketing.service';
|
|
7
|
+
export * from './spend-to-get-progress.service';
|
|
8
|
+
export * from './marketing-conflict.service';
|
|
6
9
|
export * from './product-marketing.service';
|
|
7
10
|
export * from './marketing.service';
|
|
8
11
|
export * from './synchronize-product-marketing.service';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/marketing/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,yCAAyC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["modules/marketing/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qBAAqB,CAAC;AACpC,cAAc,yCAAyC,CAAC"}
|
|
@@ -19,6 +19,9 @@ __exportStar(require("./discount-marketing.service"), exports);
|
|
|
19
19
|
__exportStar(require("./featured-marketing.service"), exports);
|
|
20
20
|
__exportStar(require("./free-delivery-marketing.service"), exports);
|
|
21
21
|
__exportStar(require("./punch-marketing.service"), exports);
|
|
22
|
+
__exportStar(require("./spend-to-get-marketing.service"), exports);
|
|
23
|
+
__exportStar(require("./spend-to-get-progress.service"), exports);
|
|
24
|
+
__exportStar(require("./marketing-conflict.service"), exports);
|
|
22
25
|
__exportStar(require("./product-marketing.service"), exports);
|
|
23
26
|
__exportStar(require("./marketing.service"), exports);
|
|
24
27
|
__exportStar(require("./synchronize-product-marketing.service"), exports);
|