@lyxa.ai/marketing 1.0.67 → 1.0.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/dist/lib/index.d.ts +21 -11810
  2. package/dist/lib/index.d.ts.map +1 -1
  3. package/dist/lib/index.js +3 -1
  4. package/dist/lib/index.js.map +1 -1
  5. package/dist/lib/modules/coupon/routers/coupon.router.d.ts +1415 -7085
  6. package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
  7. package/dist/lib/modules/coupon/routers/coupon.router.js +37 -22
  8. package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
  9. package/dist/lib/modules/coupon/services/coupon.service.d.ts +41 -6
  10. package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
  11. package/dist/lib/modules/coupon/services/coupon.service.js +290 -93
  12. package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
  13. package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -1
  14. package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js +11 -15
  15. package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js.map +1 -1
  16. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts +30 -2
  17. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
  18. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +494 -54
  19. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
  20. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
  21. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js +1 -0
  22. package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
  23. package/dist/lib/modules/coupon/transformers/coupon.transformer.d.ts +54 -2
  24. package/dist/lib/modules/coupon/transformers/coupon.transformer.d.ts.map +1 -1
  25. package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts +364 -3193
  26. package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
  27. package/dist/lib/modules/coupon/validations/all-coupons.validation.js +1 -2
  28. package/dist/lib/modules/coupon/validations/all-coupons.validation.js.map +1 -1
  29. package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +580 -1
  30. package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
  31. package/dist/lib/modules/coupon/validations/coupon.validation.js +48 -1
  32. package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
  33. package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts +116 -8
  34. package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
  35. package/dist/lib/modules/coupon/validations/create-coupon.validation.js +4 -1
  36. package/dist/lib/modules/coupon/validations/create-coupon.validation.js.map +1 -1
  37. package/dist/lib/modules/coupon/validations/global-coupon.validation.d.ts +18 -0
  38. package/dist/lib/modules/coupon/validations/global-coupon.validation.d.ts.map +1 -1
  39. package/dist/lib/modules/coupon/validations/global-coupon.validation.js +2 -0
  40. package/dist/lib/modules/coupon/validations/global-coupon.validation.js.map +1 -1
  41. package/dist/lib/modules/coupon/validations/individual-store-coupon.validation.d.ts +18 -18
  42. package/dist/lib/modules/coupon/validations/individual-store-coupon.validation.js +2 -2
  43. package/dist/lib/modules/coupon/validations/individual-store-coupon.validation.js.map +1 -1
  44. package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.d.ts +374 -0
  45. package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.d.ts.map +1 -1
  46. package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.js +2 -0
  47. package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.js.map +1 -1
  48. package/dist/lib/modules/deal-setting/routers/deal-setting.router.d.ts +5 -5
  49. package/dist/lib/modules/deal-setting/routers/deal-setting.router.d.ts.map +1 -1
  50. package/dist/lib/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
  51. package/dist/lib/modules/deal-setting/services/deal-setting.service.js +4 -1
  52. package/dist/lib/modules/deal-setting/services/deal-setting.service.js.map +1 -1
  53. package/dist/lib/modules/featured-setting/routers/featured-setting.router.d.ts +5 -5
  54. package/dist/lib/modules/featured-setting/routers/featured-setting.router.d.ts.map +1 -1
  55. package/dist/lib/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
  56. package/dist/lib/modules/featured-setting/services/featured-setting.service.js +3 -0
  57. package/dist/lib/modules/featured-setting/services/featured-setting.service.js.map +1 -1
  58. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts +54 -8
  59. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
  60. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js +13 -0
  61. package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js.map +1 -1
  62. package/dist/lib/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
  63. package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js +9 -0
  64. package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js.map +1 -1
  65. package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +0 -1
  66. package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
  67. package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js +2 -6
  68. package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js.map +1 -1
  69. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +16 -3
  70. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
  71. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js +22 -3
  72. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js.map +1 -1
  73. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +2 -0
  74. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
  75. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js +12 -0
  76. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js.map +1 -1
  77. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +242 -35
  78. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
  79. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js +19 -1
  80. package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js.map +1 -1
  81. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +10 -1
  82. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
  83. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js +83 -1
  84. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js.map +1 -1
  85. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +4 -0
  86. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
  87. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js +75 -6
  88. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js.map +1 -1
  89. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
  90. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
  91. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js +46 -19
  92. package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js.map +1 -1
  93. package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +241 -10
  94. package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
  95. package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts +2 -0
  96. package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
  97. package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js +13 -4
  98. package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js.map +1 -1
  99. package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
  100. package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js +1 -1
  101. package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js.map +1 -1
  102. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +30 -3
  103. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
  104. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js +23 -1
  105. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js.map +1 -1
  106. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +18 -0
  107. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
  108. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js +103 -0
  109. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js.map +1 -1
  110. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +187 -2
  111. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
  112. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js +34 -0
  113. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js.map +1 -1
  114. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts +1 -0
  115. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts.map +1 -0
  116. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js +2 -0
  117. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js.map +1 -0
  118. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +515 -116
  119. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
  120. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js +16 -6
  121. package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js.map +1 -1
  122. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +12 -4
  123. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
  124. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js +53 -7
  125. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js.map +1 -1
  126. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +19 -5
  127. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
  128. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js +114 -16
  129. package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js.map +1 -1
  130. package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -1
  131. package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js +1 -0
  132. package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js.map +1 -1
  133. package/dist/lib/modules/marketing/routers/marketing.router.d.ts +5 -5
  134. package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  135. package/dist/lib/modules/marketing/services/index.d.ts +1 -0
  136. package/dist/lib/modules/marketing/services/index.d.ts.map +1 -1
  137. package/dist/lib/modules/marketing/services/index.js +1 -0
  138. package/dist/lib/modules/marketing/services/index.js.map +1 -1
  139. package/dist/lib/modules/marketing/services/marketing.service.d.ts +7 -3
  140. package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
  141. package/dist/lib/modules/marketing/services/marketing.service.js +87 -19
  142. package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
  143. package/dist/lib/modules/marketing/services/new-user-discount-marketing.service.d.ts +11 -0
  144. package/dist/lib/modules/marketing/services/new-user-discount-marketing.service.d.ts.map +1 -0
  145. package/dist/lib/modules/marketing/services/new-user-discount-marketing.service.js +116 -0
  146. package/dist/lib/modules/marketing/services/new-user-discount-marketing.service.js.map +1 -0
  147. package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +1 -0
  148. package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
  149. package/dist/lib/modules/marketing/services/product-marketing.service.js +32 -0
  150. package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
  151. package/dist/lib/modules/marketing/validations/all-marketings.validation.d.ts.map +1 -1
  152. package/dist/lib/modules/marketing/validations/all-marketings.validation.js +3 -0
  153. package/dist/lib/modules/marketing/validations/all-marketings.validation.js.map +1 -1
  154. package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts +6 -6
  155. package/dist/lib/modules/marketing/validations/index.d.ts +1 -0
  156. package/dist/lib/modules/marketing/validations/index.d.ts.map +1 -1
  157. package/dist/lib/modules/marketing/validations/index.js +1 -0
  158. package/dist/lib/modules/marketing/validations/index.js.map +1 -1
  159. package/dist/lib/modules/marketing/validations/new-user-discount-marketing.validation.d.ts +677 -0
  160. package/dist/lib/modules/marketing/validations/new-user-discount-marketing.validation.d.ts.map +1 -0
  161. package/dist/lib/modules/marketing/validations/new-user-discount-marketing.validation.js +83 -0
  162. package/dist/lib/modules/marketing/validations/new-user-discount-marketing.validation.js.map +1 -0
  163. package/dist/lib/modules/marketing/validations/punch-marketing.validation.d.ts +8 -8
  164. package/dist/lib/modules/marketing/validations/spend-to-get-marketing.validation.d.ts.map +1 -1
  165. package/dist/lib/modules/marketing/validations/spend-to-get-marketing.validation.js +30 -0
  166. package/dist/lib/modules/marketing/validations/spend-to-get-marketing.validation.js.map +1 -1
  167. package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +6 -6
  168. package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts.map +1 -1
  169. package/dist/lib/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +2 -2
  170. package/dist/lib/modules/referral-setting/validations/referral-setting.validation.d.ts.map +1 -1
  171. package/dist/lib/modules/referral-setting/validations/referral-setting.validation.js.map +1 -1
  172. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.d.ts +3 -2
  173. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.d.ts.map +1 -1
  174. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.js +11 -3
  175. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.js.map +1 -1
  176. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.router.d.ts +21 -5
  177. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.router.d.ts.map +1 -1
  178. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.d.ts +2 -2
  179. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.d.ts.map +1 -1
  180. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.js.map +1 -1
  181. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.d.ts +19 -0
  182. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.d.ts.map +1 -1
  183. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.js +1 -0
  184. package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.js.map +1 -1
  185. package/dist/types/index.d.ts +21 -11810
  186. package/dist/types/index.d.ts.map +1 -1
  187. package/dist/types/modules/coupon/routers/coupon.router.d.ts +1415 -7085
  188. package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
  189. package/dist/types/modules/coupon/services/coupon.service.d.ts +41 -6
  190. package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
  191. package/dist/types/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -1
  192. package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts +30 -2
  193. package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
  194. package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
  195. package/dist/types/modules/coupon/transformers/coupon.transformer.d.ts +54 -2
  196. package/dist/types/modules/coupon/transformers/coupon.transformer.d.ts.map +1 -1
  197. package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts +364 -3193
  198. package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
  199. package/dist/types/modules/coupon/validations/coupon.validation.d.ts +580 -1
  200. package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
  201. package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts +116 -8
  202. package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
  203. package/dist/types/modules/coupon/validations/global-coupon.validation.d.ts +18 -0
  204. package/dist/types/modules/coupon/validations/global-coupon.validation.d.ts.map +1 -1
  205. package/dist/types/modules/coupon/validations/individual-store-coupon.validation.d.ts +18 -18
  206. package/dist/types/modules/coupon/validations/referral-reward-coupon.validation.d.ts +374 -0
  207. package/dist/types/modules/coupon/validations/referral-reward-coupon.validation.d.ts.map +1 -1
  208. package/dist/types/modules/deal-setting/routers/deal-setting.router.d.ts +5 -5
  209. package/dist/types/modules/deal-setting/routers/deal-setting.router.d.ts.map +1 -1
  210. package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
  211. package/dist/types/modules/featured-setting/routers/featured-setting.router.d.ts +5 -5
  212. package/dist/types/modules/featured-setting/routers/featured-setting.router.d.ts.map +1 -1
  213. package/dist/types/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
  214. package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts +54 -8
  215. package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
  216. package/dist/types/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
  217. package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +0 -1
  218. package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
  219. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +16 -3
  220. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
  221. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +2 -0
  222. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
  223. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +242 -35
  224. package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
  225. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +10 -1
  226. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
  227. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +4 -0
  228. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
  229. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
  230. package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
  231. package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +241 -10
  232. package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
  233. package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts +2 -0
  234. package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
  235. package/dist/types/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
  236. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +30 -3
  237. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
  238. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +18 -0
  239. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
  240. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +187 -2
  241. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
  242. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts +1 -0
  243. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts.map +1 -0
  244. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +515 -116
  245. package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
  246. package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +12 -4
  247. package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
  248. package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +19 -5
  249. package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
  250. package/dist/types/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -1
  251. package/dist/types/modules/marketing/routers/marketing.router.d.ts +5 -5
  252. package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  253. package/dist/types/modules/marketing/services/index.d.ts +1 -0
  254. package/dist/types/modules/marketing/services/index.d.ts.map +1 -1
  255. package/dist/types/modules/marketing/services/marketing.service.d.ts +7 -3
  256. package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
  257. package/dist/types/modules/marketing/services/new-user-discount-marketing.service.d.ts +20 -0
  258. package/dist/types/modules/marketing/services/new-user-discount-marketing.service.d.ts.map +1 -0
  259. package/dist/types/modules/marketing/services/product-marketing.service.d.ts +6 -0
  260. package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
  261. package/dist/types/modules/marketing/validations/all-marketings.validation.d.ts.map +1 -1
  262. package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts +6 -6
  263. package/dist/types/modules/marketing/validations/index.d.ts +1 -0
  264. package/dist/types/modules/marketing/validations/index.d.ts.map +1 -1
  265. package/dist/types/modules/marketing/validations/new-user-discount-marketing.validation.d.ts +686 -0
  266. package/dist/types/modules/marketing/validations/new-user-discount-marketing.validation.d.ts.map +1 -0
  267. package/dist/types/modules/marketing/validations/punch-marketing.validation.d.ts +8 -8
  268. package/dist/types/modules/marketing/validations/spend-to-get-marketing.validation.d.ts.map +1 -1
  269. package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +6 -6
  270. package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts.map +1 -1
  271. package/dist/types/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +2 -2
  272. package/dist/types/modules/referral-setting/validations/referral-setting.validation.d.ts.map +1 -1
  273. package/dist/types/modules/spend-to-get-history/spend-to-get-history.repository.d.ts +3 -2
  274. package/dist/types/modules/spend-to-get-history/spend-to-get-history.repository.d.ts.map +1 -1
  275. package/dist/types/modules/spend-to-get-history/spend-to-get-history.router.d.ts +21 -5
  276. package/dist/types/modules/spend-to-get-history/spend-to-get-history.router.d.ts.map +1 -1
  277. package/dist/types/modules/spend-to-get-history/spend-to-get-history.service.d.ts +2 -2
  278. package/dist/types/modules/spend-to-get-history/spend-to-get-history.service.d.ts.map +1 -1
  279. package/dist/types/modules/spend-to-get-history/spend-to-get-history.validation.d.ts +19 -0
  280. package/dist/types/modules/spend-to-get-history/spend-to-get-history.validation.d.ts.map +1 -1
  281. package/package.json +2 -6
@@ -10,6 +10,8 @@ const shared_1 = require("@lyxa.ai/core/dist/utilities/shared");
10
10
  const dayjs_1 = require("@lyxa.ai/core/dist/utilities/dayjs");
11
11
  const pagination_1 = require("@lyxa.ai/core/dist/utilities/pagination");
12
12
  const search_1 = require("@lyxa.ai/core/dist/utilities/search");
13
+ const time_1 = require("@lyxa.ai/core/dist/utilities/time");
14
+ const core_1 = require("@lyxa.ai/core");
13
15
  class CouponRepository {
14
16
  model;
15
17
  userModel;
@@ -44,12 +46,31 @@ class CouponRepository {
44
46
  {
45
47
  $match: { _id: user },
46
48
  },
49
+ {
50
+ $lookup: {
51
+ from: 'user-coupons',
52
+ let: { userId: '$_id' },
53
+ pipeline: [
54
+ {
55
+ $match: {
56
+ $expr: {
57
+ $eq: ['$user', '$$userId'],
58
+ },
59
+ },
60
+ },
61
+ ],
62
+ as: 'userCoupons',
63
+ },
64
+ },
65
+ {
66
+ $unwind: '$userCoupons',
67
+ },
47
68
  {
48
69
  $lookup: {
49
70
  from: 'coupons',
50
- localField: 'coupons',
71
+ localField: 'userCoupons.coupon',
51
72
  foreignField: '_id',
52
- as: 'couponDocs',
73
+ as: 'couponDetails',
53
74
  pipeline: [
54
75
  {
55
76
  $match: {
@@ -134,6 +155,15 @@ class CouponRepository {
134
155
  ],
135
156
  },
136
157
  },
158
+ { $unwind: '$couponDetails' },
159
+ {
160
+ $addFields: {
161
+ 'couponDetails.duration': {
162
+ start: '$userCoupons.startDate',
163
+ end: '$userCoupons.endDate',
164
+ },
165
+ },
166
+ },
137
167
  {
138
168
  $lookup: {
139
169
  from: 'orders',
@@ -232,7 +262,6 @@ class CouponRepository {
232
262
  },
233
263
  },
234
264
  },
235
- { $unwind: '$couponDocs' },
236
265
  ...(shop || vendor ? this.filterShopVendorCoupons(shop, vendor, itemType) : []),
237
266
  ...this.filterFirstOrderOnlyCoupons({ shop, vendor }),
238
267
  {
@@ -243,7 +272,7 @@ class CouponRepository {
243
272
  $filter: {
244
273
  input: '$couponUsage',
245
274
  as: 'cu',
246
- cond: { $eq: ['$$cu._id', '$couponDocs._id'] },
275
+ cond: { $eq: ['$$cu._id', '$couponDetails._id'] },
247
276
  },
248
277
  },
249
278
  0,
@@ -260,7 +289,7 @@ class CouponRepository {
260
289
  $filter: {
261
290
  input: '$couponUsage',
262
291
  as: 'cu',
263
- cond: { $eq: ['$$cu._id', '$couponDocs._id'] },
292
+ cond: { $eq: ['$$cu._id', '$couponDetails._id'] },
264
293
  },
265
294
  },
266
295
  as: 'cu',
@@ -274,80 +303,80 @@ class CouponRepository {
274
303
  $addFields: {
275
304
  isExpired: {
276
305
  $or: [
277
- { $gt: [{ $strLenCP: { $ifNull: ['$couponDocs.expirationReason', ''] } }, 0] },
306
+ { $gt: [{ $strLenCP: { $ifNull: ['$couponDetails.expirationReason', ''] } }, 0] },
278
307
  {
279
308
  $and: [
280
- { $ifNull: ['$couponDocs.duration.end', false] },
281
- { $lt: ['$couponDocs.duration.end', now] },
309
+ { $ifNull: ['$couponDetails.duration.end', false] },
310
+ { $lt: ['$couponDetails.duration.end', now] },
282
311
  ],
283
312
  },
284
313
  ],
285
314
  },
286
315
  exchangeRate,
287
- 'couponDocs.value': {
316
+ 'couponDetails.value': {
288
317
  $switch: {
289
318
  branches: [
290
319
  {
291
- case: { $eq: ['$couponDocs.couponType', enum_1.CouponType.REFERRAL_CODE] },
320
+ case: { $eq: ['$couponDetails.couponType', enum_1.CouponType.REFERRAL_CODE] },
292
321
  then: referralSettings?.receiver?.value ?? 0,
293
322
  },
294
323
  ],
295
- default: '$couponDocs.value',
324
+ default: '$couponDetails.value',
296
325
  },
297
326
  },
298
- 'couponDocs.valueType': {
327
+ 'couponDetails.valueType': {
299
328
  $switch: {
300
329
  branches: [
301
330
  {
302
- case: { $eq: ['$couponDocs.couponType', enum_1.CouponType.REFERRAL_CODE] },
331
+ case: { $eq: ['$couponDetails.couponType', enum_1.CouponType.REFERRAL_CODE] },
303
332
  then: referralSettings?.receiver?.valueType ?? 0,
304
333
  },
305
334
  ],
306
- default: '$couponDocs.valueType',
335
+ default: '$couponDetails.valueType',
307
336
  },
308
337
  },
309
- 'couponDocs.secondaryCurrencyValue': {
338
+ 'couponDetails.secondaryCurrencyValue': {
310
339
  $cond: [
311
- { $eq: ['$couponDocs.valueType', enum_1.ValueType.PERCENTAGE] },
340
+ { $eq: ['$couponDetails.valueType', enum_1.ValueType.PERCENTAGE] },
312
341
  null,
313
342
  {
314
343
  $switch: {
315
344
  branches: [
316
345
  {
317
- case: { $eq: ['$couponDocs.couponType', enum_1.CouponType.REFERRAL_CODE] },
346
+ case: { $eq: ['$couponDetails.couponType', enum_1.CouponType.REFERRAL_CODE] },
318
347
  then: secondaryReferralReceiverValue,
319
348
  },
320
349
  ],
321
350
  default: (0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
322
- $multiply: ['$couponDocs.value', exchangeRate],
351
+ $multiply: ['$couponDetails.value', exchangeRate],
323
352
  }),
324
353
  },
325
354
  },
326
355
  ],
327
356
  },
328
- 'couponDocs.secondaryCurrencyMaxDiscountLimit': {
357
+ 'couponDetails.secondaryCurrencyMaxDiscountLimit': {
329
358
  $switch: {
330
359
  branches: [
331
360
  {
332
- case: { $eq: ['$couponDocs.couponType', enum_1.CouponType.REFERRAL_CODE] },
361
+ case: { $eq: ['$couponDetails.couponType', enum_1.CouponType.REFERRAL_CODE] },
333
362
  then: null,
334
363
  },
335
364
  ],
336
365
  default: (0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
337
- $multiply: ['$couponDocs.maxDiscountLimit', exchangeRate],
366
+ $multiply: ['$couponDetails.maxDiscountLimit', exchangeRate],
338
367
  }),
339
368
  },
340
369
  },
341
- 'couponDocs.secondaryCurrencyMinOrderValue': {
370
+ 'couponDetails.secondaryCurrencyMinOrderValue': {
342
371
  $switch: {
343
372
  branches: [
344
373
  {
345
- case: { $eq: ['$couponDocs.couponType', enum_1.CouponType.REFERRAL_CODE] },
374
+ case: { $eq: ['$couponDetails.couponType', enum_1.CouponType.REFERRAL_CODE] },
346
375
  then: secondaryReferralReceiverMinOrderAmount,
347
376
  },
348
377
  ],
349
378
  default: (0, common_pipeline_functions_1.getRoundSecondaryCurrencyStage)({
350
- $multiply: ['$couponDocs.minOrderValue', exchangeRate],
379
+ $multiply: ['$couponDetails.minOrderValue', exchangeRate],
351
380
  }),
352
381
  },
353
382
  },
@@ -366,8 +395,8 @@ class CouponRepository {
366
395
  $cond: [
367
396
  {
368
397
  $or: [
369
- { $not: ['$couponDocs.orderLimitPerUser'] },
370
- { $lt: ['$usedCount', '$couponDocs.orderLimitPerUser'] },
398
+ { $not: ['$couponDetails.orderLimitPerUser'] },
399
+ { $lt: ['$usedCount', '$couponDetails.orderLimitPerUser'] },
371
400
  ],
372
401
  },
373
402
  'available',
@@ -385,13 +414,13 @@ class CouponRepository {
385
414
  $group: {
386
415
  _id: '$_id',
387
416
  available: {
388
- $push: { $cond: [{ $eq: ['$category', 'available'] }, '$couponDocs', '$$REMOVE'] },
417
+ $push: { $cond: [{ $eq: ['$category', 'available'] }, '$couponDetails', '$$REMOVE'] },
389
418
  },
390
419
  used: {
391
- $push: { $cond: [{ $eq: ['$category', 'used'] }, '$couponDocs', '$$REMOVE'] },
420
+ $push: { $cond: [{ $eq: ['$category', 'used'] }, '$couponDetails', '$$REMOVE'] },
392
421
  },
393
422
  expired: {
394
- $push: { $cond: [{ $eq: ['$category', 'expired'] }, '$couponDocs', '$$REMOVE'] },
423
+ $push: { $cond: [{ $eq: ['$category', 'expired'] }, '$couponDetails', '$$REMOVE'] },
395
424
  },
396
425
  },
397
426
  },
@@ -465,37 +494,37 @@ class CouponRepository {
465
494
  $or: [
466
495
  {
467
496
  $and: [
468
- { $eq: ['$couponDocs.couponType', enum_1.CouponType.INDIVIDUAL_STORE] },
497
+ { $eq: ['$couponDetails.couponType', enum_1.CouponType.INDIVIDUAL_STORE] },
469
498
  shop
470
- ? { $eq: ['$couponDocs.shop._id', shop] }
471
- : { $eq: ['$couponDocs.vendor._id', vendor] },
499
+ ? { $eq: ['$couponDetails.shop._id', shop] }
500
+ : { $eq: ['$couponDetails.vendor._id', vendor] },
472
501
  ],
473
502
  },
474
503
  {
475
504
  $and: [
476
- { $eq: ['$couponDocs.couponType', enum_1.CouponType.SHOPS_CATEGORIES] },
505
+ { $eq: ['$couponDetails.couponType', enum_1.CouponType.SHOPS_CATEGORIES] },
477
506
  {
478
507
  $or: [
479
- { $in: [itemType, { $ifNull: ['$couponDocs.itemTypes', []] }] },
480
- ...(shop ? [{ $in: [shop, { $ifNull: ['$couponDocs.shops', []] }] }] : []),
481
- ...(vendor ? [{ $in: [vendor, { $ifNull: ['$couponDocs.vendors', []] }] }] : []),
508
+ { $in: [itemType, { $ifNull: ['$couponDetails.itemTypes', []] }] },
509
+ ...(shop ? [{ $in: [shop, { $ifNull: ['$couponDetails.shops', []] }] }] : []),
510
+ ...(vendor ? [{ $in: [vendor, { $ifNull: ['$couponDetails.vendors', []] }] }] : []),
482
511
  ],
483
512
  },
484
513
  ],
485
514
  },
486
515
  {
487
516
  $and: [
488
- { $eq: ['$couponDocs.couponType', enum_1.CouponType.INDIVIDUAL_USER] },
517
+ { $eq: ['$couponDetails.couponType', enum_1.CouponType.INDIVIDUAL_USER] },
489
518
  {
490
519
  $or: [
491
- { $in: [itemType, { $ifNull: ['$couponDocs.itemTypes', []] }] },
492
- ...(shop ? [{ $in: [shop, { $ifNull: ['$couponDocs.shops', []] }] }] : []),
493
- ...(vendor ? [{ $in: [vendor, { $ifNull: ['$couponDocs.vendors', []] }] }] : []),
520
+ { $in: [itemType, { $ifNull: ['$couponDetails.itemTypes', []] }] },
521
+ ...(shop ? [{ $in: [shop, { $ifNull: ['$couponDetails.shops', []] }] }] : []),
522
+ ...(vendor ? [{ $in: [vendor, { $ifNull: ['$couponDetails.vendors', []] }] }] : []),
494
523
  {
495
524
  $and: [
496
- { $eq: [{ $size: { $ifNull: ['$couponDocs.shops', []] } }, 0] },
497
- { $eq: [{ $size: { $ifNull: ['$couponDocs.vendors', []] } }, 0] },
498
- { $eq: [{ $size: { $ifNull: ['$couponDocs.itemTypes', []] } }, 0] },
525
+ { $eq: [{ $size: { $ifNull: ['$couponDetails.shops', []] } }, 0] },
526
+ { $eq: [{ $size: { $ifNull: ['$couponDetails.vendors', []] } }, 0] },
527
+ { $eq: [{ $size: { $ifNull: ['$couponDetails.itemTypes', []] } }, 0] },
499
528
  ],
500
529
  },
501
530
  ],
@@ -506,7 +535,7 @@ class CouponRepository {
506
535
  $not: [
507
536
  {
508
537
  $in: [
509
- '$couponDocs.couponType',
538
+ '$couponDetails.couponType',
510
539
  [enum_1.CouponType.INDIVIDUAL_STORE, enum_1.CouponType.SHOPS_CATEGORIES, enum_1.CouponType.INDIVIDUAL_USER],
511
540
  ],
512
541
  },
@@ -526,8 +555,8 @@ class CouponRepository {
526
555
  ? { $in: [shop, '$orderedShops'] }
527
556
  : {
528
557
  $or: [
529
- { $in: ['$couponDocs.shop._id', '$orderedShops'] },
530
- { $in: ['$couponDocs.vendor._id', '$orderedVendors'] },
558
+ { $in: ['$couponDetails.shop._id', '$orderedShops'] },
559
+ { $in: ['$couponDetails.vendor._id', '$orderedVendors'] },
531
560
  ],
532
561
  };
533
562
  const hasUnusedStoreInCategory = vendor
@@ -540,7 +569,7 @@ class CouponRepository {
540
569
  $eq: [
541
570
  {
542
571
  $size: {
543
- $setDifference: [{ $ifNull: ['$couponDocs.shops', []] }, '$orderedShops'],
572
+ $setDifference: [{ $ifNull: ['$couponDetails.shops', []] }, '$orderedShops'],
544
573
  },
545
574
  },
546
575
  0,
@@ -550,7 +579,7 @@ class CouponRepository {
550
579
  $eq: [
551
580
  {
552
581
  $size: {
553
- $setDifference: [{ $ifNull: ['$couponDocs.vendors', []] }, '$orderedVendors'],
582
+ $setDifference: [{ $ifNull: ['$couponDetails.vendors', []] }, '$orderedVendors'],
554
583
  },
555
584
  },
556
585
  0,
@@ -563,14 +592,14 @@ class CouponRepository {
563
592
  $addFields: {
564
593
  hasOrderedFromStore: {
565
594
  $cond: [
566
- { $eq: ['$couponDocs.couponType', enum_1.CouponType.INDIVIDUAL_STORE] },
595
+ { $eq: ['$couponDetails.couponType', enum_1.CouponType.INDIVIDUAL_STORE] },
567
596
  hasOrderedFromStore,
568
597
  false,
569
598
  ],
570
599
  },
571
600
  hasUnusedShopInCategory: {
572
601
  $cond: [
573
- { $eq: ['$couponDocs.couponType', enum_1.CouponType.SHOPS_CATEGORIES] },
602
+ { $eq: ['$couponDetails.couponType', enum_1.CouponType.SHOPS_CATEGORIES] },
574
603
  hasUnusedStoreInCategory,
575
604
  false,
576
605
  ],
@@ -583,9 +612,12 @@ class CouponRepository {
583
612
  $not: {
584
613
  $and: [
585
614
  {
586
- $in: ['$couponDocs.couponType', [enum_1.CouponType.INDIVIDUAL_STORE, enum_1.CouponType.SHOPS_CATEGORIES]],
615
+ $in: [
616
+ '$couponDetails.couponType',
617
+ [enum_1.CouponType.INDIVIDUAL_STORE, enum_1.CouponType.SHOPS_CATEGORIES],
618
+ ],
587
619
  },
588
- { $eq: ['$couponDocs.firstOrderOnly', true] },
620
+ { $eq: ['$couponDetails.firstOrderOnly', true] },
589
621
  { $or: ['$hasOrderedFromStore', '$hasUnusedShopInCategory'] },
590
622
  ],
591
623
  },
@@ -611,8 +643,6 @@ class CouponRepository {
611
643
  .includes(keyword));
612
644
  });
613
645
  }
614
- result.metadata.totalElements = result.documents.length;
615
- result.metadata.totalPages = Math.ceil(result.documents.length / size);
616
646
  return result;
617
647
  }
618
648
  buildCouponUsersPipeline(params) {
@@ -909,6 +939,416 @@ class CouponRepository {
909
939
  ],
910
940
  });
911
941
  }
942
+ async getReferFriendCouponOrders(params) {
943
+ const { page = 1, size = 10, sort, search, status, startDate, endDate } = params;
944
+ const adminSettings = await (0, core_1.getLibraries)().getCachedSettingsService().getSettings();
945
+ const exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 1;
946
+ const match = {
947
+ couponType: enum_1.CouponType.REFERRAL_REWARD,
948
+ };
949
+ if (startDate || endDate) {
950
+ match.createdAt = {};
951
+ if (startDate) {
952
+ match.createdAt.$gte = new Date(startDate);
953
+ }
954
+ if (endDate) {
955
+ match.createdAt.$lte = new Date(endDate);
956
+ }
957
+ }
958
+ const pipeline = [
959
+ {
960
+ $match: match,
961
+ },
962
+ {
963
+ $lookup: {
964
+ from: 'users',
965
+ localField: 'user',
966
+ foreignField: '_id',
967
+ as: 'senderDoc',
968
+ pipeline: [
969
+ {
970
+ $project: {
971
+ coreUser: 1,
972
+ },
973
+ },
974
+ ],
975
+ },
976
+ },
977
+ {
978
+ $unwind: {
979
+ path: '$senderDoc',
980
+ preserveNullAndEmptyArrays: true,
981
+ },
982
+ },
983
+ {
984
+ $lookup: {
985
+ from: 'users',
986
+ localField: 'referralCodeUsedBy',
987
+ foreignField: '_id',
988
+ as: 'receiverDoc',
989
+ pipeline: [
990
+ {
991
+ $project: {
992
+ coreUser: 1,
993
+ },
994
+ },
995
+ ],
996
+ },
997
+ },
998
+ {
999
+ $unwind: {
1000
+ path: '$receiverDoc',
1001
+ preserveNullAndEmptyArrays: true,
1002
+ },
1003
+ },
1004
+ {
1005
+ $project: {
1006
+ senderDoc: {
1007
+ _id: '$senderDoc._id',
1008
+ coreUser: '$senderDoc.coreUser',
1009
+ },
1010
+ receiverDoc: {
1011
+ _id: '$receiverDoc._id',
1012
+ coreUser: '$receiverDoc.coreUser',
1013
+ },
1014
+ senderGets: {
1015
+ value: '$referralSettingSnapShot.sender.value',
1016
+ valueType: '$referralSettingSnapShot.sender.valueType',
1017
+ },
1018
+ receiverGets: {
1019
+ value: '$referralSettingSnapShot.receiver.value',
1020
+ valueType: '$referralSettingSnapShot.receiver.valueType',
1021
+ },
1022
+ status: enum_1.Status.ACTIVE,
1023
+ referralDate: '$createdAt',
1024
+ conversionDate: {
1025
+ $cond: [
1026
+ {
1027
+ $eq: ['$expirationReason', null],
1028
+ },
1029
+ null,
1030
+ '$updatedAt',
1031
+ ],
1032
+ },
1033
+ },
1034
+ },
1035
+ ];
1036
+ if (search) {
1037
+ const userIds = await this.getCoreUserIds(search);
1038
+ pipeline.push({
1039
+ $match: {
1040
+ $or: [
1041
+ {
1042
+ 'senderDoc.coreUser': {
1043
+ $in: userIds,
1044
+ },
1045
+ },
1046
+ {
1047
+ 'receiverDoc.coreUser': {
1048
+ $in: userIds,
1049
+ },
1050
+ },
1051
+ ],
1052
+ },
1053
+ });
1054
+ }
1055
+ const result = await (0, pagination_1.paginateAggregation)(this.model, pipeline, page, size, sort ?? { createdAt: -1 });
1056
+ const coreUserIds = result.documents
1057
+ .flatMap((doc) => [doc.senderDoc?.coreUser, doc.receiverDoc?.coreUser])
1058
+ .filter(Boolean);
1059
+ const coreUsers = await this.coreUserModel.find({
1060
+ _id: { $in: coreUserIds },
1061
+ });
1062
+ const coreUserMap = new Map(coreUsers.map((user) => [String(user._id), user]));
1063
+ for (const doc of result.documents) {
1064
+ const senderCoreUser = coreUserMap.get(String(doc.senderDoc?.coreUser));
1065
+ const receiverCoreUser = coreUserMap.get(String(doc.receiverDoc?.coreUser));
1066
+ const senderValue = doc.senderGets?.valueType === 'fixed'
1067
+ ? (0, shared_1.roundSecondaryCurrency)((doc.senderGets?.value ?? 0) * exchangeRate)
1068
+ : doc.senderGets?.value;
1069
+ const receiverValue = doc.receiverGets?.valueType === 'fixed'
1070
+ ? (0, shared_1.roundSecondaryCurrency)((doc.receiverGets?.value ?? 0) * exchangeRate)
1071
+ : doc.receiverGets?.value;
1072
+ doc.sender = {
1073
+ _id: String(doc.senderDoc?._id ?? ''),
1074
+ name: senderCoreUser?.name ?? null,
1075
+ photo: senderCoreUser?.profilePhoto ?? null,
1076
+ };
1077
+ doc.receiver = {
1078
+ _id: String(doc.receiverDoc?._id ?? ''),
1079
+ name: receiverCoreUser?.name ?? null,
1080
+ photo: receiverCoreUser?.profilePhoto ?? null,
1081
+ };
1082
+ doc.senderGets = senderValue != null ? `${senderValue} ${doc.senderGets.valueType}` : null;
1083
+ doc.receiverGets = receiverValue != null ? `${receiverValue} ${doc.receiverGets.valueType}` : null;
1084
+ delete doc.senderDoc;
1085
+ delete doc.receiverDoc;
1086
+ }
1087
+ return result;
1088
+ }
1089
+ getAnalyticsGrouping(startDate, endDate) {
1090
+ const diffInDays = Math.ceil((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24)) + 1;
1091
+ return {
1092
+ isDaily: diffInDays <= 30,
1093
+ dateFormat: diffInDays <= 30 ? '%Y-%m-%d' : '%Y-%m',
1094
+ };
1095
+ }
1096
+ fillMissingDates(startDate, endDate, data, valueField) {
1097
+ const dataMap = new Map(data.map(item => [item.date, item[valueField]]));
1098
+ const result = [];
1099
+ const currentDate = new Date(startDate);
1100
+ while (currentDate <= endDate) {
1101
+ const formatter = new Intl.DateTimeFormat('en-CA', {
1102
+ timeZone: time_1.LyxaTimezone,
1103
+ year: 'numeric',
1104
+ month: '2-digit',
1105
+ day: '2-digit',
1106
+ });
1107
+ const parts = formatter.formatToParts(currentDate);
1108
+ const year = parts.find(p => p.type === 'year')?.value;
1109
+ const month = parts.find(p => p.type === 'month')?.value;
1110
+ const day = parts.find(p => p.type === 'day')?.value;
1111
+ const date = `${year}-${month}-${day}`;
1112
+ result.push({
1113
+ date,
1114
+ [valueField]: dataMap.get(date) ?? 0,
1115
+ });
1116
+ currentDate.setDate(currentDate.getDate() + 1);
1117
+ }
1118
+ return result;
1119
+ }
1120
+ fillMissingMonths(startDate, endDate, data, valueField) {
1121
+ const dataMap = new Map(data.map(item => [item.date, item[valueField]]));
1122
+ const result = [];
1123
+ const current = new Date(startDate);
1124
+ current.setDate(1);
1125
+ while (current <= endDate) {
1126
+ const year = current.getFullYear();
1127
+ const month = String(current.getMonth() + 1).padStart(2, '0');
1128
+ const date = `${year}-${month}`;
1129
+ result.push({
1130
+ date,
1131
+ [valueField]: dataMap.get(date) ?? 0,
1132
+ });
1133
+ current.setMonth(current.getMonth() + 1);
1134
+ }
1135
+ return result;
1136
+ }
1137
+ async getReferralsGraphData(payload) {
1138
+ const { startDate, endDate } = payload;
1139
+ const { isDaily, dateFormat } = this.getAnalyticsGrouping(startDate, endDate);
1140
+ const referrals = await this.model.aggregate([
1141
+ {
1142
+ $match: {
1143
+ couponType: enum_1.CouponType.REFERRAL_REWARD,
1144
+ createdAt: {
1145
+ $gte: startDate,
1146
+ $lte: endDate,
1147
+ },
1148
+ },
1149
+ },
1150
+ {
1151
+ $group: {
1152
+ _id: {
1153
+ $dateToString: {
1154
+ format: dateFormat,
1155
+ date: '$createdAt',
1156
+ timezone: time_1.LyxaTimezone,
1157
+ },
1158
+ },
1159
+ totalReferrals: {
1160
+ $sum: 1,
1161
+ },
1162
+ },
1163
+ },
1164
+ {
1165
+ $project: {
1166
+ _id: 0,
1167
+ date: '$_id',
1168
+ totalReferrals: 1,
1169
+ },
1170
+ },
1171
+ {
1172
+ $sort: {
1173
+ date: 1,
1174
+ },
1175
+ },
1176
+ ]);
1177
+ const conversions = await this.model.aggregate([
1178
+ {
1179
+ $match: {
1180
+ couponType: enum_1.CouponType.REFERRAL_REWARD,
1181
+ expirationReason: {
1182
+ $ne: null,
1183
+ },
1184
+ updatedAt: {
1185
+ $gte: startDate,
1186
+ $lte: endDate,
1187
+ },
1188
+ },
1189
+ },
1190
+ {
1191
+ $group: {
1192
+ _id: {
1193
+ $dateToString: {
1194
+ format: dateFormat,
1195
+ date: '$updatedAt',
1196
+ timezone: time_1.LyxaTimezone,
1197
+ },
1198
+ },
1199
+ totalConversions: {
1200
+ $sum: 1,
1201
+ },
1202
+ },
1203
+ },
1204
+ {
1205
+ $project: {
1206
+ _id: 0,
1207
+ date: '$_id',
1208
+ totalConversions: 1,
1209
+ },
1210
+ },
1211
+ {
1212
+ $sort: {
1213
+ date: 1,
1214
+ },
1215
+ },
1216
+ ]);
1217
+ if (!isDaily) {
1218
+ const referralData = this.fillMissingMonths(startDate, endDate, referrals, 'totalReferrals');
1219
+ const conversionData = this.fillMissingMonths(startDate, endDate, conversions, 'totalConversions');
1220
+ return referralData.map((item, index) => ({
1221
+ date: item.date,
1222
+ totalReferrals: item.totalReferrals,
1223
+ totalConversions: conversionData[index].totalConversions,
1224
+ }));
1225
+ }
1226
+ const referralData = this.fillMissingDates(startDate, endDate, referrals, 'totalReferrals');
1227
+ const conversionData = this.fillMissingDates(startDate, endDate, conversions, 'totalConversions');
1228
+ return referralData.map((item, index) => ({
1229
+ date: item.date,
1230
+ totalReferrals: item.totalReferrals,
1231
+ totalConversions: conversionData[index].totalConversions,
1232
+ }));
1233
+ }
1234
+ async getReferFriendMetrics(payload) {
1235
+ const { startDate, endDate } = payload;
1236
+ const [totalReferralsSent, totalReferralsConverted, totalProfit, totalNewCustomers] = await Promise.all([
1237
+ this.orderModel.countDocuments({
1238
+ status: enum_1.RegularOrderStatus.DELIVERED,
1239
+ deletedAt: null,
1240
+ processedAt: {
1241
+ $gte: startDate,
1242
+ $lte: endDate,
1243
+ },
1244
+ 'adjustedFinance.coupon.couponType': enum_1.CouponType.REFERRAL_CODE,
1245
+ }),
1246
+ this.model.countDocuments({
1247
+ couponType: enum_1.CouponType.REFERRAL_REWARD,
1248
+ expirationReason: {
1249
+ $ne: null,
1250
+ },
1251
+ updatedAt: {
1252
+ $gte: startDate,
1253
+ $lte: endDate,
1254
+ },
1255
+ }),
1256
+ this.orderModel.aggregate([
1257
+ {
1258
+ $match: {
1259
+ status: enum_1.RegularOrderStatus.DELIVERED,
1260
+ deletedAt: null,
1261
+ processedAt: {
1262
+ $gte: startDate,
1263
+ $lte: endDate,
1264
+ },
1265
+ 'adjustedFinance.coupon.couponType': enum_1.CouponType.REFERRAL_CODE,
1266
+ },
1267
+ },
1268
+ {
1269
+ $group: {
1270
+ _id: null,
1271
+ total: {
1272
+ $sum: '$adjustedFinance.companyProfit.totalProfit',
1273
+ },
1274
+ },
1275
+ },
1276
+ ]),
1277
+ this.userModel.countDocuments({
1278
+ createdAt: {
1279
+ $gte: startDate,
1280
+ $lte: endDate,
1281
+ },
1282
+ }),
1283
+ ]);
1284
+ const newCustomersFromReferral = await this.model.countDocuments({
1285
+ couponType: enum_1.CouponType.REFERRAL_REWARD,
1286
+ createdAt: {
1287
+ $gte: startDate,
1288
+ $lte: endDate,
1289
+ },
1290
+ });
1291
+ const conversionRate = totalReferralsSent === 0
1292
+ ? 0
1293
+ : Number(((totalReferralsConverted / totalReferralsSent) * 100).toFixed(2));
1294
+ const customerReferralRate = totalNewCustomers === 0 ? 0 : Number(((newCustomersFromReferral / totalNewCustomers) * 100).toFixed(2));
1295
+ return {
1296
+ totalReferralsSent,
1297
+ totalReferralsConverted,
1298
+ totalProfitFromReferrals: totalProfit[0]?.total ?? 0,
1299
+ conversionRate,
1300
+ customerReferralRate,
1301
+ };
1302
+ }
1303
+ async getTotalProfitGraphData(payload) {
1304
+ const { startDate, endDate } = payload;
1305
+ const { isDaily, dateFormat } = this.getAnalyticsGrouping(startDate, endDate);
1306
+ const analytics = await this.orderModel.aggregate([
1307
+ {
1308
+ $match: {
1309
+ status: enum_1.RegularOrderStatus.DELIVERED,
1310
+ deletedAt: null,
1311
+ processedAt: {
1312
+ $gte: startDate,
1313
+ $lte: endDate,
1314
+ },
1315
+ 'adjustedFinance.coupon.couponType': enum_1.CouponType.REFERRAL_CODE,
1316
+ },
1317
+ },
1318
+ {
1319
+ $group: {
1320
+ _id: {
1321
+ $dateToString: {
1322
+ format: dateFormat,
1323
+ date: '$processedAt',
1324
+ timezone: time_1.LyxaTimezone,
1325
+ },
1326
+ },
1327
+ totalProfit: {
1328
+ $sum: {
1329
+ $ifNull: ['$adjustedFinance.companyProfit.totalProfit', 0],
1330
+ },
1331
+ },
1332
+ },
1333
+ },
1334
+ {
1335
+ $project: {
1336
+ _id: 0,
1337
+ date: '$_id',
1338
+ totalProfit: 1,
1339
+ },
1340
+ },
1341
+ {
1342
+ $sort: {
1343
+ date: 1,
1344
+ },
1345
+ },
1346
+ ]);
1347
+ if (!isDaily) {
1348
+ return this.fillMissingMonths(startDate, endDate, analytics, 'totalProfit');
1349
+ }
1350
+ return this.fillMissingDates(startDate, endDate, analytics, 'totalProfit');
1351
+ }
912
1352
  }
913
1353
  exports.CouponRepository = CouponRepository;
914
1354
  //# sourceMappingURL=CouponRepository.js.map