@lyxa.ai/marketing 1.0.37 → 1.0.40

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 (59) hide show
  1. package/dist/lib/index.d.ts +87 -7
  2. package/dist/lib/index.d.ts.map +1 -1
  3. package/dist/lib/modules/coupon/services/coupon.service.d.ts +3 -0
  4. package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
  5. package/dist/lib/modules/coupon/services/coupon.service.js +122 -5
  6. package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
  7. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
  8. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +7 -0
  9. package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
  10. package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
  11. package/dist/lib/modules/coupon/validations/coupon.validation.js +5 -14
  12. package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
  13. package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts +39 -0
  14. package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -0
  15. package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js +539 -0
  16. package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js.map +1 -0
  17. package/dist/lib/modules/marketing/routers/marketing.router.d.ts +87 -7
  18. package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  19. package/dist/lib/modules/marketing/routers/marketing.router.js +27 -8
  20. package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
  21. package/dist/lib/modules/marketing/services/marketing.service.d.ts +4 -8
  22. package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
  23. package/dist/lib/modules/marketing/services/marketing.service.js +65 -355
  24. package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
  25. package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +1 -0
  26. package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
  27. package/dist/lib/modules/marketing/services/product-marketing.service.js +4 -0
  28. package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
  29. package/dist/lib/modules/marketing/validations/marketing.validation.d.ts +106 -1
  30. package/dist/lib/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
  31. package/dist/lib/modules/marketing/validations/marketing.validation.js +31 -1
  32. package/dist/lib/modules/marketing/validations/marketing.validation.js.map +1 -1
  33. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
  34. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js +19 -1
  35. package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js.map +1 -1
  36. package/dist/lib/utility/utils.d.ts +3 -0
  37. package/dist/lib/utility/utils.d.ts.map +1 -0
  38. package/dist/lib/utility/utils.js +31 -0
  39. package/dist/lib/utility/utils.js.map +1 -0
  40. package/dist/types/index.d.ts +87 -7
  41. package/dist/types/index.d.ts.map +1 -1
  42. package/dist/types/modules/coupon/services/coupon.service.d.ts +3 -0
  43. package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
  44. package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
  45. package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
  46. package/dist/types/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts +39 -0
  47. package/dist/types/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -0
  48. package/dist/types/modules/marketing/routers/marketing.router.d.ts +87 -7
  49. package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
  50. package/dist/types/modules/marketing/services/marketing.service.d.ts +4 -8
  51. package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
  52. package/dist/types/modules/marketing/services/product-marketing.service.d.ts +1 -0
  53. package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
  54. package/dist/types/modules/marketing/validations/marketing.validation.d.ts +106 -1
  55. package/dist/types/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
  56. package/dist/types/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
  57. package/dist/types/utility/utils.d.ts +15 -0
  58. package/dist/types/utility/utils.d.ts.map +1 -0
  59. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"coupon.validation.js","sourceRoot":"/","sources":["modules/coupon/validations/coupon.validation.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,4DAA0G;AAC1G,iGAGmE;AACnE,8DAA2D;AAK9C,QAAA,YAAY,GAAG;IAC3B,IAAI,EAAE,iCAAa,CAAC,MAAM,CAAC,MAAM,EAAE;QAClC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,MAAM,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,+BAA+B,EAAE;QACvF,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,CAAC;QACZ,UAAU,EAAE,6BAA6B;QACzC,UAAU,EAAE,6BAA6B;KACzC,CAAC;IACF,iBAAiB,EAAE,iCAAa,CAAC,MAAM,CAAC,mBAAmB,CAAC;SAC1D,WAAW,EAAE;SACb,QAAQ,EAAE;SACV,QAAQ,EAAE;SACV,OAAO,CAAC,IAAI,CAAC;IACf,0BAA0B,EAAE,iCAAa,CAAC,OAAO,CAAC,iCAAiC,CAAC;SAClF,QAAQ,EAAE;SACV,OAAO,CAAC,KAAK,CAAC;IAChB,SAAS,EAAE,iCAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE;IAC1D,SAAS,EAAE,iCAAa,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE;CACzD,CAAC;AAEW,QAAA,UAAU,GAAG;IACzB,GAAG,oBAAY;IACf,SAAS,EAAE,iCAAa,CAAC,QAAQ,CAAC,gBAAS,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AAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,aAAM,CAAC,MAAM,CAAC;CAClF,CAAC,CAAC;AAEU,QAAA,sCAAsC,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9D,MAAM,EAAE,iCAAa,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;CACtD,CAAC,CAAC;AAEU,QAAA,8BAA8B,GAAG,IAAA,wCAAoB,EAAC,oCAA4B,CAAC,CAAC;AAEpF,QAAA,cAAc,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACpD,QAAA,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,qBAAqB,EAAE,OAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA","sourcesContent":["import { z } from 'zod';\nimport {\n\tZodValidation,\n\tcreateSchemaBuilder,\n\tDTO,\n} from '@lyxa.ai/core/dist/utilities/validation/global-validation';\nimport { CouponExpirationReason, CouponType, Status, ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tcreateResponseSchema,\n\tDurationSchema,\n} from '@lyxa.ai/core/dist/utilities/validation/common-validation';\nimport { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\n\n/**\n * Define the base parent schema fields\n */\nexport const couponFields = {\n\tcode: ZodValidation.string('Code', {\n\t\tregex: { pattern: new RegExp('^[A-Z0-9]+$'), message: 'Coupon name must be uppercase' },\n\t\tmaxLength: 6,\n\t\tminLength: 6,\n\t\tminMessage: 'Coupon must be 6 characters',\n\t\tmaxMessage: 'Coupon must be 6 characters',\n\t}),\n\torderLimitPerUser: ZodValidation.number('OrderLimitPerUser')\n\t\t.nonnegative()\n\t\t.optional()\n\t\t.nullable()\n\t\t.default(null),\n\tisOrderLimitPerUserEnabled: ZodValidation.boolean('Is order limit per user enabled')\n\t\t.optional()\n\t\t.default(false),\n\tcreatedBy: ZodValidation.objectId('Created by').optional(),\n\tisExpired: ZodValidation.boolean('Is expired').optional(),\n};\n\nexport const baseFields = {\n\t...couponFields,\n\tvalueType: ZodValidation.enumType(ValueType, 'Value type'),\n\tvalue: ZodValidation.number('Value'),\n\tsecondaryCurrencyValue: ZodValidation.number('Secondary currency value').optional(),\n\tmaxDiscountLimit: ZodValidation.number('Max discount limit').optional().nullable().default(null),\n\tsecondaryCurrencyMaxDiscountLimit: ZodValidation.number('Secondary currency max discount limit').optional(),\n\tisMaxDiscountLimitEnabled: ZodValidation.boolean('Is max discount limit enabled').optional().default(false),\n\tduration: DurationSchema\n\t\t// .refine((d: any) => d.start >= new Date() && d.end >= new Date(), {\n\t\t// \tmessage: 'Start and end dates must not be in the past',\n\t\t// })\n\t\t.transform(duration => {\n\t\t\tduration.start = dayjs(duration.start).toDate();\n\t\t\tduration.end = dayjs(duration.end).toDate();\n\t\t\treturn duration;\n\t\t}),\n\tspendLimit: ZodValidation.number('Spend limit').optional().nullable().default(null),\n\tisSpendLimitEnabled: ZodValidation.boolean('Is spend limit enabled').optional().default(false),\n\ttotalOrderLimit: ZodValidation.number('Total order limit').optional().nullable().default(null),\n\tisTotalOrderLimitEnabled: ZodValidation.boolean('Is total order limit enabled').optional().default(false),\n\tminOrderValue: ZodValidation.number('Min order value').nullable().default(null),\n\tsecondaryCurrencyMinOrderValue: ZodValidation.number('Secondary currency min order value').optional(),\n\tisMinOrderValueEnabled: ZodValidation.boolean('Is min order value enabled').optional().default(false),\n\tforNewUserOnly: ZodValidation.boolean('ForNewUserOnly').optional().default(false),\n\tstatus: ZodValidation.enumType(Status, 'Status').optional().default(Status.ACTIVE),\n\texpirationReason: ZodValidation.enumType(CouponExpirationReason, 'Expiration reason')\n\t\t.optional()\n\t\t.nullable()\n\t\t.default(null),\n\treferringUser: z\n\t\t.object({\n\t\t\tname: ZodValidation.string('Referring user name').optional(),\n\t\t})\n\t\t.optional(),\n};\n\n/**\n * Create schema builder for Parent entity\n * - Includes timestamps\n * - Excludes 'createdAt' from update operations\n */\nconst schemaBuilder = createSchemaBuilder(baseFields);\n\n/**\n * Get all schemas for the Parent entity\n */\nconst {\n\tBaseSchema: CouponValidationSchema,\n\tEntitySchema: CouponSchema,\n\tIdSchema: CouponIdSchema,\n\tUpdateSchema: UpdateCouponSchema,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\n/**\n * Export schemas\n */\nexport const GetUserCouponsResponseSchema = z.object({\n\tavailable: z.array(CouponSchema),\n\tused: z.array(CouponSchema),\n\texpired: z.array(CouponSchema),\n});\n\nexport {\n\tCouponValidationSchema,\n\tCouponSchema,\n\tCouponIdSchema as CouponIdValidationSchema,\n\tUpdateCouponSchema,\n};\n\n/**\n * Schema for getting user coupons\n */\nexport const GetUserCouponSchema = z.object({\n\tuser: ZodValidation.objectId('User').optional(),\n\tshop: ZodValidation.objectId('Shop').optional(),\n\tpage: ZodValidation.number('Page').optional().default(0),\n\tsize: ZodValidation.number('Page size').optional().default(100),\n});\n\n/**\n * Schema for validating coupons\n */\nexport const ValidateCouponSchema = z.object({\n\tuser: ZodValidation.objectIdOrStringSchema,\n\tshop: ZodValidation.objectIdOrStringSchema,\n\tcoupon: ZodValidation.string('Coupon').optional(),\n\tamountBeforeCoupon: ZodValidation.number('Amount before coupon'),\n\tsecondaryAmountBeforeCoupon: ZodValidation.number('Secondary amount before coupon'),\n\tscheduledAt: ZodValidation.date('Scheduled at').optional(),\n});\n\nconst discountCutSchema = z.object({\n\tcompanyCut: ZodValidation.number('companyCut').optional(),\n\tsecondaryCompanyCut: ZodValidation.number('secondaryCompanyCut').optional(),\n\tshopCut: ZodValidation.number('shopCut').optional(),\n\tsecondaryShopCut: ZodValidation.number('secondaryShopCut').optional(),\n});\n\n/**\n * Schema for coupon validation output\n */\nexport const CouponValidationOutputSchema = z.object({\n\tisValid: ZodValidation.boolean('IsValid').default(false),\n\tmessage: ZodValidation.string('Message').optional(),\n\tamountAfterCoupon: ZodValidation.number('Amount after coupon').optional(),\n\tsecondaryAmountAfterCoupon: ZodValidation.number('Secondary amount after coupon').optional(),\n\tdiscountAmount: ZodValidation.number('Coupon Discount').optional(),\n\tsecondaryDiscountAmount: ZodValidation.number('Secondary coupon discount').optional(),\n\tdiscountCut: discountCutSchema.optional(),\n});\n\nexport const CouponCodeSchema = z.object({\n\tcouponCode: ZodValidation.string('Coupon code', {\n\t\tminLength: 6,\n\t\tmaxLength: 6,\n\t\tminMessage: 'Coupon code must be 6 characters',\n\t\tmaxMessage: 'Coupon code must be 6 characters',\n\t\tregex: {\n\t\t\tpattern: /^[A-Z0-9]+$/,\n\t\t\tmessage: 'Coupon must be uppercase and alphanumeric',\n\t\t},\n\t}),\n});\n\nexport const UpdateCouponStatusSchema = z.object({\n\t_id: ZodValidation.objectIdOrStringSchema,\n\tstatus: ZodValidation.enumType(Status, 'Status').optional().default(Status.ACTIVE),\n});\n\nexport const CheckExistingNewUserCouponOutputSchema = z.object({\n\texists: ZodValidation.boolean('Exists').default(false),\n});\n\nexport const CouponValidationResponseSchema = createResponseSchema(CouponValidationOutputSchema);\n\nexport const DeviceIdSchema = z.object({ deviceId: z.string() });\nexport const IsNewUserGiftBoxShownSchema = z.object({ isNewUserGiftBoxShown: z.boolean() })\n\n/**\n * Export DTO types\n */\nexport type CreateCouponDTO = DTO<typeof CouponValidationSchema>;\nexport type CouponDTO = DTO<typeof CouponSchema>;\nexport type UpdateCouponDTO = DTO<typeof UpdateCouponSchema>;\nexport type GetUserCouponDTO = DTO<typeof GetUserCouponSchema>;\nexport type ValidateCouponDTO = DTO<typeof ValidateCouponSchema>;\nexport type CouponValidationOutputDTO = DTO<typeof CouponValidationOutputSchema>;\nexport type GetUserCouponsResponseDTO = DTO<typeof GetUserCouponsResponseSchema>;\nexport type UpdateCouponStatusDTO = DTO<typeof UpdateCouponStatusSchema>;\nexport type CheckExistingNewUserCouponOutputDTO = DTO<typeof CheckExistingNewUserCouponOutputSchema>;\nexport type DeviceIdDTO = DTO<typeof DeviceIdSchema>;\nexport type IsNewUserGiftBoxShownDTO = DTO<typeof IsNewUserGiftBoxShownSchema>;\n"]}
1
+ {"version":3,"file":"coupon.validation.js","sourceRoot":"/","sources":["modules/coupon/validations/coupon.validation.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,4DAA0G;AAC1G,iGAGmE;AACnE,8DAA2D;AAK9C,QAAA,YAAY,GAAG;IAC3B,IAAI,EAAE,iCAAa,CAAC,MAAM,CAAC,MAAM,EAAE;QAClC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,MAAM,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,+BAA+B,EAAE;QACvF,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;QACb,UAAU,EAAE,8BAA8B;QAC1C,UAAU,EAAE,8BAA8B;KAC1C,CAAC;IACF,iBAAiB,EAAE,iCAAa,CAAC,MAAM,CAAC,mBAAmB,CAAC;SAC1D,WAAW,EAAE;SACb,QAAQ,EAAE;SACV,QAAQ,EAAE;SACV,OAAO,CAAC,IAAI,CAAC;IACf,0BAA0B,EAAE,iCAAa,CAAC,OAAO,CAAC,iCAAiC,CAAC;SAClF,QAAQ,EAAE;SACV,OAAO,CAAC,KAAK,CAAC;IAChB,SAAS,EAAE,iCAAa,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE;IAC1D,SAAS,EAAE,iCAAa,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE;CACzD,CAAC;AAEW,QAAA,UAAU,GAAG;IACzB,GAAG,oBAAY;IACf,SAAS,EAAE,iCAAa,CAAC,QAAQ,CAAC,gBAAS,EAAE,YAAY,CAAC;IAC1D,KAAK,EAAE,iCAAa,CAAC,MAAM,CAAC,OAAO,CAAC;IACpC,sBAAsB,EAAE,iCAAa,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC,QAAQ,EAAE;IACnF,gBAAgB,EAAE,iCAAa,CAAC,MAAM,CAAC,oBAAoB,CA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AE,EAAE,CAAC,CAAC;AACpD,QAAA,2BAA2B,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,qBAAqB,EAAE,OAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC","sourcesContent":["import { z } from 'zod';\nimport {\n\tZodValidation,\n\tcreateSchemaBuilder,\n\tDTO,\n} from '@lyxa.ai/core/dist/utilities/validation/global-validation';\nimport { CouponExpirationReason, CouponType, Status, ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tcreateResponseSchema,\n\tDurationSchema,\n} from '@lyxa.ai/core/dist/utilities/validation/common-validation';\nimport { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\n\n/**\n * Define the base parent schema fields\n */\nexport const couponFields = {\n\tcode: ZodValidation.string('Code', {\n\t\tregex: { pattern: new RegExp('^[A-Z0-9]+$'), message: 'Coupon name must be uppercase' },\n\t\tmaxLength: 10,\n\t\tminLength: 10,\n\t\tminMessage: 'Coupon must be 10 characters',\n\t\tmaxMessage: 'Coupon must be 10 characters',\n\t}),\n\torderLimitPerUser: ZodValidation.number('OrderLimitPerUser')\n\t\t.nonnegative()\n\t\t.optional()\n\t\t.nullable()\n\t\t.default(null),\n\tisOrderLimitPerUserEnabled: ZodValidation.boolean('Is order limit per user enabled')\n\t\t.optional()\n\t\t.default(false),\n\tcreatedBy: ZodValidation.objectId('Created by').optional(),\n\tisExpired: ZodValidation.boolean('Is expired').optional(),\n};\n\nexport const baseFields = {\n\t...couponFields,\n\tvalueType: ZodValidation.enumType(ValueType, 'Value type'),\n\tvalue: ZodValidation.number('Value'),\n\tsecondaryCurrencyValue: ZodValidation.number('Secondary currency value').optional(),\n\tmaxDiscountLimit: ZodValidation.number('Max discount limit').optional().nullable().default(null),\n\tsecondaryCurrencyMaxDiscountLimit: ZodValidation.number('Secondary currency max discount limit').optional(),\n\tisMaxDiscountLimitEnabled: ZodValidation.boolean('Is max discount limit enabled').optional().default(false),\n\tduration: DurationSchema\n\t\t// .refine((d: any) => d.start >= new Date() && d.end >= new Date(), {\n\t\t// \tmessage: 'Start and end dates must not be in the past',\n\t\t// })\n\t\t.transform(duration => {\n\t\t\tduration.start = dayjs(duration.start).toDate();\n\t\t\tduration.end = dayjs(duration.end).toDate();\n\t\t\treturn duration;\n\t\t}),\n\tspendLimit: ZodValidation.number('Spend limit').optional().nullable().default(null),\n\tisSpendLimitEnabled: ZodValidation.boolean('Is spend limit enabled').optional().default(false),\n\ttotalOrderLimit: ZodValidation.number('Total order limit').optional().nullable().default(null),\n\tisTotalOrderLimitEnabled: ZodValidation.boolean('Is total order limit enabled').optional().default(false),\n\tminOrderValue: ZodValidation.number('Min order value').nullable().default(null),\n\tsecondaryCurrencyMinOrderValue: ZodValidation.number('Secondary currency min order value').optional(),\n\tisMinOrderValueEnabled: ZodValidation.boolean('Is min order value enabled').optional().default(false),\n\tforNewUserOnly: ZodValidation.boolean('ForNewUserOnly').optional().default(false),\n\tstatus: ZodValidation.enumType(Status, 'Status').optional().default(Status.ACTIVE),\n\texpirationReason: ZodValidation.enumType(CouponExpirationReason, 'Expiration reason')\n\t\t.optional()\n\t\t.nullable()\n\t\t.default(null),\n\treferringUser: z\n\t\t.object({\n\t\t\tname: ZodValidation.string('Referring user name').optional(),\n\t\t})\n\t\t.optional(),\n};\n\n/**\n * Create schema builder for Parent entity\n * - Includes timestamps\n * - Excludes 'createdAt' from update operations\n */\nconst schemaBuilder = createSchemaBuilder(baseFields);\n\n/**\n * Get all schemas for the Parent entity\n */\nconst {\n\tBaseSchema: CouponValidationSchema,\n\tEntitySchema: CouponSchema,\n\tIdSchema: CouponIdSchema,\n\tUpdateSchema: UpdateCouponSchema,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\n/**\n * Export schemas\n */\nexport const GetUserCouponsResponseSchema = z.object({\n\tavailable: z.array(CouponSchema),\n\tused: z.array(CouponSchema),\n\texpired: z.array(CouponSchema),\n});\n\nexport {\n\tCouponValidationSchema,\n\tCouponSchema,\n\tCouponIdSchema as CouponIdValidationSchema,\n\tUpdateCouponSchema,\n};\n\n/**\n * Schema for getting user coupons\n */\nexport const GetUserCouponSchema = z.object({\n\tuser: ZodValidation.objectId('User').optional(),\n\tshop: ZodValidation.objectId('Shop').optional(),\n\tpage: ZodValidation.number('Page').optional().default(0),\n\tsize: ZodValidation.number('Page size').optional().default(100),\n});\n\n/**\n * Schema for validating coupons\n */\nexport const ValidateCouponSchema = z.object({\n\tuser: ZodValidation.objectIdOrStringSchema,\n\tshop: ZodValidation.objectIdOrStringSchema,\n\tcoupon: ZodValidation.string('Coupon').optional(),\n\tamountBeforeCoupon: ZodValidation.number('Amount before coupon'),\n\tsecondaryAmountBeforeCoupon: ZodValidation.number('Secondary amount before coupon'),\n\tscheduledAt: ZodValidation.date('Scheduled at').optional(),\n});\n\nconst discountCutSchema = z.object({\n\tcompanyCut: ZodValidation.number('companyCut').optional(),\n\tsecondaryCompanyCut: ZodValidation.number('secondaryCompanyCut').optional(),\n\tshopCut: ZodValidation.number('shopCut').optional(),\n\tsecondaryShopCut: ZodValidation.number('secondaryShopCut').optional(),\n});\n\n/**\n * Schema for coupon validation output\n */\nexport const CouponValidationOutputSchema = z.object({\n\tisValid: ZodValidation.boolean('IsValid').default(false),\n\tmessage: ZodValidation.string('Message').optional(),\n\tamountAfterCoupon: ZodValidation.number('Amount after coupon').optional(),\n\tsecondaryAmountAfterCoupon: ZodValidation.number('Secondary amount after coupon').optional(),\n\tdiscountAmount: ZodValidation.number('Coupon Discount').optional(),\n\tsecondaryDiscountAmount: ZodValidation.number('Secondary coupon discount').optional(),\n\tdiscountCut: discountCutSchema.optional(),\n});\n\nexport const CouponCodeSchema = z.object({\n\tcouponCode: ZodValidation.string('Coupon code'),\n});\n\nexport const UpdateCouponStatusSchema = z.object({\n\t_id: ZodValidation.objectIdOrStringSchema,\n\tstatus: ZodValidation.enumType(Status, 'Status').optional().default(Status.ACTIVE),\n});\n\nexport const CheckExistingNewUserCouponOutputSchema = z.object({\n\texists: ZodValidation.boolean('Exists').default(false),\n});\n\nexport const CouponValidationResponseSchema = createResponseSchema(CouponValidationOutputSchema);\n\nexport const DeviceIdSchema = z.object({ deviceId: z.string() });\nexport const IsNewUserGiftBoxShownSchema = z.object({ isNewUserGiftBoxShown: z.boolean() });\n\n/**\n * Export DTO types\n */\nexport type CreateCouponDTO = DTO<typeof CouponValidationSchema>;\nexport type CouponDTO = DTO<typeof CouponSchema>;\nexport type UpdateCouponDTO = DTO<typeof UpdateCouponSchema>;\nexport type GetUserCouponDTO = DTO<typeof GetUserCouponSchema>;\nexport type ValidateCouponDTO = DTO<typeof ValidateCouponSchema>;\nexport type CouponValidationOutputDTO = DTO<typeof CouponValidationOutputSchema>;\nexport type GetUserCouponsResponseDTO = DTO<typeof GetUserCouponsResponseSchema>;\nexport type UpdateCouponStatusDTO = DTO<typeof UpdateCouponStatusSchema>;\nexport type CheckExistingNewUserCouponOutputDTO = DTO<typeof CheckExistingNewUserCouponOutputSchema>;\nexport type DeviceIdDTO = DTO<typeof DeviceIdSchema>;\nexport type IsNewUserGiftBoxShownDTO = DTO<typeof IsNewUserGiftBoxShownSchema>;\n"]}
@@ -0,0 +1,39 @@
1
+ import { DocumentType, mongoose } from '@typegoose/typegoose';
2
+ import { LineItem, RegularOrder } from '@lyxa.ai/core/dist/libraries/mongo/models';
3
+ import { MarketingGraphInputDTO, MarketingMetricsDTO, MarketingOrdersGraphOutputDTO } from '../../../marketing/validations';
4
+ import { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';
5
+ import { Duration } from '@lyxa.ai/core/dist/libraries/mongo/models/shared/duration.model';
6
+ export declare class MarketingMetricsRepository {
7
+ private model;
8
+ private orderModel;
9
+ constructor();
10
+ calculateMarketingSpendPerOrder(order: DocumentType<RegularOrder> & {
11
+ lineItems: DocumentType<LineItem>[];
12
+ }): Map<mongoose.Types.ObjectId, number>;
13
+ calculateMarketingSpent(marketingId: mongoose.Types.ObjectId, duration?: Duration): Promise<{
14
+ amount: number;
15
+ marketingType: MarketingType;
16
+ }>;
17
+ private calculateItemBasedSpent;
18
+ private calculateFreeDeliverySpent;
19
+ private calculatePunchMarketingSpent;
20
+ private buildBaseMatch;
21
+ private runAggregateAndGetTotal;
22
+ getMetrics(marketingId: mongoose.Types.ObjectId): Promise<MarketingMetricsDTO>;
23
+ private getMarketingItemCount;
24
+ private calculateOrderIncreaseWithDiscount;
25
+ private calculateCustomerIncreaseWithDiscount;
26
+ private calculateIncrease;
27
+ private getNewCustomersForShop;
28
+ getOrdersGraph(data: MarketingGraphInputDTO): Promise<MarketingOrdersGraphOutputDTO>;
29
+ getCustomersGraph(data: MarketingGraphInputDTO): Promise<{
30
+ date: string;
31
+ users: number;
32
+ }[]>;
33
+ getAmountSpentGraph(data: MarketingGraphInputDTO): Promise<{
34
+ date: string;
35
+ amount: number;
36
+ }[]>;
37
+ }
38
+ export declare const marketingMetricsRepository: MarketingMetricsRepository;
39
+ //# sourceMappingURL=MarketingMetricsRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MarketingMetricsRepository.d.ts","sourceRoot":"/","sources":["modules/marketing/patterns/repository/MarketingMetricsRepository.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAEN,QAAQ,EAGR,YAAY,EAEZ,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAEN,sBAAsB,EACtB,mBAAmB,EACnB,6BAA6B,EAC7B,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,OAAO,EAAE,QAAQ,EAAE,MAAM,iEAAiE,CAAC;AAI3F,qBACa,0BAA0B;IACtC,OAAO,CAAC,KAAK,CAAiD;IAC9D,OAAO,CAAC,UAAU,CAA2D;;IAOtE,+BAA+B,CACrC,KAAK,EAAE,YAAY,CAAC,YAAY,CAAC,GAAG;QAAE,SAAS,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAA;KAAE,GACzE,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;IAiD1B,uBAAuB,CACnC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACpC,QAAQ,CAAC,EAAE,QAAQ,GACjB,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,aAAa,CAAA;KAAE,CAAC;YA4B9C,uBAAuB;YAqCvB,0BAA0B;YAyB1B,4BAA4B;IAsB1C,OAAO,CAAC,cAAc;YAkBR,uBAAuB;IAKxB,UAAU,CAAC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC;YAmC7E,qBAAqB;YAKrB,kCAAkC;YA2BlC,qCAAqC;IAcnD,OAAO,CAAC,iBAAiB;YAWX,sBAAsB;IA8BvB,cAAc,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAwDpF,iBAAiB,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAsF3F,mBAAmB,CAC/B,IAAI,EAAE,sBAAsB,GAC1B,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAgL9C;AAED,eAAO,MAAM,0BAA0B,4BAA4C,CAAC"}
@@ -0,0 +1,539 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __metadata = (this && this.__metadata) || function (k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.marketingMetricsRepository = exports.MarketingMetricsRepository = void 0;
46
+ const typedi_1 = __importStar(require("typedi"));
47
+ const dayjs_1 = require("@lyxa.ai/core/dist/utilities/dayjs");
48
+ const typegoose_1 = require("@typegoose/typegoose");
49
+ const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models");
50
+ const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
51
+ const product_marketing_service_1 = require("../../../marketing/services/product-marketing.service");
52
+ const enum_2 = require("@lyxa.ai/core/dist/utilities/enum");
53
+ const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
54
+ const time_1 = require("@lyxa.ai/core/dist/utilities/time");
55
+ const utils_1 = require("../../../../utility/utils");
56
+ let MarketingMetricsRepository = class MarketingMetricsRepository {
57
+ model;
58
+ orderModel;
59
+ constructor() {
60
+ this.model = models_1.MarketingModel;
61
+ this.orderModel = models_1.RegularOrderModel;
62
+ }
63
+ calculateMarketingSpendPerOrder(order) {
64
+ const spendMap = new Map();
65
+ const addSpend = (marketingId, amount) => {
66
+ if (!amount || amount <= 0)
67
+ return;
68
+ spendMap.set(marketingId, (spendMap.get(marketingId) ?? 0) + amount);
69
+ };
70
+ for (const lineItem of order.lineItems ?? []) {
71
+ for (const marketingId of lineItem.marketings ?? []) {
72
+ const snap = lineItem.calculationSnap ?? {};
73
+ addSpend(marketingId._id, (Number(snap.itemDiscountByCompany) || 0) +
74
+ (Number(snap.itemDiscountByShop) || 0) +
75
+ (Number(snap.b1g1DiscountByCompany) || 0) +
76
+ (Number(snap.b1g1DiscountByShop) || 0));
77
+ }
78
+ }
79
+ if (order.adjustedFinance?.freeDelivery) {
80
+ for (const marketingId of order.marketings ?? []) {
81
+ addSpend(marketingId._id, (order.adjustedFinance.freeDelivery.companyCut ?? 0) +
82
+ (order.adjustedFinance.freeDelivery.shopCut ?? 0));
83
+ }
84
+ }
85
+ if (order.adjustedFinance?.pricing?.punchMarketingDiscount) {
86
+ for (const marketingId of order.marketings ?? []) {
87
+ addSpend(marketingId._id, order.adjustedFinance.pricing.punchMarketingDiscount);
88
+ }
89
+ }
90
+ return spendMap;
91
+ }
92
+ async calculateMarketingSpent(marketingId, duration) {
93
+ const marketing = await this.model.findById(marketingId).lean();
94
+ if (!marketing) {
95
+ (0, error_common_1.notFoundError)('Marketing not found');
96
+ }
97
+ const calculators = {
98
+ [enum_2.MarketingType.FREE_DELIVERY]: () => this.calculateFreeDeliverySpent(marketingId, duration),
99
+ [enum_2.MarketingType.DISCOUNT]: () => this.calculateItemBasedSpent(marketingId, duration),
100
+ [enum_2.MarketingType.BUY1GET1]: () => this.calculateItemBasedSpent(marketingId, duration),
101
+ [enum_2.MarketingType.PUNCH_MARKETING]: () => this.calculatePunchMarketingSpent(marketingId, duration),
102
+ [enum_2.MarketingType.FEATURED]: function () {
103
+ return Promise.resolve(marketing.amount || 0);
104
+ },
105
+ };
106
+ const amount = calculators[marketing.marketingType] ? await calculators[marketing.marketingType]() : 0;
107
+ return {
108
+ amount,
109
+ marketingType: marketing.marketingType,
110
+ };
111
+ }
112
+ async calculateItemBasedSpent(marketingId, duration) {
113
+ const pipeline = [
114
+ this.buildBaseMatch(marketingId, duration),
115
+ {
116
+ $lookup: {
117
+ from: 'lineItems',
118
+ localField: 'cart',
119
+ foreignField: 'cart',
120
+ as: 'lineItems',
121
+ },
122
+ },
123
+ { $unwind: '$lineItems' },
124
+ {
125
+ $group: {
126
+ _id: null,
127
+ totalSpent: {
128
+ $sum: {
129
+ $add: [
130
+ { $ifNull: ['$lineItems.calculationSnap.itemDiscountByCompany', 0] },
131
+ { $ifNull: ['$lineItems.calculationSnap.itemDiscountByShop', 0] },
132
+ { $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByCompany', 0] },
133
+ { $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByShop', 0] },
134
+ ],
135
+ },
136
+ },
137
+ },
138
+ },
139
+ ];
140
+ return this.runAggregateAndGetTotal(pipeline, 'totalSpent');
141
+ }
142
+ async calculateFreeDeliverySpent(marketingId, duration) {
143
+ const pipeline = [
144
+ this.buildBaseMatch(marketingId, duration),
145
+ {
146
+ $group: {
147
+ _id: null,
148
+ totalSpent: {
149
+ $sum: {
150
+ $add: [
151
+ { $ifNull: ['$adjustedFinance.freeDelivery.companyCut', 0] },
152
+ { $ifNull: ['$adjustedFinance.freeDelivery.shopCut', 0] },
153
+ ],
154
+ },
155
+ },
156
+ },
157
+ },
158
+ ];
159
+ return this.runAggregateAndGetTotal(pipeline, 'totalSpent');
160
+ }
161
+ async calculatePunchMarketingSpent(marketingId, duration) {
162
+ const pipeline = [
163
+ this.buildBaseMatch(marketingId, duration),
164
+ {
165
+ $group: {
166
+ _id: null,
167
+ totalSpent: {
168
+ $sum: {
169
+ $ifNull: ['$adjustedFinance.pricing.punchMarketingDiscount', 0],
170
+ },
171
+ },
172
+ },
173
+ },
174
+ ];
175
+ return this.runAggregateAndGetTotal(pipeline, 'totalSpent');
176
+ }
177
+ buildBaseMatch(marketingId, duration) {
178
+ return {
179
+ $match: {
180
+ marketings: marketingId,
181
+ status: { $ne: enum_1.RegularOrderStatus.CANCELLED },
182
+ ...(duration && {
183
+ processedAt: {
184
+ $gte: duration.start,
185
+ $lte: duration.end,
186
+ },
187
+ }),
188
+ },
189
+ };
190
+ }
191
+ async runAggregateAndGetTotal(pipeline, field) {
192
+ const [result] = await this.orderModel.aggregate(pipeline);
193
+ return result?.[field] ?? 0;
194
+ }
195
+ async getMetrics(marketingId) {
196
+ const marketing = await this.model.findById(marketingId).lean();
197
+ if (!marketing) {
198
+ (0, error_common_1.notFoundError)('Marketing not found');
199
+ }
200
+ const currentDuration = { start: marketing.duration.start, end: (0, dayjs_1.dayjs)().toDate() };
201
+ const previousDuration = {
202
+ start: (0, dayjs_1.dayjs)(marketing.duration.start).subtract((0, dayjs_1.dayjs)().diff(marketing.duration.start)).toDate(),
203
+ end: marketing.duration.start,
204
+ };
205
+ let metrics = {};
206
+ if ([enum_2.MarketingType.DISCOUNT, enum_2.MarketingType.BUY1GET1].includes(marketing.marketingType)) {
207
+ metrics.numberOfItems = await this.getMarketingItemCount(marketingId);
208
+ }
209
+ metrics.orderIncreaseWithDiscount = await this.calculateOrderIncreaseWithDiscount(marketingId, marketing.shop._id, currentDuration, previousDuration);
210
+ metrics.customerIncreaseWithDiscount = await this.calculateCustomerIncreaseWithDiscount(marketingId, marketing.shop._id, currentDuration, previousDuration);
211
+ return metrics;
212
+ }
213
+ async getMarketingItemCount(marketingId) {
214
+ const result = await product_marketing_service_1.productMarketingService.countDocuments({ marketing: marketingId });
215
+ return result ?? 0;
216
+ }
217
+ async calculateOrderIncreaseWithDiscount(marketingId, shopId, currentDuration, previousDuration) {
218
+ const [currentOrders, previousOrders] = await Promise.all([
219
+ this.orderModel.countDocuments({
220
+ createdAt: {
221
+ $gte: currentDuration.start,
222
+ $lte: currentDuration.end,
223
+ },
224
+ marketings: marketingId,
225
+ shop: shopId,
226
+ }),
227
+ this.orderModel.countDocuments({
228
+ createdAt: {
229
+ $gte: previousDuration.start,
230
+ $lte: previousDuration.end,
231
+ },
232
+ shop: shopId,
233
+ }),
234
+ ]);
235
+ return this.calculateIncrease(currentOrders, previousOrders);
236
+ }
237
+ async calculateCustomerIncreaseWithDiscount(marketingId, shopId, currentDuration, previousDuration) {
238
+ const [currentNewCustomers, previousNewCustomers] = await Promise.all([
239
+ this.getNewCustomersForShop(shopId, currentDuration, { marketings: marketingId }),
240
+ this.getNewCustomersForShop(shopId, previousDuration),
241
+ ]);
242
+ return this.calculateIncrease(currentNewCustomers, previousNewCustomers);
243
+ }
244
+ calculateIncrease(current, previous) {
245
+ const count = current - previous;
246
+ const percentageIncrease = previous === 0 ? (current > 0 ? 100 : 0) : (count / previous) * 100;
247
+ return {
248
+ count,
249
+ percentageIncrease,
250
+ };
251
+ }
252
+ async getNewCustomersForShop(shopId, duration, extraMatch = {}) {
253
+ const customersInPeriod = await this.orderModel.distinct('user', {
254
+ createdAt: {
255
+ $gte: duration.start,
256
+ $lte: duration.end,
257
+ },
258
+ shop: shopId,
259
+ ...extraMatch,
260
+ });
261
+ if (customersInPeriod.length === 0) {
262
+ return 0;
263
+ }
264
+ const existingCustomers = await this.orderModel.distinct('user', {
265
+ shop: shopId,
266
+ createdAt: { $lt: duration.start },
267
+ user: { $in: customersInPeriod },
268
+ });
269
+ return customersInPeriod.length - existingCustomers.length;
270
+ }
271
+ async getOrdersGraph(data) {
272
+ const dateFormat = data.type === enum_1.GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';
273
+ const pipeline = [
274
+ this.buildBaseMatch(new typegoose_1.mongoose.Types.ObjectId(data.marketingId), {
275
+ start: data.startDate,
276
+ end: data.endDate,
277
+ }),
278
+ {
279
+ $project: {
280
+ date: {
281
+ $dateToString: {
282
+ format: dateFormat,
283
+ date: '$processedAt',
284
+ timezone: time_1.LyxaTimezone,
285
+ },
286
+ },
287
+ },
288
+ },
289
+ {
290
+ $group: {
291
+ _id: '$date',
292
+ orders: { $sum: 1 },
293
+ },
294
+ },
295
+ {
296
+ $sort: { _id: 1 },
297
+ },
298
+ {
299
+ $project: {
300
+ _id: 0,
301
+ date: '$_id',
302
+ orders: 1,
303
+ },
304
+ },
305
+ ];
306
+ const results = await this.orderModel.aggregate(pipeline).allowDiskUse(true).exec();
307
+ const graphData = (0, utils_1.fillMissingPeriods)(results, data.startDate, data.endDate, data.type, {
308
+ orders: 0,
309
+ });
310
+ return graphData;
311
+ }
312
+ async getCustomersGraph(data) {
313
+ const marketing = await this.model.findById(data.marketingId).select('shop').lean();
314
+ if (!marketing) {
315
+ (0, error_common_1.notFoundError)('Marketing not found');
316
+ }
317
+ const shopId = marketing.shop._id;
318
+ const oldUsers = await this.orderModel.distinct('user', {
319
+ shop: shopId,
320
+ status: enum_1.RegularOrderStatus.DELIVERED,
321
+ processedAt: { $lt: data.startDate },
322
+ });
323
+ const dateFormat = data.type === enum_1.GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';
324
+ const pipeline = [
325
+ {
326
+ $match: {
327
+ orderType: enum_1.OrderType.REGULAR,
328
+ status: enum_1.RegularOrderStatus.DELIVERED,
329
+ shop: shopId,
330
+ marketings: new typegoose_1.mongoose.Types.ObjectId(data.marketingId),
331
+ processedAt: { $gte: data.startDate, $lte: data.endDate },
332
+ user: { $nin: oldUsers },
333
+ },
334
+ },
335
+ { $sort: { processedAt: 1 } },
336
+ {
337
+ $group: {
338
+ _id: '$user',
339
+ firstOrderDate: { $first: '$processedAt' },
340
+ },
341
+ },
342
+ {
343
+ $project: {
344
+ date: {
345
+ $dateToString: {
346
+ format: dateFormat,
347
+ date: '$firstOrderDate',
348
+ timezone: time_1.LyxaTimezone,
349
+ },
350
+ },
351
+ },
352
+ },
353
+ {
354
+ $group: {
355
+ _id: '$date',
356
+ users: { $sum: 1 },
357
+ },
358
+ },
359
+ { $sort: { _id: 1 } },
360
+ {
361
+ $project: {
362
+ _id: 0,
363
+ date: '$_id',
364
+ users: 1,
365
+ },
366
+ },
367
+ ];
368
+ const results = await this.orderModel.aggregate(pipeline).allowDiskUse(true).exec();
369
+ return (0, utils_1.fillMissingPeriods)(results, data.startDate, data.endDate, data.type, {
370
+ users: 0,
371
+ });
372
+ }
373
+ async getAmountSpentGraph(data) {
374
+ const marketing = await this.model.findById(data.marketingId).lean();
375
+ if (!marketing) {
376
+ (0, error_common_1.notFoundError)('Marketing not found');
377
+ }
378
+ const marketingId = new typegoose_1.mongoose.Types.ObjectId(data.marketingId);
379
+ const dateFormat = data.type === enum_1.GraphType.MONTHLY ? '%Y-%m' : '%Y-%m-%d';
380
+ let pipeline = null;
381
+ if ([enum_2.MarketingType.DISCOUNT, enum_2.MarketingType.BUY1GET1].includes(marketing.marketingType)) {
382
+ pipeline = [
383
+ this.buildBaseMatch(marketingId, {
384
+ start: data.startDate,
385
+ end: data.endDate,
386
+ }),
387
+ {
388
+ $lookup: {
389
+ from: 'lineItems',
390
+ localField: 'cart',
391
+ foreignField: 'cart',
392
+ as: 'lineItems',
393
+ },
394
+ },
395
+ { $unwind: '$lineItems' },
396
+ {
397
+ $match: {
398
+ 'lineItems.marketings': marketingId,
399
+ },
400
+ },
401
+ {
402
+ $project: {
403
+ date: {
404
+ $dateToString: {
405
+ format: dateFormat,
406
+ date: '$processedAt',
407
+ timezone: time_1.LyxaTimezone,
408
+ },
409
+ },
410
+ amount: {
411
+ $add: [
412
+ {
413
+ $cond: [
414
+ marketing.isAppliedByCompany,
415
+ { $ifNull: ['$lineItems.calculationSnap.itemDiscountByCompany', 0] },
416
+ { $ifNull: ['$lineItems.calculationSnap.itemDiscountByShop', 0] },
417
+ ],
418
+ },
419
+ {
420
+ $cond: [
421
+ marketing.isAppliedByCompany,
422
+ { $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByCompany', 0] },
423
+ { $ifNull: ['$lineItems.calculationSnap.b1g1DiscountByShop', 0] },
424
+ ],
425
+ },
426
+ ],
427
+ },
428
+ },
429
+ },
430
+ {
431
+ $group: {
432
+ _id: '$date',
433
+ amount: { $sum: '$amount' },
434
+ },
435
+ },
436
+ { $sort: { _id: 1 } },
437
+ {
438
+ $project: {
439
+ _id: 0,
440
+ date: '$_id',
441
+ amount: 1,
442
+ },
443
+ },
444
+ ];
445
+ }
446
+ else if (marketing.marketingType === enum_2.MarketingType.FREE_DELIVERY) {
447
+ pipeline = [
448
+ this.buildBaseMatch(marketingId, {
449
+ start: data.startDate,
450
+ end: data.endDate,
451
+ }),
452
+ {
453
+ $project: {
454
+ date: {
455
+ $dateToString: {
456
+ format: dateFormat,
457
+ date: '$processedAt',
458
+ timezone: time_1.LyxaTimezone,
459
+ },
460
+ },
461
+ amount: {
462
+ $cond: [
463
+ marketing.isAppliedByCompany,
464
+ { $ifNull: ['$adjustedFinance.freeDelivery.companyCut', 0] },
465
+ { $ifNull: ['$adjustedFinance.freeDelivery.shopCut', 0] },
466
+ ],
467
+ },
468
+ },
469
+ },
470
+ {
471
+ $group: {
472
+ _id: '$date',
473
+ amount: { $sum: '$amount' },
474
+ },
475
+ },
476
+ { $sort: { _id: 1 } },
477
+ {
478
+ $project: {
479
+ _id: 0,
480
+ date: '$_id',
481
+ amount: 1,
482
+ },
483
+ },
484
+ ];
485
+ }
486
+ else if (marketing.marketingType === enum_2.MarketingType.PUNCH_MARKETING) {
487
+ pipeline = [
488
+ this.buildBaseMatch(marketingId, {
489
+ start: data.startDate,
490
+ end: data.endDate,
491
+ }),
492
+ {
493
+ $project: {
494
+ date: {
495
+ $dateToString: {
496
+ format: dateFormat,
497
+ date: '$processedAt',
498
+ timezone: time_1.LyxaTimezone,
499
+ },
500
+ },
501
+ amount: {
502
+ $ifNull: ['$adjustedFinance.pricing.punchMarketingDiscount', 0],
503
+ },
504
+ },
505
+ },
506
+ {
507
+ $group: {
508
+ _id: '$date',
509
+ amount: { $sum: '$amount' },
510
+ },
511
+ },
512
+ { $sort: { _id: 1 } },
513
+ {
514
+ $project: {
515
+ _id: 0,
516
+ date: '$_id',
517
+ amount: 1,
518
+ },
519
+ },
520
+ ];
521
+ }
522
+ if (!pipeline) {
523
+ return (0, utils_1.fillMissingPeriods)([], data.startDate, data.endDate, data.type, {
524
+ amount: 0,
525
+ });
526
+ }
527
+ const results = await this.orderModel.aggregate(pipeline).allowDiskUse(true).exec();
528
+ return (0, utils_1.fillMissingPeriods)(results, data.startDate, data.endDate, data.type, {
529
+ amount: 0,
530
+ });
531
+ }
532
+ };
533
+ exports.MarketingMetricsRepository = MarketingMetricsRepository;
534
+ exports.MarketingMetricsRepository = MarketingMetricsRepository = __decorate([
535
+ (0, typedi_1.Service)(),
536
+ __metadata("design:paramtypes", [])
537
+ ], MarketingMetricsRepository);
538
+ exports.marketingMetricsRepository = typedi_1.default.get(MarketingMetricsRepository);
539
+ //# sourceMappingURL=MarketingMetricsRepository.js.map