@lyxa.ai/marketing 1.0.46 → 1.0.48
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/index.d.ts +1414 -13
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +3 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts +72 -6
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js +12 -3
- package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.d.ts +1 -0
- package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.js +102 -4
- package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/custom-coupon.service.d.ts +2 -0
- package/dist/lib/modules/coupon/services/custom-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/custom-coupon.service.js +1 -1
- package/dist/lib/modules/coupon/services/custom-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/global-coupon.service.d.ts +1 -1
- package/dist/lib/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/global-coupon.service.js +16 -10
- package/dist/lib/modules/coupon/services/global-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/helper.service.d.ts +2 -1
- package/dist/lib/modules/coupon/services/helper.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/helper.service.js +7 -1
- package/dist/lib/modules/coupon/services/helper.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.d.ts +2 -0
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.js +2 -2
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/individual-user-coupon.service.js +6 -0
- package/dist/lib/modules/coupon/services/individual-user-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts +10 -4
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js +88 -9
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +20 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.js +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js +36 -19
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.d.ts +2 -0
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js +2 -2
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +359 -34
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js +16 -3
- package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +6 -6
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +6 -6
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +30 -30
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +8 -2
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts +2 -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 +14 -0
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +24 -24
- package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts +36 -36
- package/dist/lib/modules/marketing/validations/featured-marketing.validation.d.ts +6 -6
- package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.d.ts +4 -4
- package/dist/lib/modules/marketing/validations/marketing.validation.d.ts +2 -2
- package/dist/lib/modules/marketing/validations/product-marketing.validation.d.ts +7 -7
- package/dist/lib/modules/marketing/validations/punch-marketing.validation.d.ts +4 -4
- package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +1 -1
- package/dist/lib/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +2 -2
- package/dist/lib/modules/tournament/config/config.builder.d.ts +5 -0
- package/dist/lib/modules/tournament/config/config.builder.d.ts.map +1 -0
- package/dist/lib/modules/tournament/config/config.builder.js +19 -0
- package/dist/lib/modules/tournament/config/config.builder.js.map +1 -0
- package/dist/lib/modules/tournament/config/config.repository.d.ts +13 -0
- package/dist/lib/modules/tournament/config/config.repository.d.ts.map +1 -0
- package/dist/lib/modules/tournament/config/config.repository.js +77 -0
- package/dist/lib/modules/tournament/config/config.repository.js.map +1 -0
- package/dist/lib/modules/tournament/config/config.router.d.ts +363 -0
- package/dist/lib/modules/tournament/config/config.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/config/config.router.js +40 -0
- package/dist/lib/modules/tournament/config/config.router.js.map +1 -0
- package/dist/lib/modules/tournament/config/config.service.d.ts +14 -0
- package/dist/lib/modules/tournament/config/config.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/config/config.service.js +101 -0
- package/dist/lib/modules/tournament/config/config.service.js.map +1 -0
- package/dist/lib/modules/tournament/config/config.validation.d.ts +1014 -0
- package/dist/lib/modules/tournament/config/config.validation.d.ts.map +1 -0
- package/dist/lib/modules/tournament/config/config.validation.js +70 -0
- package/dist/lib/modules/tournament/config/config.validation.js.map +1 -0
- package/dist/lib/modules/tournament/match/events/match-ended.consumer.d.ts +2 -0
- package/dist/lib/modules/tournament/match/events/match-ended.consumer.d.ts.map +1 -0
- package/dist/lib/modules/tournament/match/events/match-ended.consumer.js +15 -0
- package/dist/lib/modules/tournament/match/events/match-ended.consumer.js.map +1 -0
- package/dist/lib/modules/tournament/match/events/match-ended.event.d.ts +14 -0
- package/dist/lib/modules/tournament/match/events/match-ended.event.d.ts.map +1 -0
- package/dist/lib/modules/tournament/match/events/match-ended.event.js +12 -0
- package/dist/lib/modules/tournament/match/events/match-ended.event.js.map +1 -0
- package/dist/lib/modules/tournament/match/match.builder.d.ts +38 -0
- package/dist/lib/modules/tournament/match/match.builder.d.ts.map +1 -0
- package/dist/lib/modules/tournament/match/match.builder.js +37 -0
- package/dist/lib/modules/tournament/match/match.builder.js.map +1 -0
- package/dist/lib/modules/tournament/match/match.repository.d.ts +13 -0
- package/dist/lib/modules/tournament/match/match.repository.d.ts.map +1 -0
- package/dist/lib/modules/tournament/match/match.repository.js +84 -0
- package/dist/lib/modules/tournament/match/match.repository.js.map +1 -0
- package/dist/lib/modules/tournament/match/match.router.d.ts +489 -0
- package/dist/lib/modules/tournament/match/match.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/match/match.router.js +56 -0
- package/dist/lib/modules/tournament/match/match.router.js.map +1 -0
- package/dist/lib/modules/tournament/match/match.service.d.ts +29 -0
- package/dist/lib/modules/tournament/match/match.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/match/match.service.js +193 -0
- package/dist/lib/modules/tournament/match/match.service.js.map +1 -0
- package/dist/lib/modules/tournament/match/match.validation.d.ts +880 -0
- package/dist/lib/modules/tournament/match/match.validation.d.ts.map +1 -0
- package/dist/lib/modules/tournament/match/match.validation.js +74 -0
- package/dist/lib/modules/tournament/match/match.validation.js.map +1 -0
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.d.ts +13 -0
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.d.ts.map +1 -0
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.js +28 -0
- package/dist/lib/modules/tournament/notification/jobs/notification.producer.js.map +1 -0
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.d.ts +7 -0
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.d.ts.map +1 -0
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.js +76 -0
- package/dist/lib/modules/tournament/notification/jobs/notification.worker.js.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.d.ts +10 -0
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.js +86 -0
- package/dist/lib/modules/tournament/notification/notification.scheduler.service.js.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.service.d.ts +11 -0
- package/dist/lib/modules/tournament/notification/notification.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/notification/notification.service.js +101 -0
- package/dist/lib/modules/tournament/notification/notification.service.js.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.repository.d.ts +12 -0
- package/dist/lib/modules/tournament/participant/participant.repository.d.ts.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.repository.js +73 -0
- package/dist/lib/modules/tournament/participant/participant.repository.js.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.router.d.ts +104 -0
- package/dist/lib/modules/tournament/participant/participant.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.router.js +28 -0
- package/dist/lib/modules/tournament/participant/participant.router.js.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.service.d.ts +14 -0
- package/dist/lib/modules/tournament/participant/participant.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.service.js +103 -0
- package/dist/lib/modules/tournament/participant/participant.service.js.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.validation.d.ts +719 -0
- package/dist/lib/modules/tournament/participant/participant.validation.d.ts.map +1 -0
- package/dist/lib/modules/tournament/participant/participant.validation.js +44 -0
- package/dist/lib/modules/tournament/participant/participant.validation.js.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.builder.d.ts +14 -0
- package/dist/lib/modules/tournament/prediction/prediction.builder.d.ts.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.builder.js +23 -0
- package/dist/lib/modules/tournament/prediction/prediction.builder.js.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.repository.d.ts +11 -0
- package/dist/lib/modules/tournament/prediction/prediction.repository.d.ts.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.repository.js +73 -0
- package/dist/lib/modules/tournament/prediction/prediction.repository.js.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.router.d.ts +133 -0
- package/dist/lib/modules/tournament/prediction/prediction.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.router.js +36 -0
- package/dist/lib/modules/tournament/prediction/prediction.router.js.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.service.d.ts +17 -0
- package/dist/lib/modules/tournament/prediction/prediction.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.service.js +125 -0
- package/dist/lib/modules/tournament/prediction/prediction.service.js.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.validation.d.ts +575 -0
- package/dist/lib/modules/tournament/prediction/prediction.validation.d.ts.map +1 -0
- package/dist/lib/modules/tournament/prediction/prediction.validation.js +46 -0
- package/dist/lib/modules/tournament/prediction/prediction.validation.js.map +1 -0
- package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.d.ts +8 -0
- package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.d.ts.map +1 -0
- package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.js +65 -0
- package/dist/lib/modules/tournament/reward/handlers/coupon-reward.handler.js.map +1 -0
- package/dist/lib/modules/tournament/reward/reward.factory.d.ts +6 -0
- package/dist/lib/modules/tournament/reward/reward.factory.d.ts.map +1 -0
- package/dist/lib/modules/tournament/reward/reward.factory.js +21 -0
- package/dist/lib/modules/tournament/reward/reward.factory.js.map +1 -0
- package/dist/lib/modules/tournament/reward/reward.interface.d.ts +5 -0
- package/dist/lib/modules/tournament/reward/reward.interface.d.ts.map +1 -0
- package/dist/lib/modules/tournament/reward/reward.interface.js +3 -0
- package/dist/lib/modules/tournament/reward/reward.interface.js.map +1 -0
- package/dist/lib/modules/tournament/reward/reward.service.d.ts +6 -0
- package/dist/lib/modules/tournament/reward/reward.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/reward/reward.service.js +56 -0
- package/dist/lib/modules/tournament/reward/reward.service.js.map +1 -0
- package/dist/lib/modules/tournament/reward/reward.types.d.ts +11 -0
- package/dist/lib/modules/tournament/reward/reward.types.d.ts.map +1 -0
- package/dist/lib/modules/tournament/reward/reward.types.js +8 -0
- package/dist/lib/modules/tournament/reward/reward.types.js.map +1 -0
- package/dist/lib/modules/tournament/team/team.builder.d.ts +19 -0
- package/dist/lib/modules/tournament/team/team.builder.d.ts.map +1 -0
- package/dist/lib/modules/tournament/team/team.builder.js +18 -0
- package/dist/lib/modules/tournament/team/team.builder.js.map +1 -0
- package/dist/lib/modules/tournament/team/team.repository.d.ts +11 -0
- package/dist/lib/modules/tournament/team/team.repository.d.ts.map +1 -0
- package/dist/lib/modules/tournament/team/team.repository.js +71 -0
- package/dist/lib/modules/tournament/team/team.repository.js.map +1 -0
- package/dist/lib/modules/tournament/team/team.router.d.ts +237 -0
- package/dist/lib/modules/tournament/team/team.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/team/team.router.js +36 -0
- package/dist/lib/modules/tournament/team/team.router.js.map +1 -0
- package/dist/lib/modules/tournament/team/team.service.d.ts +15 -0
- package/dist/lib/modules/tournament/team/team.service.d.ts.map +1 -0
- package/dist/lib/modules/tournament/team/team.service.js +137 -0
- package/dist/lib/modules/tournament/team/team.service.js.map +1 -0
- package/dist/lib/modules/tournament/team/team.validation.d.ts +986 -0
- package/dist/lib/modules/tournament/team/team.validation.d.ts.map +1 -0
- package/dist/lib/modules/tournament/team/team.validation.js +55 -0
- package/dist/lib/modules/tournament/team/team.validation.js.map +1 -0
- package/dist/lib/modules/tournament/tournament.router.d.ts +1336 -0
- package/dist/lib/modules/tournament/tournament.router.d.ts.map +1 -0
- package/dist/lib/modules/tournament/tournament.router.js +17 -0
- package/dist/lib/modules/tournament/tournament.router.js.map +1 -0
- package/dist/types/event/event-initializations.d.ts.map +1 -1
- package/dist/types/events/event-initializations.d.ts +2 -0
- package/dist/types/events/event-initializations.d.ts.map +1 -0
- package/dist/types/index.d.ts +1414 -13
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts +72 -6
- package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/coupon.service.d.ts +1 -0
- package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/custom-coupon.service.d.ts +2 -0
- package/dist/types/modules/coupon/services/custom-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/global-coupon.service.d.ts +1 -1
- package/dist/types/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/helper.service.d.ts +2 -1
- package/dist/types/modules/coupon/services/helper.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/individual-store-coupon.service.d.ts +2 -0
- package/dist/types/modules/coupon/services/individual-store-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts +10 -4
- package/dist/types/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts +1 -1
- package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/shops-categories-coupon.service.d.ts +2 -0
- package/dist/types/modules/coupon/services/shops-categories-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts +359 -34
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +6 -6
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +6 -6
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +30 -30
- package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts +2 -0
- package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +24 -24
- package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts +36 -36
- package/dist/types/modules/marketing/validations/featured-marketing.validation.d.ts +6 -6
- package/dist/types/modules/marketing/validations/free-delivery-marketing.validation.d.ts +4 -4
- package/dist/types/modules/marketing/validations/marketing.validation.d.ts +2 -2
- package/dist/types/modules/marketing/validations/product-marketing.validation.d.ts +7 -7
- package/dist/types/modules/marketing/validations/punch-marketing.validation.d.ts +4 -4
- package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +1 -1
- package/dist/types/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +2 -2
- package/dist/types/modules/tournament/config/config.builder.d.ts +5 -0
- package/dist/types/modules/tournament/config/config.builder.d.ts.map +1 -0
- package/dist/types/modules/tournament/config/config.repository.d.ts +13 -0
- package/dist/types/modules/tournament/config/config.repository.d.ts.map +1 -0
- package/dist/types/modules/tournament/config/config.router.d.ts +363 -0
- package/dist/types/modules/tournament/config/config.router.d.ts.map +1 -0
- package/dist/types/modules/tournament/config/config.service.d.ts +14 -0
- package/dist/types/modules/tournament/config/config.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/config/config.validation.d.ts +1014 -0
- package/dist/types/modules/tournament/config/config.validation.d.ts.map +1 -0
- package/dist/types/modules/tournament/config/tournament-config.validation.d.ts +201 -0
- package/dist/types/modules/tournament/config/tournament-config.validation.d.ts.map +1 -0
- package/dist/types/modules/tournament/match/events/match-ended.consumer.d.ts +2 -0
- package/dist/types/modules/tournament/match/events/match-ended.consumer.d.ts.map +1 -0
- package/dist/types/modules/tournament/match/events/match-ended.event.d.ts +14 -0
- package/dist/types/modules/tournament/match/events/match-ended.event.d.ts.map +1 -0
- package/dist/types/modules/tournament/match/match.builder.d.ts +38 -0
- package/dist/types/modules/tournament/match/match.builder.d.ts.map +1 -0
- package/dist/types/modules/tournament/match/match.repository.d.ts +13 -0
- package/dist/types/modules/tournament/match/match.repository.d.ts.map +1 -0
- package/dist/types/modules/tournament/match/match.router.d.ts +489 -0
- package/dist/types/modules/tournament/match/match.router.d.ts.map +1 -0
- package/dist/types/modules/tournament/match/match.service.d.ts +29 -0
- package/dist/types/modules/tournament/match/match.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/match/match.validation.d.ts +880 -0
- package/dist/types/modules/tournament/match/match.validation.d.ts.map +1 -0
- package/dist/types/modules/tournament/notification/jobs/notification.producer.d.ts +13 -0
- package/dist/types/modules/tournament/notification/jobs/notification.producer.d.ts.map +1 -0
- package/dist/types/modules/tournament/notification/jobs/notification.worker.d.ts +7 -0
- package/dist/types/modules/tournament/notification/jobs/notification.worker.d.ts.map +1 -0
- package/dist/types/modules/tournament/notification/notification.scheduler.service.d.ts +10 -0
- package/dist/types/modules/tournament/notification/notification.scheduler.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/notification/notification.service.d.ts +11 -0
- package/dist/types/modules/tournament/notification/notification.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/participant/participant.repository.d.ts +12 -0
- package/dist/types/modules/tournament/participant/participant.repository.d.ts.map +1 -0
- package/dist/types/modules/tournament/participant/participant.router.d.ts +104 -0
- package/dist/types/modules/tournament/participant/participant.router.d.ts.map +1 -0
- package/dist/types/modules/tournament/participant/participant.service.d.ts +14 -0
- package/dist/types/modules/tournament/participant/participant.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/participant/participant.validation.d.ts +719 -0
- package/dist/types/modules/tournament/participant/participant.validation.d.ts.map +1 -0
- package/dist/types/modules/tournament/prediction/prediction.builder.d.ts +14 -0
- package/dist/types/modules/tournament/prediction/prediction.builder.d.ts.map +1 -0
- package/dist/types/modules/tournament/prediction/prediction.repository.d.ts +11 -0
- package/dist/types/modules/tournament/prediction/prediction.repository.d.ts.map +1 -0
- package/dist/types/modules/tournament/prediction/prediction.router.d.ts +133 -0
- package/dist/types/modules/tournament/prediction/prediction.router.d.ts.map +1 -0
- package/dist/types/modules/tournament/prediction/prediction.service.d.ts +17 -0
- package/dist/types/modules/tournament/prediction/prediction.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/prediction/prediction.validation.d.ts +575 -0
- package/dist/types/modules/tournament/prediction/prediction.validation.d.ts.map +1 -0
- package/dist/types/modules/tournament/reward/handlers/coupon-reward.handler.d.ts +8 -0
- package/dist/types/modules/tournament/reward/handlers/coupon-reward.handler.d.ts.map +1 -0
- package/dist/types/modules/tournament/reward/reward.factory.d.ts +6 -0
- package/dist/types/modules/tournament/reward/reward.factory.d.ts.map +1 -0
- package/dist/types/modules/tournament/reward/reward.interface.d.ts +5 -0
- package/dist/types/modules/tournament/reward/reward.interface.d.ts.map +1 -0
- package/dist/types/modules/tournament/reward/reward.service.d.ts +6 -0
- package/dist/types/modules/tournament/reward/reward.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/reward/reward.types.d.ts +11 -0
- package/dist/types/modules/tournament/reward/reward.types.d.ts.map +1 -0
- package/dist/types/modules/tournament/team/team.builder.d.ts +19 -0
- package/dist/types/modules/tournament/team/team.builder.d.ts.map +1 -0
- package/dist/types/modules/tournament/team/team.repository.d.ts +11 -0
- package/dist/types/modules/tournament/team/team.repository.d.ts.map +1 -0
- package/dist/types/modules/tournament/team/team.router.d.ts +237 -0
- package/dist/types/modules/tournament/team/team.router.d.ts.map +1 -0
- package/dist/types/modules/tournament/team/team.service.d.ts +15 -0
- package/dist/types/modules/tournament/team/team.service.d.ts.map +1 -0
- package/dist/types/modules/tournament/team/team.validation.d.ts +986 -0
- package/dist/types/modules/tournament/team/team.validation.d.ts.map +1 -0
- package/dist/types/modules/tournament/tournament.router.d.ts +1336 -0
- package/dist/types/modules/tournament/tournament.router.d.ts.map +1 -0
- package/package.json +3 -3
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts +0 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts.map +0 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js +0 -2
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js.map +0 -1
|
@@ -20,7 +20,7 @@ export declare class CouponHelperService {
|
|
|
20
20
|
discountAmount: number;
|
|
21
21
|
secondaryDiscountAmount: number;
|
|
22
22
|
}>;
|
|
23
|
-
buildCouponResponse(data: ValidateCouponDTO, discountAmount: number, secondaryDiscountAmount: number, isShopCoverExpenses: boolean, couponDetails?: Record<string, any>): CouponValidationOutputDTO;
|
|
23
|
+
buildCouponResponse(coupon: any, data: ValidateCouponDTO, discountAmount: number, secondaryDiscountAmount: number, isShopCoverExpenses: boolean, couponDetails?: Record<string, any>): CouponValidationOutputDTO;
|
|
24
24
|
validateShopEligibility({ data, coupon }: {
|
|
25
25
|
data: ValidateCouponDTO;
|
|
26
26
|
coupon: any;
|
|
@@ -232,6 +232,7 @@ export declare class CouponHelperService {
|
|
|
232
232
|
} | undefined;
|
|
233
233
|
isMenuDietaryFilterEnabled?: boolean | undefined;
|
|
234
234
|
categoryNumberingEnabled?: boolean | undefined;
|
|
235
|
+
hideOutOfStockProducts?: boolean | undefined;
|
|
235
236
|
createdAt?: Date | undefined;
|
|
236
237
|
updatedAt?: Date | undefined;
|
|
237
238
|
}> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.service.d.ts","sourceRoot":"/","sources":["modules/coupon/services/helper.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACN,UAAU,EAYV,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAA4C,SAAS,EAAE,MAAM,mCAAmC,CAAC;AACxG,OAAc,EAAE,KAAK,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAI9E,qBACa,mBAAmB;IAC/B,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,UAAU,CAA2D;IAC7E,OAAO,CAAC,mBAAmB,CAA6B;IACxD,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,WAAW,CAA+C;IAClE,OAAO,CAAC,cAAc,CAAoD;;IAW1E,OAAO,KAAK,aAAa,GAKxB;IAEY,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC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,4BAA4B;IAmB7B,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CAS5E;AAED,eAAO,MAAM,mBAAmB,qBAAqC,CAAC"}
|
|
@@ -206,7 +206,7 @@ let CouponHelperService = class CouponHelperService {
|
|
|
206
206
|
secondaryDiscountAmount = Math.min(secondaryDiscountAmount, data.secondaryAmountBeforeCoupon);
|
|
207
207
|
return { discountAmount, secondaryDiscountAmount };
|
|
208
208
|
}
|
|
209
|
-
buildCouponResponse(data, discountAmount, secondaryDiscountAmount, isShopCoverExpenses, couponDetails) {
|
|
209
|
+
buildCouponResponse(coupon, data, discountAmount, secondaryDiscountAmount, isShopCoverExpenses, couponDetails) {
|
|
210
210
|
return {
|
|
211
211
|
isValid: true,
|
|
212
212
|
discountAmount,
|
|
@@ -222,6 +222,12 @@ let CouponHelperService = class CouponHelperService {
|
|
|
222
222
|
secondaryShopCut: isShopCoverExpenses && !data.vendor ? secondaryDiscountAmount : 0,
|
|
223
223
|
},
|
|
224
224
|
couponDetails,
|
|
225
|
+
couponInfo: {
|
|
226
|
+
_id: coupon._id,
|
|
227
|
+
couponType: coupon.couponType,
|
|
228
|
+
valueType: coupon.valueType,
|
|
229
|
+
value: coupon.value,
|
|
230
|
+
},
|
|
225
231
|
};
|
|
226
232
|
}
|
|
227
233
|
async validateShopEligibility({ data, coupon }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.service.js","sourceRoot":"/","sources":["modules/coupon/services/helper.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,oDAA8D;AAC9D,sEAamD;AAEnD,4DAAwG;AACxG,qFAAwE;AAExE,oEAA2E;AAC3E,gEAAgG;AAGzF,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IACvB,SAAS,CAA2C;IACpD,UAAU,CAA2D;IACrE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,\n\tRegularOrderModel,\n\tServiceBooking,\n\tServiceBookingModel,\n\tShop,\n\tShopModel,\n\tUser,\n\tUserModel,\n\tVendor,\n\tVendorModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { RegularOrderStatus, ServiceBookingStatus, ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport dayjs, { Dayjs } from '@lyxa.ai/core/dist/utilities/dayjs/dayjs';\nimport { CouponValidationOutputDTO, ValidateCouponDTO } from '../validations';\nimport { convertToSecondary } from '@lyxa.ai/core/dist/utilities/currency';\nimport { roundBaseCurrency, roundSecondaryCurrency } from '@lyxa.ai/core/dist/utilities/shared';\n\n@Service()\nexport class CouponHelperService {\n\tprivate userModel: typeof UserModel & SoftDeleteModel<User>;\n\tprivate orderModel: typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\tprivate serviceBookingModel: typeof ServiceBookingModel;\n\tprivate shopModel: typeof ShopModel & SoftDeleteModel<Shop>;\n\tprivate vendorModel: typeof VendorModel & SoftDeleteModel<Vendor>;\n\tprivate _coreUserModel: ReturnType<typeof getCoreUserModel> | null = null;\n\n\tconstructor() {\n\t\tthis.userModel = UserModel as typeof UserModel & SoftDeleteModel<User>;\n\t\tthis.orderModel = RegularOrderModel as typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\t\tthis.serviceBookingModel = ServiceBookingModel as typeof ServiceBookingModel &\n\t\t\tSoftDeleteModel<ServiceBooking>;\n\t\tthis.shopModel = ShopModel as typeof ShopModel & SoftDeleteModel<Shop>;\n\t\tthis.vendorModel = VendorModel as typeof VendorModel & SoftDeleteModel<Vendor>;\n\t}\n\n\tprivate get coreUserModel() {\n\t\tif (!this._coreUserModel) {\n\t\t\tthis._coreUserModel = getCoreUserModel();\n\t\t}\n\t\treturn this._coreUserModel;\n\t}\n\n\tpublic async isNewUser(user: mongoose.Types.ObjectId): Promise<boolean> {\n\t\tlet users = [user._id.toString()];\n\n\t\tconst existingUser = await this.userModel.findOne({\n\t\t\t_id: user,\n\t\t});\n\n\t\tconst sameDeviceUsers = await this.userModel.findWithDeleted({\n\t\t\tdeviceId: existingUser?.deviceId,\n\t\t});\n\n\t\tsameDeviceUsers.forEach((u: any) => {\n\t\t\tif (!users.includes(u._id.toString())) {\n\t\t\t\tusers.push(u._id.toString());\n\t\t\t}\n\t\t});\n\n\t\tconst [orderCount, bookingCount] = await Promise.all([\n\t\t\tthis.orderModel.countDocuments({\n\t\t\t\tuser: { $in: users },\n\t\t\t\tstatus: { $ne: RegularOrderStatus.CANCELLED },\n\t\t\t}),\n\t\t\tthis.serviceBookingModel.countDocuments({\n\t\t\t\tuser: { $in: users },\n\t\t\t\tstatus: { $ne: ServiceBookingStatus.CANCELLED },\n\t\t\t}),\n\t\t]);\n\n\t\treturn orderCount + bookingCount < 1;\n\t}\n\n\tpublic async getSameDeviceOrdersWithCoupon(\n\t\tuser: mongoose.Types.ObjectId,\n\t\tcoupon: DocumentType<BaseCoupon>\n\t): Promise<number> {\n\t\tlet users = [user._id.toString()];\n\n\t\tconst existingUser = await this.userModel.findOne({\n\t\t\t_id: user,\n\t\t});\n\n\t\tconst sameDeviceUsers = await this.userModel.findWithDeleted({\n\t\t\tdeviceId: existingUser?.deviceId,\n\t\t});\n\n\t\tsameDeviceUsers.forEach((u: any) => {\n\t\t\tif (!users.includes(u._id.toString())) {\n\t\t\t\tusers.push(u._id.toString());\n\t\t\t}\n\t\t});\n\n\t\tconst [orderCount, bookingCount] = await Promise.all([\n\t\t\tthis.orderModel.countDocuments({\n\t\t\t\tuser: { $in: users },\n\t\t\t\tstatus: { $ne: RegularOrderStatus.CANCELLED },\n\t\t\t\t'adjustedFinance.coupon.coupon': coupon._id,\n\t\t\t}),\n\t\t\tthis.serviceBookingModel.countDocuments({\n\t\t\t\tuser: { $in: users },\n\t\t\t\tstatus: { $ne: ServiceBookingStatus.CANCELLED },\n\t\t\t\t'adjustedFinance.coupon.coupon': coupon._id,\n\t\t\t}),\n\t\t]);\n\n\t\treturn orderCount + bookingCount;\n\t}\n\n\tpublic async getNewUsers(): Promise<mongoose.Types.ObjectId[]> {\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\t// Step 1: Lookup all users who share the same deviceId\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'users',\n\t\t\t\t\tlocalField: 'deviceId',\n\t\t\t\t\tforeignField: 'deviceId',\n\t\t\t\t\tas: 'sameDeviceUsers',\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Step 2: Collect the list of userIds belonging to this device\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tallUserIds: {\n\t\t\t\t\t\t$map: {\n\t\t\t\t\t\t\tinput: '$sameDeviceUsers',\n\t\t\t\t\t\t\tas: 'u',\n\t\t\t\t\t\t\tin: '$$u._id',\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// Step 3: Lookup orders attached to any of these users\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'orders',\n\t\t\t\t\tlet: { ids: '$allUserIds' },\n\t\t\t\t\tpipeline: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$expr: {\n\t\t\t\t\t\t\t\t\t$and: [{ $in: ['$user', '$$ids'] }, { $ne: ['$status', 'CANCELLED'] }],\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\tas: 'orders',\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Step 4: Count orders\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\torderCount: { $size: '$orders' },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Step 5: New user = zero or one non-cancelled order\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\torderCount: { $lte: 1 },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Optional: Remove temporary fields\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\tsameDeviceUsers: 0,\n\t\t\t\t\tallUserIds: 0,\n\t\t\t\t\torders: 0,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\tconst newUsers = await this.userModel.aggregate(pipeline).exec();\n\n\t\treturn newUsers.map(u => u._id);\n\t}\n\n\tpublic isDurationValid(start: Dayjs, end: Dayjs): boolean {\n\t\tconst getRoundedHourBack = (hoursBack = 0) => {\n\t\t\treturn dayjs().subtract(hoursBack, 'hour').startOf('hour');\n\t\t};\n\n\t\tconst cutoffTime = getRoundedHourBack();\n\n\t\treturn start >= cutoffTime && end >= cutoffTime;\n\t}\n\n\tpublic async calculateCouponDiscount(data: ValidateCouponDTO, coupon: DocumentType<BaseCoupon>) {\n\t\tlet discountAmount =\n\t\t\tcoupon.valueType === ValueType.FIXED\n\t\t\t\t? coupon.value\n\t\t\t\t: roundBaseCurrency((data.amountBeforeCoupon * coupon.value) / 100);\n\n\t\tlet secondaryDiscountAmount =\n\t\t\tcoupon.valueType === ValueType.FIXED\n\t\t\t\t? await convertToSecondary(coupon.value)\n\t\t\t\t: roundSecondaryCurrency((data.secondaryAmountBeforeCoupon * coupon.value) / 100);\n\n\t\tif (coupon.isMaxDiscountLimitEnabled && coupon.maxDiscountLimit) {\n\t\t\tconst secondaryMax = await convertToSecondary(coupon.maxDiscountLimit);\n\n\t\t\tdiscountAmount = Math.min(discountAmount, coupon.maxDiscountLimit);\n\t\t\tsecondaryDiscountAmount = Math.min(secondaryDiscountAmount, secondaryMax);\n\t\t}\n\n\t\t// Prevent negative totals\n\t\tdiscountAmount = Math.min(discountAmount, data.amountBeforeCoupon);\n\t\tsecondaryDiscountAmount = Math.min(secondaryDiscountAmount, data.secondaryAmountBeforeCoupon);\n\n\t\treturn { discountAmount, secondaryDiscountAmount };\n\t}\n\n\tpublic buildCouponResponse(\n\t\tdata: ValidateCouponDTO,\n\t\tdiscountAmount: number,\n\t\tsecondaryDiscountAmount: number,\n\t\tisShopCoverExpenses: boolean,\n\t\tcouponDetails?: Record<string, any>\n\t): CouponValidationOutputDTO {\n\t\treturn {\n\t\t\tisValid: true,\n\t\t\tdiscountAmount,\n\t\t\tsecondaryDiscountAmount,\n\t\t\tamountAfterCoupon: roundBaseCurrency(data.amountBeforeCoupon - discountAmount),\n\t\t\tsecondaryAmountAfterCoupon: roundSecondaryCurrency(\n\t\t\t\tdata.secondaryAmountBeforeCoupon - secondaryDiscountAmount\n\t\t\t),\n\t\t\tdiscountCut: {\n\t\t\t\tcompanyCut: isShopCoverExpenses ? 0 : discountAmount,\n\t\t\t\tsecondaryCompanyCut: isShopCoverExpenses ? 0 : secondaryDiscountAmount,\n\t\t\t\tvendorCut: isShopCoverExpenses && data.vendor ? discountAmount : 0,\n\t\t\t\tsecondaryVendorCut: isShopCoverExpenses && data.vendor ? secondaryDiscountAmount : 0,\n\t\t\t\tshopCut: isShopCoverExpenses && !data.vendor ? discountAmount : 0,\n\t\t\t\tsecondaryShopCut: isShopCoverExpenses && !data.vendor ? secondaryDiscountAmount : 0,\n\t\t\t},\n\t\t\tcouponDetails,\n\t\t};\n\t}\n\n\tpublic async validateShopEligibility({ data, coupon }: { data: ValidateCouponDTO; coupon: any }) {\n\t\tif (data.vendor) {\n\t\t\treturn this.validateVendorEligibility({ data, coupon });\n\t\t}\n\n\t\tconst shop = await this.shopModel\n\t\t\t.findOne({\n\t\t\t\t_id: new mongoose.Types.ObjectId(data.shop),\n\t\t\t\tdeletedAt: null,\n\t\t\t})\n\t\t\t.lean();\n\n\t\tif (!shop) return { isValid: false, message: 'Shop not found' };\n\n\t\tconst singleShopError = await this.validateSingleShopRestriction(shop, coupon);\n\t\tif (singleShopError) return singleShopError;\n\n\t\tconst restrictionError = this.validateMultiRestrictions(shop, coupon);\n\t\tif (restrictionError) return restrictionError;\n\n\t\tconst firstOrderError = await this.validateFirstOrderOnly(data, shop, coupon);\n\t\tif (firstOrderError) return firstOrderError;\n\n\t\treturn { isValid: true, shop };\n\t}\n\n\tprivate async validateVendorEligibility({ data, coupon }: { data: ValidateCouponDTO; coupon: any }) {\n\t\tconst vendor = await this.vendorModel\n\t\t\t.findOne({\n\t\t\t\t_id: new mongoose.Types.ObjectId(data.vendor),\n\t\t\t})\n\t\t\t.lean();\n\n\t\tif (!vendor) return { isValid: false, message: 'Vendor not found' };\n\n\t\tconst singleVendorError = await this.validateSingleVendorRestriction(vendor, coupon);\n\t\tif (singleVendorError) return singleVendorError;\n\n\t\tconst restrictionError = this.validateVendorMultiRestrictions(vendor, coupon);\n\t\tif (restrictionError) return restrictionError;\n\n\t\tconst firstOrderError = await this.validateVendorFirstOrderOnly(data, vendor, coupon);\n\t\tif (firstOrderError) return firstOrderError;\n\n\t\treturn { isValid: true, vendor };\n\t}\n\n\tprivate async validateSingleShopRestriction(shop: any, coupon: any) {\n\t\tif (!coupon.shop) return null;\n\n\t\tconst couponShopId = coupon.shop.toString();\n\t\tconst currentShopId = shop._id.toString();\n\n\t\tif (couponShopId === currentShopId) return null;\n\n\t\tconst validShop = await this.shopModel\n\t\t\t.findOne({ _id: coupon.shop, deletedAt: null })\n\t\t\t.select('name')\n\t\t\t.lean();\n\n\t\tif (!validShop) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: 'Coupon is associated with an invalid shop',\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tisValid: false,\n\t\t\tmessage: `This coupon can be used at ${validShop.name} only`,\n\t\t};\n\t}\n\n\tprivate validateMultiRestrictions(shop: any, coupon: any) {\n\t\tconst hasShopRestriction = Array.isArray(coupon.shops) && coupon.shops.length > 0;\n\t\tconst hasItemTypeRestriction = Array.isArray(coupon.itemTypes) && coupon.itemTypes.length > 0;\n\n\t\tif (!hasShopRestriction && !hasItemTypeRestriction) return null;\n\n\t\tconst shopMatches =\n\t\t\thasShopRestriction &&\n\t\t\tcoupon.shops.some((couponShop: any) => couponShop._id.toString() === shop._id.toString());\n\n\t\tconst itemTypeMatches = hasItemTypeRestriction && coupon.itemTypes.includes(shop.itemType);\n\n\t\tif (!shopMatches && !itemTypeMatches) {\n\t\t\tconst shopNames = coupon.shops.map((shop: any) => shop.name).join(', ');\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: `This coupon can be used at ${shopNames}`,\n\t\t\t};\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate async validateSingleVendorRestriction(vendor: any, coupon: any) {\n\t\tif (!coupon.vendor) return null;\n\n\t\tconst couponVendorId = coupon.vendor.toString();\n\t\tconst currentVendorId = vendor._id.toString();\n\n\t\tif (couponVendorId === currentVendorId) return null;\n\n\t\tconst validVendor = await this.vendorModel.findOne({ _id: coupon.vendor }).select('name').lean();\n\n\t\tif (!validVendor) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: 'Coupon is associated with an invalid vendor',\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tisValid: false,\n\t\t\tmessage: `This coupon can be used at ${validVendor.name} only`,\n\t\t};\n\t}\n\n\tprivate validateVendorMultiRestrictions(vendor: any, coupon: any) {\n\t\tconst hasVendorRestriction = Array.isArray(coupon.vendors) && coupon.vendors.length > 0;\n\t\tconst hasItemTypeRestriction = Array.isArray(coupon.itemTypes) && coupon.itemTypes.length > 0;\n\n\t\tif (!hasVendorRestriction && !hasItemTypeRestriction) return null;\n\n\t\tconst vendorMatches =\n\t\t\thasVendorRestriction &&\n\t\t\tcoupon.vendors.some((couponVendor: any) => couponVendor._id.toString() === vendor._id.toString());\n\n\t\tconst itemTypeMatches = hasItemTypeRestriction && coupon.itemTypes.includes(vendor.serviceType);\n\n\t\tif (!vendorMatches && !itemTypeMatches) {\n\t\t\tconst vendorNames = coupon.vendors.map((vendor: any) => vendor.name).join(', ');\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: `This coupon can be used at ${vendorNames}`,\n\t\t\t};\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate async validateFirstOrderOnly(data: ValidateCouponDTO, shop: any, coupon: any) {\n\t\tif (!coupon.firstOrderOnly) return null;\n\n\t\tconst existingOrder = await this.orderModel.exists({\n\t\t\tuser: new mongoose.Types.ObjectId(data.user),\n\t\t\tshop: shop._id,\n\t\t\tstatus: { $ne: RegularOrderStatus.CANCELLED },\n\t\t});\n\n\t\tif (existingOrder) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: 'This coupon is only valid for the first order in the shop',\n\t\t\t};\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate async validateVendorFirstOrderOnly(data: ValidateCouponDTO, vendor: any, coupon: any) {\n\t\tif (!coupon.firstOrderOnly) return null;\n\n\t\tconst existingBooking = await this.serviceBookingModel.exists({\n\t\t\tuser: new mongoose.Types.ObjectId(data.user),\n\t\t\tvendor: vendor._id,\n\t\t\tstatus: { $ne: ServiceBookingStatus.CANCELLED },\n\t\t});\n\n\t\tif (existingBooking) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: 'This coupon is only valid for the first order in the vendor',\n\t\t\t};\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tpublic async fetchUserName(userId: mongoose.Types.ObjectId): Promise<string> {\n\t\tconst user = await this.userModel.findById(userId).select('coreUser').lean();\n\n\t\tif (!user) return 'Unknown User';\n\n\t\tconst coreUser = await this.coreUserModel.findById(user.coreUser).select('name').lean();\n\n\t\treturn coreUser ? coreUser.name : 'Unknown User';\n\t}\n}\n\nexport const couponHelperService = Container.get(CouponHelperService);\n"]}
|
|
1
|
+
{"version":3,"file":"helper.service.js","sourceRoot":"/","sources":["modules/coupon/services/helper.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,oDAA8D;AAC9D,sEAamD;AAEnD,4DAAwG;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AAC,CAAC,cAAc,CAAC;IAClD,CAAC;CACD,CAAA;AAraY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,gBAAO,GAAE;;GACG,mBAAmB,CAqa/B;AAEY,QAAA,mBAAmB,GAAG,gBAAS,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tBaseCoupon,\n\tgetCoreUserModel,\n\tRegularOrder,\n\tRegularOrderModel,\n\tServiceBooking,\n\tServiceBookingModel,\n\tShop,\n\tShopModel,\n\tUser,\n\tUserModel,\n\tVendor,\n\tVendorModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { RegularOrderStatus, ServiceBookingStatus, ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport dayjs, { Dayjs } from '@lyxa.ai/core/dist/utilities/dayjs/dayjs';\nimport { CouponValidationOutputDTO, ValidateCouponDTO } from '../validations';\nimport { convertToSecondary } from '@lyxa.ai/core/dist/utilities/currency';\nimport { roundBaseCurrency, roundSecondaryCurrency } from '@lyxa.ai/core/dist/utilities/shared';\n\n@Service()\nexport class CouponHelperService {\n\tprivate userModel: typeof UserModel & SoftDeleteModel<User>;\n\tprivate orderModel: typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\tprivate serviceBookingModel: typeof ServiceBookingModel;\n\tprivate shopModel: typeof ShopModel & SoftDeleteModel<Shop>;\n\tprivate vendorModel: typeof VendorModel & SoftDeleteModel<Vendor>;\n\tprivate _coreUserModel: ReturnType<typeof getCoreUserModel> | null = null;\n\n\tconstructor() {\n\t\tthis.userModel = UserModel as typeof UserModel & SoftDeleteModel<User>;\n\t\tthis.orderModel = RegularOrderModel as typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\t\tthis.serviceBookingModel = ServiceBookingModel as typeof ServiceBookingModel &\n\t\t\tSoftDeleteModel<ServiceBooking>;\n\t\tthis.shopModel = ShopModel as typeof ShopModel & SoftDeleteModel<Shop>;\n\t\tthis.vendorModel = VendorModel as typeof VendorModel & SoftDeleteModel<Vendor>;\n\t}\n\n\tprivate get coreUserModel() {\n\t\tif (!this._coreUserModel) {\n\t\t\tthis._coreUserModel = getCoreUserModel();\n\t\t}\n\t\treturn this._coreUserModel;\n\t}\n\n\tpublic async isNewUser(user: mongoose.Types.ObjectId): Promise<boolean> {\n\t\tlet users = [user._id.toString()];\n\n\t\tconst existingUser = await this.userModel.findOne({\n\t\t\t_id: user,\n\t\t});\n\n\t\tconst sameDeviceUsers = await this.userModel.findWithDeleted({\n\t\t\tdeviceId: existingUser?.deviceId,\n\t\t});\n\n\t\tsameDeviceUsers.forEach((u: any) => {\n\t\t\tif (!users.includes(u._id.toString())) {\n\t\t\t\tusers.push(u._id.toString());\n\t\t\t}\n\t\t});\n\n\t\tconst [orderCount, bookingCount] = await Promise.all([\n\t\t\tthis.orderModel.countDocuments({\n\t\t\t\tuser: { $in: users },\n\t\t\t\tstatus: { $ne: RegularOrderStatus.CANCELLED },\n\t\t\t}),\n\t\t\tthis.serviceBookingModel.countDocuments({\n\t\t\t\tuser: { $in: users },\n\t\t\t\tstatus: { $ne: ServiceBookingStatus.CANCELLED },\n\t\t\t}),\n\t\t]);\n\n\t\treturn orderCount + bookingCount < 1;\n\t}\n\n\tpublic async getSameDeviceOrdersWithCoupon(\n\t\tuser: mongoose.Types.ObjectId,\n\t\tcoupon: DocumentType<BaseCoupon>\n\t): Promise<number> {\n\t\tlet users = [user._id.toString()];\n\n\t\tconst existingUser = await this.userModel.findOne({\n\t\t\t_id: user,\n\t\t});\n\n\t\tconst sameDeviceUsers = await this.userModel.findWithDeleted({\n\t\t\tdeviceId: existingUser?.deviceId,\n\t\t});\n\n\t\tsameDeviceUsers.forEach((u: any) => {\n\t\t\tif (!users.includes(u._id.toString())) {\n\t\t\t\tusers.push(u._id.toString());\n\t\t\t}\n\t\t});\n\n\t\tconst [orderCount, bookingCount] = await Promise.all([\n\t\t\tthis.orderModel.countDocuments({\n\t\t\t\tuser: { $in: users },\n\t\t\t\tstatus: { $ne: RegularOrderStatus.CANCELLED },\n\t\t\t\t'adjustedFinance.coupon.coupon': coupon._id,\n\t\t\t}),\n\t\t\tthis.serviceBookingModel.countDocuments({\n\t\t\t\tuser: { $in: users },\n\t\t\t\tstatus: { $ne: ServiceBookingStatus.CANCELLED },\n\t\t\t\t'adjustedFinance.coupon.coupon': coupon._id,\n\t\t\t}),\n\t\t]);\n\n\t\treturn orderCount + bookingCount;\n\t}\n\n\tpublic async getNewUsers(): Promise<mongoose.Types.ObjectId[]> {\n\t\tconst pipeline: mongoose.PipelineStage[] = [\n\t\t\t// Step 1: Lookup all users who share the same deviceId\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'users',\n\t\t\t\t\tlocalField: 'deviceId',\n\t\t\t\t\tforeignField: 'deviceId',\n\t\t\t\t\tas: 'sameDeviceUsers',\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Step 2: Collect the list of userIds belonging to this device\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tallUserIds: {\n\t\t\t\t\t\t$map: {\n\t\t\t\t\t\t\tinput: '$sameDeviceUsers',\n\t\t\t\t\t\t\tas: 'u',\n\t\t\t\t\t\t\tin: '$$u._id',\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// Step 3: Lookup orders attached to any of these users\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'orders',\n\t\t\t\t\tlet: { ids: '$allUserIds' },\n\t\t\t\t\tpipeline: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$match: {\n\t\t\t\t\t\t\t\t$expr: {\n\t\t\t\t\t\t\t\t\t$and: [{ $in: ['$user', '$$ids'] }, { $ne: ['$status', 'CANCELLED'] }],\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\tas: 'orders',\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Step 4: Count orders\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\torderCount: { $size: '$orders' },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Step 5: New user = zero or one non-cancelled order\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\torderCount: { $lte: 1 },\n\t\t\t\t},\n\t\t\t},\n\n\t\t\t// Optional: Remove temporary fields\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\tsameDeviceUsers: 0,\n\t\t\t\t\tallUserIds: 0,\n\t\t\t\t\torders: 0,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\tconst newUsers = await this.userModel.aggregate(pipeline).exec();\n\n\t\treturn newUsers.map(u => u._id);\n\t}\n\n\tpublic isDurationValid(start: Dayjs, end: Dayjs): boolean {\n\t\tconst getRoundedHourBack = (hoursBack = 0) => {\n\t\t\treturn dayjs().subtract(hoursBack, 'hour').startOf('hour');\n\t\t};\n\n\t\tconst cutoffTime = getRoundedHourBack();\n\n\t\treturn start >= cutoffTime && end >= cutoffTime;\n\t}\n\n\tpublic async calculateCouponDiscount(data: ValidateCouponDTO, coupon: DocumentType<BaseCoupon>) {\n\t\tlet discountAmount =\n\t\t\tcoupon.valueType === ValueType.FIXED\n\t\t\t\t? coupon.value\n\t\t\t\t: roundBaseCurrency((data.amountBeforeCoupon * coupon.value) / 100);\n\n\t\tlet secondaryDiscountAmount =\n\t\t\tcoupon.valueType === ValueType.FIXED\n\t\t\t\t? await convertToSecondary(coupon.value)\n\t\t\t\t: roundSecondaryCurrency((data.secondaryAmountBeforeCoupon * coupon.value) / 100);\n\n\t\tif (coupon.isMaxDiscountLimitEnabled && coupon.maxDiscountLimit) {\n\t\t\tconst secondaryMax = await convertToSecondary(coupon.maxDiscountLimit);\n\n\t\t\tdiscountAmount = Math.min(discountAmount, coupon.maxDiscountLimit);\n\t\t\tsecondaryDiscountAmount = Math.min(secondaryDiscountAmount, secondaryMax);\n\t\t}\n\n\t\t// Prevent negative totals\n\t\tdiscountAmount = Math.min(discountAmount, data.amountBeforeCoupon);\n\t\tsecondaryDiscountAmount = Math.min(secondaryDiscountAmount, data.secondaryAmountBeforeCoupon);\n\n\t\treturn { discountAmount, secondaryDiscountAmount };\n\t}\n\n\tpublic buildCouponResponse(\n\t\tcoupon: any,\n\t\tdata: ValidateCouponDTO,\n\t\tdiscountAmount: number,\n\t\tsecondaryDiscountAmount: number,\n\t\tisShopCoverExpenses: boolean,\n\t\tcouponDetails?: Record<string, any>\n\t): CouponValidationOutputDTO {\n\t\treturn {\n\t\t\tisValid: true,\n\t\t\tdiscountAmount,\n\t\t\tsecondaryDiscountAmount,\n\t\t\tamountAfterCoupon: roundBaseCurrency(data.amountBeforeCoupon - discountAmount),\n\t\t\tsecondaryAmountAfterCoupon: roundSecondaryCurrency(\n\t\t\t\tdata.secondaryAmountBeforeCoupon - secondaryDiscountAmount\n\t\t\t),\n\t\t\tdiscountCut: {\n\t\t\t\tcompanyCut: isShopCoverExpenses ? 0 : discountAmount,\n\t\t\t\tsecondaryCompanyCut: isShopCoverExpenses ? 0 : secondaryDiscountAmount,\n\t\t\t\tvendorCut: isShopCoverExpenses && data.vendor ? discountAmount : 0,\n\t\t\t\tsecondaryVendorCut: isShopCoverExpenses && data.vendor ? secondaryDiscountAmount : 0,\n\t\t\t\tshopCut: isShopCoverExpenses && !data.vendor ? discountAmount : 0,\n\t\t\t\tsecondaryShopCut: isShopCoverExpenses && !data.vendor ? secondaryDiscountAmount : 0,\n\t\t\t},\n\t\t\tcouponDetails,\n\t\t\tcouponInfo: {\n\t\t\t\t_id: coupon._id,\n\t\t\t\tcouponType: coupon.couponType,\n\t\t\t\tvalueType: coupon.valueType,\n\t\t\t\tvalue: coupon.value,\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic async validateShopEligibility({ data, coupon }: { data: ValidateCouponDTO; coupon: any }) {\n\t\tif (data.vendor) {\n\t\t\treturn this.validateVendorEligibility({ data, coupon });\n\t\t}\n\n\t\tconst shop = await this.shopModel\n\t\t\t.findOne({\n\t\t\t\t_id: new mongoose.Types.ObjectId(data.shop),\n\t\t\t\tdeletedAt: null,\n\t\t\t})\n\t\t\t.lean();\n\n\t\tif (!shop) return { isValid: false, message: 'Shop not found' };\n\n\t\tconst singleShopError = await this.validateSingleShopRestriction(shop, coupon);\n\t\tif (singleShopError) return singleShopError;\n\n\t\tconst restrictionError = this.validateMultiRestrictions(shop, coupon);\n\t\tif (restrictionError) return restrictionError;\n\n\t\tconst firstOrderError = await this.validateFirstOrderOnly(data, shop, coupon);\n\t\tif (firstOrderError) return firstOrderError;\n\n\t\treturn { isValid: true, shop };\n\t}\n\n\tprivate async validateVendorEligibility({ data, coupon }: { data: ValidateCouponDTO; coupon: any }) {\n\t\tconst vendor = await this.vendorModel\n\t\t\t.findOne({\n\t\t\t\t_id: new mongoose.Types.ObjectId(data.vendor),\n\t\t\t})\n\t\t\t.lean();\n\n\t\tif (!vendor) return { isValid: false, message: 'Vendor not found' };\n\n\t\tconst singleVendorError = await this.validateSingleVendorRestriction(vendor, coupon);\n\t\tif (singleVendorError) return singleVendorError;\n\n\t\tconst restrictionError = this.validateVendorMultiRestrictions(vendor, coupon);\n\t\tif (restrictionError) return restrictionError;\n\n\t\tconst firstOrderError = await this.validateVendorFirstOrderOnly(data, vendor, coupon);\n\t\tif (firstOrderError) return firstOrderError;\n\n\t\treturn { isValid: true, vendor };\n\t}\n\n\tprivate async validateSingleShopRestriction(shop: any, coupon: any) {\n\t\tif (!coupon.shop) return null;\n\n\t\tconst couponShopId = coupon.shop.toString();\n\t\tconst currentShopId = shop._id.toString();\n\n\t\tif (couponShopId === currentShopId) return null;\n\n\t\tconst validShop = await this.shopModel\n\t\t\t.findOne({ _id: coupon.shop, deletedAt: null })\n\t\t\t.select('name')\n\t\t\t.lean();\n\n\t\tif (!validShop) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: 'Coupon is associated with an invalid shop',\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tisValid: false,\n\t\t\tmessage: `This coupon can be used at ${validShop.name} only`,\n\t\t};\n\t}\n\n\tprivate validateMultiRestrictions(shop: any, coupon: any) {\n\t\tconst hasShopRestriction = Array.isArray(coupon.shops) && coupon.shops.length > 0;\n\t\tconst hasItemTypeRestriction = Array.isArray(coupon.itemTypes) && coupon.itemTypes.length > 0;\n\n\t\tif (!hasShopRestriction && !hasItemTypeRestriction) return null;\n\n\t\tconst shopMatches =\n\t\t\thasShopRestriction &&\n\t\t\tcoupon.shops.some((couponShop: any) => couponShop._id.toString() === shop._id.toString());\n\n\t\tconst itemTypeMatches = hasItemTypeRestriction && coupon.itemTypes.includes(shop.itemType);\n\n\t\tif (!shopMatches && !itemTypeMatches) {\n\t\t\tconst shopNames = coupon.shops.map((shop: any) => shop.name).join(', ');\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: `This coupon can be used at ${shopNames}`,\n\t\t\t};\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate async validateSingleVendorRestriction(vendor: any, coupon: any) {\n\t\tif (!coupon.vendor) return null;\n\n\t\tconst couponVendorId = coupon.vendor.toString();\n\t\tconst currentVendorId = vendor._id.toString();\n\n\t\tif (couponVendorId === currentVendorId) return null;\n\n\t\tconst validVendor = await this.vendorModel.findOne({ _id: coupon.vendor }).select('name').lean();\n\n\t\tif (!validVendor) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: 'Coupon is associated with an invalid vendor',\n\t\t\t};\n\t\t}\n\n\t\treturn {\n\t\t\tisValid: false,\n\t\t\tmessage: `This coupon can be used at ${validVendor.name} only`,\n\t\t};\n\t}\n\n\tprivate validateVendorMultiRestrictions(vendor: any, coupon: any) {\n\t\tconst hasVendorRestriction = Array.isArray(coupon.vendors) && coupon.vendors.length > 0;\n\t\tconst hasItemTypeRestriction = Array.isArray(coupon.itemTypes) && coupon.itemTypes.length > 0;\n\n\t\tif (!hasVendorRestriction && !hasItemTypeRestriction) return null;\n\n\t\tconst vendorMatches =\n\t\t\thasVendorRestriction &&\n\t\t\tcoupon.vendors.some((couponVendor: any) => couponVendor._id.toString() === vendor._id.toString());\n\n\t\tconst itemTypeMatches = hasItemTypeRestriction && coupon.itemTypes.includes(vendor.serviceType);\n\n\t\tif (!vendorMatches && !itemTypeMatches) {\n\t\t\tconst vendorNames = coupon.vendors.map((vendor: any) => vendor.name).join(', ');\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: `This coupon can be used at ${vendorNames}`,\n\t\t\t};\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate async validateFirstOrderOnly(data: ValidateCouponDTO, shop: any, coupon: any) {\n\t\tif (!coupon.firstOrderOnly) return null;\n\n\t\tconst existingOrder = await this.orderModel.exists({\n\t\t\tuser: new mongoose.Types.ObjectId(data.user),\n\t\t\tshop: shop._id,\n\t\t\tstatus: { $ne: RegularOrderStatus.CANCELLED },\n\t\t});\n\n\t\tif (existingOrder) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: 'This coupon is only valid for the first order in the shop',\n\t\t\t};\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate async validateVendorFirstOrderOnly(data: ValidateCouponDTO, vendor: any, coupon: any) {\n\t\tif (!coupon.firstOrderOnly) return null;\n\n\t\tconst existingBooking = await this.serviceBookingModel.exists({\n\t\t\tuser: new mongoose.Types.ObjectId(data.user),\n\t\t\tvendor: vendor._id,\n\t\t\tstatus: { $ne: ServiceBookingStatus.CANCELLED },\n\t\t});\n\n\t\tif (existingBooking) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: 'This coupon is only valid for the first order in the vendor',\n\t\t\t};\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tpublic async fetchUserName(userId: mongoose.Types.ObjectId): Promise<string> {\n\t\tconst user = await this.userModel.findById(userId).select('coreUser').lean();\n\n\t\tif (!user) return 'Unknown User';\n\n\t\tconst coreUser = await this.coreUserModel.findById(user.coreUser).select('name').lean();\n\n\t\treturn coreUser ? coreUser.name : 'Unknown User';\n\t}\n}\n\nexport const couponHelperService = Container.get(CouponHelperService);\n"]}
|
|
@@ -24,6 +24,7 @@ export declare class IndividualStoreCouponService {
|
|
|
24
24
|
secondaryVendorCut?: number | undefined;
|
|
25
25
|
} | undefined;
|
|
26
26
|
couponDetails?: Record<string, unknown> | undefined;
|
|
27
|
+
couponInfo?: Record<string, unknown> | undefined;
|
|
27
28
|
} | {
|
|
28
29
|
isValid: boolean;
|
|
29
30
|
message: string;
|
|
@@ -232,6 +233,7 @@ export declare class IndividualStoreCouponService {
|
|
|
232
233
|
} | undefined;
|
|
233
234
|
isMenuDietaryFilterEnabled?: boolean | undefined;
|
|
234
235
|
categoryNumberingEnabled?: boolean | undefined;
|
|
236
|
+
hideOutOfStockProducts?: boolean | undefined;
|
|
235
237
|
createdAt?: Date | undefined;
|
|
236
238
|
updatedAt?: Date | undefined;
|
|
237
239
|
}> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"individual-store-coupon.service.d.ts","sourceRoot":"/","sources":["modules/coupon/services/individual-store-coupon.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,qBAAqB,IAAI,KAAK,EAI9B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,8BAA8B,IAAI,SAAS,EAC3C,8BAA8B,IAAI,SAAS,EAC3C,iBAAiB,EACjB,MAAM,6BAA6B,CAAC;AAIrC,qBACa,4BAA4B;IACxC,OAAO,CAAC,KAAK,CAAC;IACd,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAmB;IACtD,OAAO,CA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqBhF;AAED,eAAO,MAAM,4BAA4B,8BAA8C,CAAC"}
|
|
@@ -79,12 +79,12 @@ let IndividualStoreCouponService = class IndividualStoreCouponService {
|
|
|
79
79
|
async validateCoupon(data, coupon) {
|
|
80
80
|
const validation = await helper_service_1.couponHelperService.validateShopEligibility({
|
|
81
81
|
data,
|
|
82
|
-
coupon
|
|
82
|
+
coupon,
|
|
83
83
|
});
|
|
84
84
|
if (!validation.isValid)
|
|
85
85
|
return validation;
|
|
86
86
|
const { discountAmount, secondaryDiscountAmount } = await helper_service_1.couponHelperService.calculateCouponDiscount(data, coupon);
|
|
87
|
-
return helper_service_1.couponHelperService.buildCouponResponse(data, discountAmount, secondaryDiscountAmount, coupon.isShopCoverExpenses ?? false);
|
|
87
|
+
return helper_service_1.couponHelperService.buildCouponResponse(coupon, data, discountAmount, secondaryDiscountAmount, coupon.isShopCoverExpenses ?? false);
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
exports.IndividualStoreCouponService = IndividualStoreCouponService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"individual-store-coupon.service.js","sourceRoot":"/","sources":["modules/coupon/services/individual-store-coupon.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AAEzC,uEAMoD;AAOpD,qDAAuD;AAGhD,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAChC,KAAK,CAAC;IACG,kBAAkB,CAAmB;IAC9C,UAAU,CAA2D;IAE7E;QACC,IAAI,CAAC,KAAK,GAAG,mCAA0B,CAAC;QACxC,IAAI,CAAC,kBAAkB,GAAG,kBAA6B,CAAC;QACxD,IAAI,CAAC,UAAU,GAAG,0BAA6E,CAAC;IACjG,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEvC,OAAO,MAAM,CAAC;IACf,CAAC;IAOM,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,IAAe;QAC9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAC/C;YACC,GAAG,EAAE,EAAE;YACP,SAAS,EAAE,IAAI;SACf,EACD,IAAI,EACJ;YACC,GAAG,EAAE,IAAI;YACT,aAAa,EAAE,IAAI;SACnB,CACD,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,kBAAkB;aAC3B,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,IAAuB,EAAE,MAA2B;QAC/E,MAAM,UAAU,GAAG,MAAM,oCAAmB,CAAC,uBAAuB,CAAC;YACpE,IAAI;YACJ,MAAM;SACN,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,CAAC,OAAO;YAAE,OAAO,UAAU,CAAC;QAE3C,MAAM,EAAE,cAAc,EAAE,uBAAuB,EAAE,GAAG,MAAM,oCAAmB,CAAC,uBAAuB,
|
|
1
|
+
{"version":3,"file":"individual-store-coupon.service.js","sourceRoot":"/","sources":["modules/coupon/services/individual-store-coupon.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AAEzC,uEAMoD;AAOpD,qDAAuD;AAGhD,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAChC,KAAK,CAAC;IACG,kBAAkB,CAAmB;IAC9C,UAAU,CAA2D;IAE7E;QACC,IAAI,CAAC,KAAK,GAAG,mCAA0B,CAAC;QACxC,I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4B,CAsExC;AAEY,QAAA,4BAA4B,GAAG,gBAAS,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tIndividualStoreCouponModel,\n\tIndividualStoreCoupon as Model,\n\tRegularOrder,\n\tRegularOrderModel,\n\tShopModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateIndividualStoreCouponDTO as CreateDTO,\n\tUpdateIndividualStoreCouponDTO as UpdateDTO,\n\tValidateCouponDTO,\n} from '@modules/coupon/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { couponHelperService } from './helper.service';\n\n@Service()\nexport class IndividualStoreCouponService {\n\tprivate model;\n\tprivate readonly shopModelForCoupon: typeof ShopModel;\n\tprivate orderModel: typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\n\tconstructor() {\n\t\tthis.model = IndividualStoreCouponModel;\n\t\tthis.shopModelForCoupon = ShopModel as typeof ShopModel;\n\t\tthis.orderModel = RegularOrderModel as typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst coupon = this.model.create(data);\n\n\t\treturn coupon;\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(id: string, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\tdata,\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Record not found`,\n\t\t\t});\n\t\t}\n\n\t\treturn record;\n\t}\n\n\tpublic async validateCoupon(data: ValidateCouponDTO, coupon: DocumentType<Model>) {\n\t\tconst validation = await couponHelperService.validateShopEligibility({\n\t\t\tdata,\n\t\t\tcoupon,\n\t\t});\n\n\t\tif (!validation.isValid) return validation;\n\n\t\tconst { discountAmount, secondaryDiscountAmount } = await couponHelperService.calculateCouponDiscount(\n\t\t\tdata,\n\t\t\tcoupon\n\t\t);\n\n\t\treturn couponHelperService.buildCouponResponse(\n\t\t\tcoupon,\n\t\t\tdata,\n\t\t\tdiscountAmount,\n\t\t\tsecondaryDiscountAmount,\n\t\t\tcoupon.isShopCoverExpenses ?? false\n\t\t);\n\t}\n}\n\nexport const individualStoreCouponService = Container.get(IndividualStoreCouponService);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"individual-user-coupon.service.d.ts","sourceRoot":"/","sources":["modules/coupon/services/individual-user-coupon.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAY,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,oBAAoB,IAAI,KAAK,EAC7B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,yBAAyB,EACzB,6BAA6B,IAAI,SAAS,EAC1C,6BAA6B,IAAI,SAAS,EAC1C,iBAAiB,EACjB,MAAM,6BAA6B,CAAC;AAMrC,qBACa,2BAA2B;IACvC,OAAO,CAAC,KAAK,CAAC;;IAUD,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAWrD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA2BjE,cAAc,CAC1B,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,GACzB,OAAO,CAAC,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"individual-user-coupon.service.d.ts","sourceRoot":"/","sources":["modules/coupon/services/individual-user-coupon.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAY,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,oBAAoB,IAAI,KAAK,EAC7B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,yBAAyB,EACzB,6BAA6B,IAAI,SAAS,EAC1C,6BAA6B,IAAI,SAAS,EAC1C,iBAAiB,EACjB,MAAM,6BAA6B,CAAC;AAMrC,qBACa,2BAA2B;IACvC,OAAO,CAAC,KAAK,CAAC;;IAUD,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAWrD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA2BjE,cAAc,CAC1B,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,YAAY,CAAC,KAAK,CAAC,GACzB,OAAO,CAAC,yBAAyB,CAAC;CAgErC;AAED,eAAO,MAAM,2BAA2B,6BAA6C,CAAC"}
|
|
@@ -120,6 +120,12 @@ let IndividualUserCouponService = class IndividualUserCouponService {
|
|
|
120
120
|
vendorCut: 0,
|
|
121
121
|
secondaryVendorCut: 0,
|
|
122
122
|
},
|
|
123
|
+
couponInfo: {
|
|
124
|
+
_id: coupon._id,
|
|
125
|
+
couponType: coupon.couponType,
|
|
126
|
+
valueType: coupon.valueType,
|
|
127
|
+
value: coupon.value,
|
|
128
|
+
},
|
|
123
129
|
};
|
|
124
130
|
}
|
|
125
131
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"individual-user-coupon.service.js","sourceRoot":"/","sources":["modules/coupon/services/individual-user-coupon.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;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,uBAAuB;YACvB,iBAAiB,EAAE,IAAA,0BAAiB,EAAC,IAAI,CAAC,kBAAkB,GAAG,cAAc,CAAC;YAC9E,0BAA0B,EAAE,IAAA,+BAAsB,EACjD,IAAI,CAAC,2BAA2B,GAAG,uBAAuB,CAC1D;YACD,WAAW,EAAE;gBACZ,UAAU,EAAE,cAAc;gBAC1B,mBAAmB,EAAE,uBAAuB;gBAC5C,OAAO,EAAE,CAAC;gBACV,gBAAgB,EAAE,CAAC;gBACnB,SAAS,EAAE,CAAC;gBACZ,kBAAkB,EAAE,CAAC;aACrB;SACD,CAAC;IACH,CAAC;CACD,CAAA;
|
|
1
|
+
{"version":3,"file":"individual-user-coupon.service.js","sourceRoot":"/","sources":["modules/coupon/services/individual-user-coupon.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA8D;AAC9D,uEAGoD;AAOpD,oEAA2E;AAC3E,gEAAgG;AAChG,4DAA8D;AAC9D,qDAAuD;AAGhD,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAC/B,KAAK,CAAC;IAEd;QACC,IAAI,CAAC,KAAK,GAAG,kCAAyB,CAAC;IACxC,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEvC,OAAO,MAAM,CAAC;IACf,CAAC;IAOM,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,IAAe;QAK9C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAC/C;YACC,GAAG,EAAE,EAAE;YACP,SAAS,EAAE,IAAI;SACf,EACD,IAAI,EACJ;YACC,GAAG,EAAE,IAAI;YACT,aAAa,EAAE,IAAI;SACnB,CACD,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MA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esContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tIndividualUserCouponModel,\n\tIndividualUserCoupon as Model,\n} from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCouponValidationOutputDTO,\n\tCreateIndividualUserCouponDTO as CreateDTO,\n\tUpdateIndividualUserCouponDTO as UpdateDTO,\n\tValidateCouponDTO,\n} from '@modules/coupon/validations';\nimport { convertToSecondary } from '@lyxa.ai/core/dist/utilities/currency';\nimport { roundBaseCurrency, roundSecondaryCurrency } from '@lyxa.ai/core/dist/utilities/shared';\nimport { ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { couponHelperService } from './helper.service';\n\n@Service()\nexport class IndividualUserCouponService {\n\tprivate model;\n\n\tconstructor() {\n\t\tthis.model = IndividualUserCouponModel;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst coupon = this.model.create(data);\n\n\t\treturn coupon;\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(id: string, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\t// TODO: Update users for this coupon\n\t\t// Remove coupon ID from users not in data.users\n\t\t// Add coupon ID to users in data.users\n\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\tdata,\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Record not found`,\n\t\t\t});\n\t\t}\n\n\t\treturn record;\n\t}\n\n\tpublic async validateCoupon(\n\t\tdata: ValidateCouponDTO,\n\t\tcoupon: DocumentType<Model>\n\t): Promise<CouponValidationOutputDTO> {\n\t\tconst userId = new mongoose.Types.ObjectId(data.user);\n\t\tif (!coupon.users.some(u => u.toString() == userId.toString())) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t\tmessage: 'This coupon is for specific users only',\n\t\t\t};\n\t\t}\n\n\t\tconst shopValidation = await couponHelperService.validateShopEligibility({\n\t\t\tdata,\n\t\t\tcoupon,\n\t\t});\n\t\tif (!shopValidation.isValid) return shopValidation;\n\n\t\tlet discountAmount =\n\t\t\tcoupon.valueType == ValueType.FIXED\n\t\t\t\t? coupon.value\n\t\t\t\t: roundBaseCurrency((data.amountBeforeCoupon * coupon.value) / 100);\n\n\t\tlet secondaryDiscountAmount =\n\t\t\tcoupon.valueType == ValueType.FIXED\n\t\t\t\t? await convertToSecondary(coupon.value)\n\t\t\t\t: roundSecondaryCurrency((data.secondaryAmountBeforeCoupon * coupon.value) / 100);\n\n\t\tif (coupon.isMaxDiscountLimitEnabled && coupon.maxDiscountLimit) {\n\t\t\tdiscountAmount = Math.min(discountAmount, coupon.maxDiscountLimit);\n\t\t\tsecondaryDiscountAmount = Math.min(\n\t\t\t\tsecondaryDiscountAmount,\n\t\t\t\tawait convertToSecondary(coupon.maxDiscountLimit)\n\t\t\t);\n\t\t}\n\n\t\tif (discountAmount > data.amountBeforeCoupon) {\n\t\t\tdiscountAmount = data.amountBeforeCoupon;\n\t\t}\n\t\tif (secondaryDiscountAmount > data.secondaryAmountBeforeCoupon) {\n\t\t\tsecondaryDiscountAmount = data.secondaryAmountBeforeCoupon;\n\t\t}\n\n\t\treturn {\n\t\t\tisValid: true,\n\t\t\tdiscountAmount,\n\t\t\tsecondaryDiscountAmount,\n\t\t\tamountAfterCoupon: roundBaseCurrency(data.amountBeforeCoupon - discountAmount),\n\t\t\tsecondaryAmountAfterCoupon: roundSecondaryCurrency(\n\t\t\t\tdata.secondaryAmountBeforeCoupon - secondaryDiscountAmount\n\t\t\t),\n\t\t\tdiscountCut: {\n\t\t\t\tcompanyCut: discountAmount,\n\t\t\t\tsecondaryCompanyCut: secondaryDiscountAmount,\n\t\t\t\tshopCut: 0,\n\t\t\t\tsecondaryShopCut: 0,\n\t\t\t\tvendorCut: 0,\n\t\t\t\tsecondaryVendorCut: 0,\n\t\t\t},\n\t\t\tcouponInfo: {\n\t\t\t\t_id: coupon._id,\n\t\t\t\tcouponType: coupon.couponType,\n\t\t\t\tvalueType: coupon.valueType,\n\t\t\t\tvalue: coupon.value,\n\t\t\t},\n\t\t};\n\t}\n}\n\nexport const individualUserCouponService = Container.get(IndividualUserCouponService);\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ItemType, OrderType, RegularOrderStatus } from '@lyxa.ai/core/dist/utilities/enum';
|
|
2
|
-
import { CouponMetricsOutputDTO, DateInputDTO, GraphInputDTO } from '../../../../coupon/validations/coupon.validation';
|
|
2
|
+
import { CouponMetricsOutputDTO, DateInputDTO, GraphDTO, GraphInputDTO, TotalProfitGraphDTO } from '../../../../coupon/validations/coupon.validation';
|
|
3
3
|
export declare class CouponMetricsRepository {
|
|
4
4
|
private readonly model;
|
|
5
5
|
private orderModel;
|
|
@@ -10,6 +10,9 @@ export declare class CouponMetricsRepository {
|
|
|
10
10
|
private getActiveCouponsCount;
|
|
11
11
|
private getTotalCreatedCoupons;
|
|
12
12
|
private getCouponUsageMetrics;
|
|
13
|
+
private getEffectiveGraphType;
|
|
14
|
+
private getPeriodKeys;
|
|
15
|
+
private formatPeriodLabel;
|
|
13
16
|
getCouponMetricsByType(duration: DateInputDTO): Promise<any[]>;
|
|
14
17
|
private getCouponTypeTitle;
|
|
15
18
|
private fillMissingRows;
|
|
@@ -25,8 +28,11 @@ export declare class CouponMetricsRepository {
|
|
|
25
28
|
orderType: OrderType;
|
|
26
29
|
status: RegularOrderStatus;
|
|
27
30
|
};
|
|
28
|
-
getCouponOrdersGraphData(data: GraphInputDTO): Promise<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
getCouponOrdersGraphData(data: GraphInputDTO): Promise<GraphDTO>;
|
|
32
|
+
private convertToCouponOrdersGraphFormat;
|
|
33
|
+
getUsersNewVsReturningGraphData(data: GraphInputDTO): Promise<GraphDTO>;
|
|
34
|
+
private convertToUsersNewVsReturningGraphFormat;
|
|
35
|
+
getCouponProfitGraphData(data: GraphInputDTO): Promise<TotalProfitGraphDTO>;
|
|
36
|
+
private convertToCouponProfitGraphFormat;
|
|
31
37
|
}
|
|
32
38
|
//# sourceMappingURL=CouponMetricsRepository.d.ts.map
|
package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CouponMetricsRepository.d.ts","sourceRoot":"/","sources":["modules/coupon/services/patterns/repository/CouponMetricsRepository.ts"],"names":[],"mappings":"AAGA,OAAO,EAGN,QAAQ,EACR,SAAS,EACT,kBAAkB,EAElB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAEN,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,MAAM,+CAA+C,CAAC;AAIvD,qBAAa,uBAAuB;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,UAAU,CAAoB;;IAOtC,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,qCAAqC;IAa7C,OAAO,CAAC,mBAAmB;YAWb,qBAAqB;YASrB,sBAAsB;YAQtB,qBAAqB;IA+
|
|
1
|
+
{"version":3,"file":"CouponMetricsRepository.d.ts","sourceRoot":"/","sources":["modules/coupon/services/patterns/repository/CouponMetricsRepository.ts"],"names":[],"mappings":"AAGA,OAAO,EAGN,QAAQ,EACR,SAAS,EACT,kBAAkB,EAElB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EAEN,sBAAsB,EACtB,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,mBAAmB,EACnB,MAAM,+CAA+C,CAAC;AAIvD,qBAAa,uBAAuB;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,UAAU,CAAoB;;IAOtC,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,qCAAqC;IAa7C,OAAO,CAAC,mBAAmB;YAWb,qBAAqB;YASrB,sBAAsB;YAQtB,qBAAqB;IA+DnC,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,aAAa;IAerB,OAAO,CAAC,iBAAiB;IAQZ,sBAAsB,CAAC,QAAQ,EAAE,YAAY;IAwI1D,OAAO,CAAC,kBAAkB;IAa1B,OAAO,CAAC,eAAe;IAwBvB,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,uBAAuB;IAQlB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAgC/E,uBAAuB,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,QAAQ;;;;;;;;;IAgBrE,wBAAwB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC;IAkE7E,OAAO,CAAC,gCAAgC;IA0B3B,+BAA+B,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC;IA4HpF,OAAO,CAAC,uCAAuC;IA0BlC,wBAAwB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA0DxF,OAAO,CAAC,gCAAgC;CAsBxC"}
|
|
@@ -98,6 +98,31 @@ class CouponMetricsRepository {
|
|
|
98
98
|
redeemedCoupons: 0,
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
+
getEffectiveGraphType(type, startDate, endDate) {
|
|
102
|
+
if (type !== undefined && type !== null) {
|
|
103
|
+
return type;
|
|
104
|
+
}
|
|
105
|
+
const durationDays = (0, dayjs_1.dayjs)(endDate).endOf('day').diff((0, dayjs_1.dayjs)(startDate).startOf('day'), 'day') + 1;
|
|
106
|
+
return durationDays > 31 ? enum_1.GraphType.MONTHLY : enum_1.GraphType.DAILY;
|
|
107
|
+
}
|
|
108
|
+
getPeriodKeys(startDate, endDate, type) {
|
|
109
|
+
const unit = type === enum_1.GraphType.MONTHLY ? 'month' : 'day';
|
|
110
|
+
const format = type === enum_1.GraphType.MONTHLY ? 'YYYY-MM' : 'YYYY-MM-DD';
|
|
111
|
+
const keys = [];
|
|
112
|
+
let current = (0, dayjs_1.dayjs)(startDate).startOf(unit);
|
|
113
|
+
const end = (0, dayjs_1.dayjs)(endDate).startOf(unit);
|
|
114
|
+
while (current.isBefore(end) || current.isSame(end)) {
|
|
115
|
+
keys.push(current.format(format));
|
|
116
|
+
current = current.add(1, unit);
|
|
117
|
+
}
|
|
118
|
+
return keys;
|
|
119
|
+
}
|
|
120
|
+
formatPeriodLabel(dateKey, type) {
|
|
121
|
+
if (type === enum_1.GraphType.MONTHLY) {
|
|
122
|
+
return new Date(dateKey).toLocaleString('default', { month: 'short' });
|
|
123
|
+
}
|
|
124
|
+
return new Date(dateKey).toLocaleString('default', { day: 'numeric', month: 'short' });
|
|
125
|
+
}
|
|
101
126
|
async getCouponMetricsByType(duration) {
|
|
102
127
|
const startDate = (0, dayjs_1.dayjs)(duration.startDate).startOf('day').toDate();
|
|
103
128
|
const endDate = (0, dayjs_1.dayjs)(duration.endDate).endOf('day').toDate();
|
|
@@ -298,7 +323,8 @@ class CouponMetricsRepository {
|
|
|
298
323
|
async getCouponOrdersGraphData(data) {
|
|
299
324
|
const startDate = (0, dayjs_1.dayjs)(data.startDate).startOf('day').toDate();
|
|
300
325
|
const endDate = (0, dayjs_1.dayjs)(data.endDate).endOf('day').toDate();
|
|
301
|
-
const
|
|
326
|
+
const graphType = this.getEffectiveGraphType(data.graphType, data.startDate, data.endDate);
|
|
327
|
+
const dateFormat = graphType === enum_1.GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';
|
|
302
328
|
const result = await this.orderModel.aggregate([
|
|
303
329
|
{
|
|
304
330
|
$match: {
|
|
@@ -341,17 +367,36 @@ class CouponMetricsRepository {
|
|
|
341
367
|
$sort: { date: 1 },
|
|
342
368
|
},
|
|
343
369
|
]);
|
|
344
|
-
const graphData = (0, utils_1.fillMissingPeriods)(result, data.startDate, data.endDate,
|
|
370
|
+
const graphData = (0, utils_1.fillMissingPeriods)(result, data.startDate, data.endDate, graphType, {
|
|
345
371
|
totalOrders: 0,
|
|
346
372
|
ordersWithCoupon: 0,
|
|
347
373
|
ordersWithoutCoupon: 0,
|
|
348
374
|
});
|
|
349
|
-
return graphData;
|
|
375
|
+
return this.convertToCouponOrdersGraphFormat(graphData, graphType, data.startDate, data.endDate);
|
|
376
|
+
}
|
|
377
|
+
convertToCouponOrdersGraphFormat(data, graphType, startDate, endDate) {
|
|
378
|
+
const periodKeys = this.getPeriodKeys(startDate, endDate, graphType);
|
|
379
|
+
const categories = periodKeys.map(key => this.formatPeriodLabel(key, graphType));
|
|
380
|
+
const series = [
|
|
381
|
+
{
|
|
382
|
+
name: 'Coupon',
|
|
383
|
+
data: data.map(item => item.ordersWithCoupon),
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
name: 'No Coupon',
|
|
387
|
+
data: data.map(item => item.ordersWithoutCoupon),
|
|
388
|
+
},
|
|
389
|
+
];
|
|
390
|
+
return {
|
|
391
|
+
categories,
|
|
392
|
+
series,
|
|
393
|
+
};
|
|
350
394
|
}
|
|
351
395
|
async getUsersNewVsReturningGraphData(data) {
|
|
352
396
|
const startDate = (0, dayjs_1.dayjs)(data.startDate).startOf('day').toDate();
|
|
353
397
|
const endDate = (0, dayjs_1.dayjs)(data.endDate).endOf('day').toDate();
|
|
354
|
-
const
|
|
398
|
+
const graphType = this.getEffectiveGraphType(data.graphType, data.startDate, data.endDate);
|
|
399
|
+
const dateFormat = graphType === enum_1.GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';
|
|
355
400
|
const result = await this.orderModel.aggregate([
|
|
356
401
|
{
|
|
357
402
|
$match: {
|
|
@@ -443,17 +488,36 @@ class CouponMetricsRepository {
|
|
|
443
488
|
},
|
|
444
489
|
{ $sort: { date: 1 } },
|
|
445
490
|
]);
|
|
446
|
-
const graphData = (0, utils_1.fillMissingPeriods)(result, data.startDate, data.endDate,
|
|
491
|
+
const graphData = (0, utils_1.fillMissingPeriods)(result, data.startDate, data.endDate, graphType, {
|
|
447
492
|
totalUsers: 0,
|
|
448
493
|
newUsers: 0,
|
|
449
494
|
returningUsers: 0,
|
|
450
495
|
});
|
|
451
|
-
return graphData;
|
|
496
|
+
return this.convertToUsersNewVsReturningGraphFormat(graphData, graphType, data.startDate, data.endDate);
|
|
497
|
+
}
|
|
498
|
+
convertToUsersNewVsReturningGraphFormat(data, graphType, startDate, endDate) {
|
|
499
|
+
const periodKeys = this.getPeriodKeys(startDate, endDate, graphType);
|
|
500
|
+
const categories = periodKeys.map(key => this.formatPeriodLabel(key, graphType));
|
|
501
|
+
const series = [
|
|
502
|
+
{
|
|
503
|
+
name: 'New Users',
|
|
504
|
+
data: data.map(item => item.newUsers),
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
name: 'Returning Users',
|
|
508
|
+
data: data.map(item => item.returningUsers),
|
|
509
|
+
},
|
|
510
|
+
];
|
|
511
|
+
return {
|
|
512
|
+
categories,
|
|
513
|
+
series,
|
|
514
|
+
};
|
|
452
515
|
}
|
|
453
516
|
async getCouponProfitGraphData(data) {
|
|
454
517
|
const startDate = (0, dayjs_1.dayjs)(data.startDate).startOf('day').toDate();
|
|
455
518
|
const endDate = (0, dayjs_1.dayjs)(data.endDate).endOf('day').toDate();
|
|
456
|
-
const
|
|
519
|
+
const graphType = this.getEffectiveGraphType(data.graphType, data.startDate, data.endDate);
|
|
520
|
+
const dateFormat = graphType === enum_1.GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';
|
|
457
521
|
const result = await this.orderModel.aggregate([
|
|
458
522
|
{
|
|
459
523
|
$match: {
|
|
@@ -491,10 +555,25 @@ class CouponMetricsRepository {
|
|
|
491
555
|
$sort: { date: 1 },
|
|
492
556
|
},
|
|
493
557
|
]);
|
|
494
|
-
const graphData = (0, utils_1.fillMissingPeriods)(result, data.startDate, data.endDate,
|
|
558
|
+
const graphData = (0, utils_1.fillMissingPeriods)(result, data.startDate, data.endDate, graphType, {
|
|
495
559
|
totalProfit: 0,
|
|
496
560
|
});
|
|
497
|
-
return graphData;
|
|
561
|
+
return this.convertToCouponProfitGraphFormat(graphData, graphType, data.startDate, data.endDate);
|
|
562
|
+
}
|
|
563
|
+
convertToCouponProfitGraphFormat(data, graphType, startDate, endDate) {
|
|
564
|
+
const periodKeys = this.getPeriodKeys(startDate, endDate, graphType);
|
|
565
|
+
const categories = periodKeys.map(key => this.formatPeriodLabel(key, graphType));
|
|
566
|
+
const series = [
|
|
567
|
+
{
|
|
568
|
+
name: 'Profit',
|
|
569
|
+
data: data.map(item => item.totalProfit),
|
|
570
|
+
},
|
|
571
|
+
];
|
|
572
|
+
return {
|
|
573
|
+
categories,
|
|
574
|
+
series,
|
|
575
|
+
totalProfit: data.reduce((sum, item) => sum + item.totalProfit, 0),
|
|
576
|
+
};
|
|
498
577
|
}
|
|
499
578
|
}
|
|
500
579
|
exports.CouponMetricsRepository = CouponMetricsRepository;
|