@lyxa.ai/marketing 1.0.65 → 1.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/index.d.ts +11810 -21
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +0 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts +0 -1074
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.d.ts +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.js +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js +3 -3
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js +0 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/transformers/coupon.transformer.d.ts +0 -50
- package/dist/lib/modules/coupon/transformers/coupon.transformer.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts +0 -822
- package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts +0 -98
- package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js +1 -4
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js.map +1 -1
- package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.d.ts +0 -374
- package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.js +0 -2
- package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.js.map +1 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.js +1 -4
- package/dist/lib/modules/deal-setting/services/deal-setting.service.js.map +1 -1
- package/dist/lib/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
- package/dist/lib/modules/featured-setting/services/featured-setting.service.js +0 -3
- package/dist/lib/modules/featured-setting/services/featured-setting.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts +8 -54
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js +0 -13
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js +0 -9
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js +6 -2
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +3 -16
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js +3 -22
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +0 -2
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js +0 -12
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +35 -242
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js +1 -19
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +1 -10
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js +1 -83
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +0 -4
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js +6 -75
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js +19 -46
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +10 -241
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts +0 -2
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js +4 -13
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
- package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js +1 -1
- package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +3 -30
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js +1 -23
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +0 -18
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js +0 -103
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +2 -187
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js +0 -34
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +116 -515
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js +6 -16
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +4 -11
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js +7 -48
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +5 -19
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js +16 -114
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.d.ts +3 -7
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +32 -76
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +0 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.js +0 -32
- package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/validations/punch-marketing.validation.d.ts +4 -4
- package/dist/lib/modules/referral-setting/validations/referral-setting.validation.d.ts.map +1 -1
- package/dist/lib/modules/referral-setting/validations/referral-setting.validation.js.map +1 -1
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.d.ts +2 -3
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.d.ts.map +1 -1
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.js +3 -11
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.repository.js.map +1 -1
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.router.d.ts +0 -16
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.router.d.ts.map +1 -1
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.d.ts +2 -2
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.d.ts.map +1 -1
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.service.js.map +1 -1
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.d.ts +0 -19
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.d.ts.map +1 -1
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.js +0 -1
- package/dist/lib/modules/spend-to-get-history/spend-to-get-history.validation.js.map +1 -1
- package/dist/types/index.d.ts +11810 -21
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts +0 -1074
- package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/coupon.service.d.ts +1 -1
- package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/transformers/coupon.transformer.d.ts +0 -50
- package/dist/types/modules/coupon/transformers/coupon.transformer.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts +0 -822
- package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts +0 -98
- package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/referral-reward-coupon.validation.d.ts +0 -374
- package/dist/types/modules/coupon/validations/referral-reward-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
- package/dist/types/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts +8 -54
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +1 -0
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +3 -16
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +0 -2
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +35 -242
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +1 -10
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +0 -4
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +10 -241
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts +0 -2
- package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +3 -30
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +0 -18
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +2 -187
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +116 -515
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +4 -11
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +5 -19
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/marketing.service.d.ts +3 -7
- package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts +0 -6
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/punch-marketing.validation.d.ts +4 -4
- package/dist/types/modules/referral-setting/validations/referral-setting.validation.d.ts.map +1 -1
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.repository.d.ts +2 -3
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.repository.d.ts.map +1 -1
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.router.d.ts +0 -16
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.router.d.ts.map +1 -1
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.service.d.ts +2 -2
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.service.d.ts.map +1 -1
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.validation.d.ts +0 -19
- package/dist/types/modules/spend-to-get-history/spend-to-get-history.validation.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts +0 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts.map +0 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js +0 -2
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js.map +0 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts +0 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts.map +0 -1
package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LtoEmptyResponseSchema = exports.
|
|
3
|
+
exports.LtoEmptyResponseSchema = exports.LtoCampaignParticipantsResponseSchema = exports.LtoCampaignHistoryResponseSchema = exports.LtoActiveCampaignResponseSchema = exports.LtoCampaignNullableResponseSchema = exports.LtoCampaignResponseSchema = exports.LtoActiveCampaignSchema = exports.LtoCampaignParticipantItemSchema = exports.LtoCampaignHistoryItemSchema = exports.LtoCampaignSchema = exports.GetLtoCampaignParticipantsSchema = exports.GetLtoCampaignHistorySchema = exports.GetActiveCampaignSchema = exports.UpdateLtoCampaignSchema = exports.CreateLtoCampaignSchema = void 0;
|
|
4
4
|
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
5
5
|
const validation_1 = require("@lyxa.ai/core/dist/utilities/validation");
|
|
6
6
|
const zod_1 = require("zod");
|
|
@@ -10,8 +10,6 @@ exports.CreateLtoCampaignSchema = zod_1.z
|
|
|
10
10
|
subTitle: validation_1.ZodValidation.string('Campaign subtitle').optional(),
|
|
11
11
|
startDate: validation_1.ZodValidation.date('Start date'),
|
|
12
12
|
endDate: validation_1.ZodValidation.date('End date'),
|
|
13
|
-
campaignType: validation_1.ZodValidation.enumType(enum_1.MarketingType, 'Campaign type').default(enum_1.MarketingType.DISCOUNT),
|
|
14
|
-
repeatDays: zod_1.z.array(zod_1.z.number().int().min(0).max(6)).optional(),
|
|
15
13
|
})
|
|
16
14
|
.superRefine((d, ctx) => {
|
|
17
15
|
const now = new Date();
|
|
@@ -31,7 +29,6 @@ exports.UpdateLtoCampaignSchema = zod_1.z
|
|
|
31
29
|
endDate: validation_1.ZodValidation.date('End date'),
|
|
32
30
|
discountOptions: zod_1.z.array(validation_1.ZodValidation.number('Discount option')).min(1).optional(),
|
|
33
31
|
maxDiscountCaps: zod_1.z.array(validation_1.ZodValidation.number('Max discount cap')).min(1).optional(),
|
|
34
|
-
repeatDays: zod_1.z.array(zod_1.z.number().int().min(0).max(6)).optional(),
|
|
35
32
|
confirmActive: zod_1.z.boolean().optional(),
|
|
36
33
|
})
|
|
37
34
|
.superRefine((d, ctx) => {
|
|
@@ -77,7 +74,6 @@ exports.LtoCampaignSchema = zod_1.z.object({
|
|
|
77
74
|
status: validation_1.ZodValidation.enumType(enum_1.LimitedTimeOfferCampaignStatus, 'Status'),
|
|
78
75
|
discountOptions: zod_1.z.array(validation_1.ZodValidation.number('Discount option')).default([]),
|
|
79
76
|
maxDiscountCaps: zod_1.z.array(validation_1.ZodValidation.number('Max discount cap')).default([]),
|
|
80
|
-
repeatDays: zod_1.z.array(zod_1.z.number().int().min(0).max(6)).default([]),
|
|
81
77
|
archivedAt: zod_1.z.date().nullable().optional(),
|
|
82
78
|
createdAt: zod_1.z.date().nullable().optional(),
|
|
83
79
|
updatedAt: zod_1.z.date().nullable().optional(),
|
|
@@ -105,25 +101,11 @@ exports.LtoActiveCampaignSchema = zod_1.z.object({
|
|
|
105
101
|
startTime: zod_1.z.date().nullable().optional(),
|
|
106
102
|
endTime: zod_1.z.date().nullable().optional(),
|
|
107
103
|
});
|
|
108
|
-
exports.GetLtoCampaignSessionsSchema = zod_1.z.object({
|
|
109
|
-
campaignId: validation_1.ZodValidation.objectId(),
|
|
110
|
-
page: zod_1.z.number().int().positive().default(1),
|
|
111
|
-
size: zod_1.z.number().int().positive().max(100).default(20),
|
|
112
|
-
});
|
|
113
|
-
exports.LtoCampaignSessionSchema = zod_1.z.object({
|
|
114
|
-
_id: validation_1.ZodValidation.objectId(),
|
|
115
|
-
campaign: validation_1.ZodValidation.objectId(),
|
|
116
|
-
startDate: zod_1.z.date(),
|
|
117
|
-
endDate: zod_1.z.date(),
|
|
118
|
-
shopCount: validation_1.ZodValidation.number('Shop count'),
|
|
119
|
-
archivedAt: zod_1.z.date(),
|
|
120
|
-
});
|
|
121
104
|
exports.LtoCampaignResponseSchema = (0, validation_1.createResponseSchema)(exports.LtoCampaignSchema);
|
|
122
105
|
exports.LtoCampaignNullableResponseSchema = (0, validation_1.createResponseSchema)(exports.LtoCampaignSchema.nullable());
|
|
123
106
|
exports.LtoActiveCampaignResponseSchema = (0, validation_1.createResponseSchema)(exports.LtoActiveCampaignSchema.nullable());
|
|
124
107
|
exports.LtoCampaignHistoryResponseSchema = (0, validation_1.createResponseSchema)(exports.LtoCampaignHistoryItemSchema);
|
|
125
108
|
exports.LtoCampaignParticipantsResponseSchema = (0, validation_1.createResponseSchema)(exports.LtoCampaignParticipantItemSchema);
|
|
126
|
-
exports.LtoCampaignSessionsResponseSchema = (0, validation_1.createResponseSchema)(exports.LtoCampaignSessionSchema);
|
|
127
109
|
exports.LtoEmptyResponseSchema = zod_1.z.object({
|
|
128
110
|
success: zod_1.z.boolean(),
|
|
129
111
|
message: zod_1.z.string(),
|
package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-campaign.validation.js","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.ts"],"names":[],"mappings":";;;AAAA,4DAAgG;AAChG,wEAAiG;AACjG,6BAAsB;AAET,QAAA,uBAAuB,GAAG,OAAC;KACnC,MAAM,CAAC;IACJ,KAAK,EAAE,0BAA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AQ,EAAE,CAAC,CAAC;AACvF,QAAA,+BAA+B,GAAG,IAAA,iCAAoB,EAAC,+BAAuB,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC3F,QAAA,gCAAgC,GAAG,IAAA,iCAAoB,EAAC,oCAA4B,CAAC,CAAC;AACtF,QAAA,qCAAqC,GAAG,IAAA,iCAAoB,EAAC,wCAAgC,CAAC,CAAC;AAC/F,QAAA,iCAAiC,GAAG,IAAA,iCAAoB,EAAC,gCAAwB,CAAC,CAAC;AACnF,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE;IACpB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC","sourcesContent":["import {LimitedTimeOfferCampaignStatus, MarketingType} from '@lyxa.ai/core/dist/utilities/enum';\nimport {createResponseSchema, DTO, ZodValidation} from '@lyxa.ai/core/dist/utilities/validation';\nimport {z} from 'zod';\n\nexport const CreateLtoCampaignSchema = z\n .object({\n title: ZodValidation.string('Campaign title').optional(),\n subTitle: ZodValidation.string('Campaign subtitle').optional(),\n startDate: ZodValidation.date('Start date'),\n endDate: ZodValidation.date('End date'),\n campaignType: ZodValidation.enumType(MarketingType, 'Campaign type').default(MarketingType.DISCOUNT),\n repeatDays: z.array(z.number().int().min(0).max(6)).optional(),\n })\n .superRefine((d, ctx) => {\n const now = new Date();\n if (d.endDate <= now) {\n ctx.addIssue({code: z.ZodIssueCode.custom, message: 'End date cannot be in the past', path: ['endDate']});\n }\n if (d.endDate <= d.startDate) {\n ctx.addIssue({code: z.ZodIssueCode.custom, message: 'End date must be after start date', path: ['endDate']});\n }\n });\n\nexport const UpdateLtoCampaignSchema = z\n .object({\n _id: ZodValidation.objectId(),\n title: ZodValidation.string('Campaign title').optional(),\n subTitle: ZodValidation.string('Campaign subtitle').optional(),\n startDate: ZodValidation.date('Start date'),\n endDate: ZodValidation.date('End date'),\n discountOptions: z.array(ZodValidation.number('Discount option')).min(1).optional(),\n maxDiscountCaps: z.array(ZodValidation.number('Max discount cap')).min(1).optional(),\n repeatDays: z.array(z.number().int().min(0).max(6)).optional(),\n confirmActive: z.boolean().optional(),\n })\n .superRefine((d, ctx) => {\n const now = new Date();\n if (d.endDate <= now) {\n ctx.addIssue({code: z.ZodIssueCode.custom, message: 'End date cannot be in the past', path: ['endDate']});\n }\n if (d.endDate <= d.startDate) {\n ctx.addIssue({code: z.ZodIssueCode.custom, message: 'End date must be after start date', path: ['endDate']});\n }\n });\n\nexport const GetActiveCampaignSchema = z.object({\n latitude: ZodValidation.number('Latitude'),\n longitude: ZodValidation.number('Longitude'),\n});\n\nexport const GetLtoCampaignHistorySchema = z.object({\n page: z.number().int().positive().default(1),\n size: z.number().int().positive().max(50).default(20),\n status: z\n .union([\n z.literal(LimitedTimeOfferCampaignStatus.EXPIRED),\n z.literal(LimitedTimeOfferCampaignStatus.CANCELLED),\n ])\n .optional(),\n sortBy: z\n .enum(['id', 'campaignNumber', 'startDateTime', 'endDateTime', 'shopsJoined', 'status'])\n .optional(),\n sortOrder: z.enum(['asc', 'desc']).optional(),\n});\n\nexport const GetLtoCampaignParticipantsSchema = z.object({\n campaignId: ZodValidation.objectId(),\n search: ZodValidation.string('Search').optional(),\n page: z.number().int().positive().default(1),\n size: z.number().int().positive().max(100).default(20),\n});\n\nexport const LtoCampaignSchema = z.object({\n _id: ZodValidation.objectId(),\n campaignNumber: ZodValidation.number('Campaign number'),\n title: ZodValidation.string('Campaign title').optional(),\n subTitle: ZodValidation.string('Campaign subtitle').optional(),\n startDate: z.date().nullable().optional(),\n endDate: z.date().nullable().optional(),\n status: ZodValidation.enumType(LimitedTimeOfferCampaignStatus, 'Status'),\n discountOptions: z.array(ZodValidation.number('Discount option')).default([]),\n maxDiscountCaps: z.array(ZodValidation.number('Max discount cap')).default([]),\n repeatDays: z.array(z.number().int().min(0).max(6)).default([]),\n archivedAt: z.date().nullable().optional(),\n createdAt: z.date().nullable().optional(),\n updatedAt: z.date().nullable().optional(),\n});\n\nexport const LtoCampaignHistoryItemSchema = z.object({\n id: z.string(),\n campaignNumber: ZodValidation.number('Campaign number'),\n startDateTime: z.date().nullable().optional(),\n endDateTime: z.date().nullable().optional(),\n shopsJoined: ZodValidation.number('Shops joined'),\n status: ZodValidation.enumType(LimitedTimeOfferCampaignStatus, 'Status'),\n});\n\nexport const LtoCampaignParticipantItemSchema = z.object({\n shopId: ZodValidation.objectId(),\n shopName: z.string().nullable(),\n shopPhoto: z.string().nullable().optional(),\n joinedAt: z.date(),\n discountPercentage: ZodValidation.number('Discount percentage').optional(),\n maxDiscountCap: ZodValidation.number('Max discount cap').optional(),\n});\n\nexport const LtoActiveCampaignSchema = z.object({\n _id: ZodValidation.objectId(),\n title: ZodValidation.string('Campaign title').optional(),\n subtitle: ZodValidation.string('Campaign subtitle').optional(),\n startTime: z.date().nullable().optional(),\n endTime: z.date().nullable().optional(),\n});\n\nexport const GetLtoCampaignSessionsSchema = z.object({\n campaignId: ZodValidation.objectId(),\n page: z.number().int().positive().default(1),\n size: z.number().int().positive().max(100).default(20),\n});\n\nexport const LtoCampaignSessionSchema = z.object({\n _id: ZodValidation.objectId(),\n campaign: ZodValidation.objectId(),\n startDate: z.date(),\n endDate: z.date(),\n shopCount: ZodValidation.number('Shop count'),\n archivedAt: z.date(),\n});\n\n// Response schemas\nexport const LtoCampaignResponseSchema = createResponseSchema(LtoCampaignSchema);\nexport const LtoCampaignNullableResponseSchema = createResponseSchema(LtoCampaignSchema.nullable());\nexport const LtoActiveCampaignResponseSchema = createResponseSchema(LtoActiveCampaignSchema.nullable());\nexport const LtoCampaignHistoryResponseSchema = createResponseSchema(LtoCampaignHistoryItemSchema);\nexport const LtoCampaignParticipantsResponseSchema = createResponseSchema(LtoCampaignParticipantItemSchema);\nexport const LtoCampaignSessionsResponseSchema = createResponseSchema(LtoCampaignSessionSchema);\nexport const LtoEmptyResponseSchema = z.object({\n success: z.boolean(),\n message: z.string(),\n});\n\n// DTOs\nexport type GetActiveCampaignDTO = DTO<typeof GetActiveCampaignSchema>;\nexport type CreateLtoCampaignDTO = DTO<typeof CreateLtoCampaignSchema>;\nexport type UpdateLtoCampaignDTO = DTO<typeof UpdateLtoCampaignSchema>;\nexport type GetLtoCampaignHistoryDTO = DTO<typeof GetLtoCampaignHistorySchema>;\nexport type GetLtoCampaignParticipantsDTO = DTO<typeof GetLtoCampaignParticipantsSchema>;\nexport type GetLtoCampaignSessionsDTO = DTO<typeof GetLtoCampaignSessionsSchema>;\nexport type LtoCampaignDTO = DTO<typeof LtoCampaignSchema>;\nexport type LtoActiveCampaignDTO = DTO<typeof LtoActiveCampaignSchema>;\nexport type LtoCampaignHistoryItemDTO = DTO<typeof LtoCampaignHistoryItemSchema>;\nexport type LtoCampaignParticipantItemDTO = DTO<typeof LtoCampaignParticipantItemSchema>;\n"]}
|
|
1
|
+
{"version":3,"file":"limited-time-offer-campaign.validation.js","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.ts"],"names":[],"mappings":";;;AAAA,4DAAiF;AACjF,wEAAiG;AACjG,6BAAsB;AAET,QAAA,uBAAuB,GAAG,OAAC;KACnC,MAAM,CAAC;IACJ,KAAK,EAAE,0BAAa,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;IACxD,QAAQ,EAAE,0BAAa,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,QAAQ,EAAE;IAC9D,SAAS,EAAE,0BAAa,CAAC,IAAI,CAAC,YAAY,CAAC;IAC3C,OAAO,EAAE,0BAAa,CAAC,IAAI,CAAC,UAAU,CAAC;CAC1C,CAAC;KACD,WAAW,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;IACpB,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,IAAI,CAAC,CAAC,OAAO,IAAI,GAAG,EAAE,CAAC;QACnB,GAAG,CAAC,QAAQ,CAAC,EAAC,IAAI,EAAE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C1E,cAAc,EAAE,0BAAa,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,QAAQ,EAAE;CACtE,CAAC,CAAC;AAEU,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5C,GAAG,EAAE,0BAAa,CAAC,QAAQ,EAAE;IAC7B,KAAK,EAAE,0BAAa,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;IACxD,QAAQ,EAAE,0BAAa,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,QAAQ,EAAE;IAC9D,SAAS,EAAE,OAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IACzC,OAAO,EAAE,OAAC,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;CAC1C,CAAC,CAAC;AAGU,QAAA,yBAAyB,GAAG,IAAA,iCAAoB,EAAC,yBAAiB,CAAC,CAAC;AACpE,QAAA,iCAAiC,GAAG,IAAA,iCAAoB,EAAC,yBAAiB,CAAC,QAAQ,EAAE,CAAC,CAAC;AACvF,QAAA,+BAA+B,GAAG,IAAA,iCAAoB,EAAC,+BAAuB,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC3F,QAAA,gCAAgC,GAAG,IAAA,iCAAoB,EAAC,oCAA4B,CAAC,CAAC;AACtF,QAAA,qCAAqC,GAAG,IAAA,iCAAoB,EAAC,wCAAgC,CAAC,CAAC;AAC/F,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE;IACpB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;CACtB,CAAC,CAAC","sourcesContent":["import {LimitedTimeOfferCampaignStatus} from '@lyxa.ai/core/dist/utilities/enum';\nimport {createResponseSchema, DTO, ZodValidation} from '@lyxa.ai/core/dist/utilities/validation';\nimport {z} from 'zod';\n\nexport const CreateLtoCampaignSchema = z\n .object({\n title: ZodValidation.string('Campaign title').optional(),\n subTitle: ZodValidation.string('Campaign subtitle').optional(),\n startDate: ZodValidation.date('Start date'),\n endDate: ZodValidation.date('End date'),\n })\n .superRefine((d, ctx) => {\n const now = new Date();\n if (d.endDate <= now) {\n ctx.addIssue({code: z.ZodIssueCode.custom, message: 'End date cannot be in the past', path: ['endDate']});\n }\n if (d.endDate <= d.startDate) {\n ctx.addIssue({code: z.ZodIssueCode.custom, message: 'End date must be after start date', path: ['endDate']});\n }\n });\n\nexport const UpdateLtoCampaignSchema = z\n .object({\n _id: ZodValidation.objectId(),\n title: ZodValidation.string('Campaign title').optional(),\n subTitle: ZodValidation.string('Campaign subtitle').optional(),\n startDate: ZodValidation.date('Start date'),\n endDate: ZodValidation.date('End date'),\n discountOptions: z.array(ZodValidation.number('Discount option')).min(1).optional(),\n maxDiscountCaps: z.array(ZodValidation.number('Max discount cap')).min(1).optional(),\n confirmActive: z.boolean().optional(),\n })\n .superRefine((d, ctx) => {\n const now = new Date();\n if (d.endDate <= now) {\n ctx.addIssue({code: z.ZodIssueCode.custom, message: 'End date cannot be in the past', path: ['endDate']});\n }\n if (d.endDate <= d.startDate) {\n ctx.addIssue({code: z.ZodIssueCode.custom, message: 'End date must be after start date', path: ['endDate']});\n }\n });\n\nexport const GetActiveCampaignSchema = z.object({\n latitude: ZodValidation.number('Latitude'),\n longitude: ZodValidation.number('Longitude'),\n});\n\nexport const GetLtoCampaignHistorySchema = z.object({\n page: z.number().int().positive().default(1),\n size: z.number().int().positive().max(50).default(20),\n status: z\n .union([\n z.literal(LimitedTimeOfferCampaignStatus.EXPIRED),\n z.literal(LimitedTimeOfferCampaignStatus.CANCELLED),\n ])\n .optional(),\n sortBy: z\n .enum(['id', 'campaignNumber', 'startDateTime', 'endDateTime', 'shopsJoined', 'status'])\n .optional(),\n sortOrder: z.enum(['asc', 'desc']).optional(),\n});\n\nexport const GetLtoCampaignParticipantsSchema = z.object({\n campaignId: ZodValidation.objectId(),\n search: ZodValidation.string('Search').optional(),\n page: z.number().int().positive().default(1),\n size: z.number().int().positive().max(100).default(20),\n});\n\nexport const LtoCampaignSchema = z.object({\n _id: ZodValidation.objectId(),\n campaignNumber: ZodValidation.number('Campaign number'),\n title: ZodValidation.string('Campaign title').optional(),\n subTitle: ZodValidation.string('Campaign subtitle').optional(),\n startDate: z.date().nullable().optional(),\n endDate: z.date().nullable().optional(),\n status: ZodValidation.enumType(LimitedTimeOfferCampaignStatus, 'Status'),\n discountOptions: z.array(ZodValidation.number('Discount option')).default([]),\n maxDiscountCaps: z.array(ZodValidation.number('Max discount cap')).default([]),\n archivedAt: z.date().nullable().optional(),\n createdAt: z.date().nullable().optional(),\n updatedAt: z.date().nullable().optional(),\n});\n\nexport const LtoCampaignHistoryItemSchema = z.object({\n id: z.string(),\n campaignNumber: ZodValidation.number('Campaign number'),\n startDateTime: z.date().nullable().optional(),\n endDateTime: z.date().nullable().optional(),\n shopsJoined: ZodValidation.number('Shops joined'),\n status: ZodValidation.enumType(LimitedTimeOfferCampaignStatus, 'Status'),\n});\n\nexport const LtoCampaignParticipantItemSchema = z.object({\n shopId: ZodValidation.objectId(),\n shopName: z.string().nullable(),\n shopPhoto: z.string().nullable().optional(),\n joinedAt: z.date(),\n discountPercentage: ZodValidation.number('Discount percentage').optional(),\n maxDiscountCap: ZodValidation.number('Max discount cap').optional(),\n});\n\nexport const LtoActiveCampaignSchema = z.object({\n _id: ZodValidation.objectId(),\n title: ZodValidation.string('Campaign title').optional(),\n subtitle: ZodValidation.string('Campaign subtitle').optional(),\n startTime: z.date().nullable().optional(),\n endTime: z.date().nullable().optional(),\n});\n\n// Response schemas\nexport const LtoCampaignResponseSchema = createResponseSchema(LtoCampaignSchema);\nexport const LtoCampaignNullableResponseSchema = createResponseSchema(LtoCampaignSchema.nullable());\nexport const LtoActiveCampaignResponseSchema = createResponseSchema(LtoActiveCampaignSchema.nullable());\nexport const LtoCampaignHistoryResponseSchema = createResponseSchema(LtoCampaignHistoryItemSchema);\nexport const LtoCampaignParticipantsResponseSchema = createResponseSchema(LtoCampaignParticipantItemSchema);\nexport const LtoEmptyResponseSchema = z.object({\n success: z.boolean(),\n message: z.string(),\n});\n\n// DTOs\nexport type GetActiveCampaignDTO = DTO<typeof GetActiveCampaignSchema>;\nexport type CreateLtoCampaignDTO = DTO<typeof CreateLtoCampaignSchema>;\nexport type UpdateLtoCampaignDTO = DTO<typeof UpdateLtoCampaignSchema>;\nexport type GetLtoCampaignHistoryDTO = DTO<typeof GetLtoCampaignHistorySchema>;\nexport type GetLtoCampaignParticipantsDTO = DTO<typeof GetLtoCampaignParticipantsSchema>;\nexport type LtoCampaignDTO = DTO<typeof LtoCampaignSchema>;\nexport type LtoActiveCampaignDTO = DTO<typeof LtoActiveCampaignSchema>;\nexport type LtoCampaignHistoryItemDTO = DTO<typeof LtoCampaignHistoryItemSchema>;\nexport type LtoCampaignParticipantItemDTO = DTO<typeof LtoCampaignParticipantItemSchema>;\n"]}
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { mongoose } from '@typegoose/typegoose';
|
|
2
2
|
export declare class LtoCampaignLifecycleService {
|
|
3
3
|
private repository;
|
|
4
|
-
private scheduler;
|
|
5
|
-
private participantRepository;
|
|
6
|
-
private marketingService;
|
|
7
|
-
private sessionService;
|
|
8
4
|
constructor();
|
|
9
5
|
activateCampaign(campaignId: mongoose.Types.ObjectId): Promise<void>;
|
|
10
|
-
expireCampaign(campaignId: mongoose.Types.ObjectId): Promise<
|
|
11
|
-
demoteToScheduled(campaignId: mongoose.Types.ObjectId): Promise<void>;
|
|
6
|
+
expireCampaign(campaignId: mongoose.Types.ObjectId): Promise<void>;
|
|
12
7
|
cancelCampaign(campaignId: mongoose.Types.ObjectId): Promise<void>;
|
|
13
|
-
private revertParticipantEffects;
|
|
14
|
-
private expireRecurring;
|
|
15
|
-
private createNextOccurrence;
|
|
16
|
-
private cloneParticipants;
|
|
17
8
|
}
|
|
18
9
|
export declare const ltoCampaignLifecycleService: LtoCampaignLifecycleService;
|
|
19
10
|
//# sourceMappingURL=limited-time-offer-campaign-lifecycle.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-campaign-lifecycle.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"limited-time-offer-campaign-lifecycle.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAI9C,qBACa,2BAA2B;IACpC,OAAO,CAAC,UAAU,CAAwB;;IAM7B,gBAAgB,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpE,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlE,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAGlF;AAED,eAAO,MAAM,2BAA2B,6BAA6C,CAAC"}
|
|
@@ -45,102 +45,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
45
45
|
exports.ltoCampaignLifecycleService = exports.LtoCampaignLifecycleService = void 0;
|
|
46
46
|
const typedi_1 = __importStar(require("typedi"));
|
|
47
47
|
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
48
|
-
const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
|
|
49
48
|
const limited_time_offer_campaign_repository_1 = require("../../../limited-time-offer/campaign/limited-time-offer-campaign.repository");
|
|
50
|
-
const limited_time_offer_campaign_scheduler_service_1 = require("./limited-time-offer-campaign-scheduler.service");
|
|
51
|
-
const limited_time_offer_participant_marketing_service_1 = require("../../../limited-time-offer/participant/services/limited-time-offer-participant-marketing.service");
|
|
52
|
-
const limited_time_offer_participant_repository_1 = require("../../../limited-time-offer/participant/limited-time-offer-participant.repository");
|
|
53
|
-
const limited_time_offer_participant_builder_1 = require("../../../limited-time-offer/participant/limited-time-offer-participant.builder");
|
|
54
|
-
const limited_time_offer_campaign_session_service_1 = require("../../../limited-time-offer/session/limited-time-offer-campaign-session.service");
|
|
55
|
-
const limited_time_offer_campaign_builder_1 = require("../limited-time-offer-campaign.builder");
|
|
56
|
-
const feature_flags_1 = require("../../../../utility/feature-flags");
|
|
57
49
|
let LtoCampaignLifecycleService = class LtoCampaignLifecycleService {
|
|
58
50
|
repository;
|
|
59
|
-
scheduler;
|
|
60
|
-
participantRepository;
|
|
61
|
-
marketingService;
|
|
62
|
-
sessionService;
|
|
63
51
|
constructor() {
|
|
64
52
|
this.repository = typedi_1.default.get(limited_time_offer_campaign_repository_1.LtoCampaignRepository);
|
|
65
|
-
this.scheduler = typedi_1.default.get(limited_time_offer_campaign_scheduler_service_1.LtoCampaignSchedulerService);
|
|
66
|
-
this.participantRepository = typedi_1.default.get(limited_time_offer_participant_repository_1.LtoParticipantRepository);
|
|
67
|
-
this.marketingService = typedi_1.default.get(limited_time_offer_participant_marketing_service_1.LtoParticipantMarketingService);
|
|
68
|
-
this.sessionService = typedi_1.default.get(limited_time_offer_campaign_session_service_1.LtoCampaignSessionService);
|
|
69
53
|
}
|
|
70
54
|
async activateCampaign(campaignId) {
|
|
71
55
|
await this.repository.setStatus(campaignId, enum_1.LimitedTimeOfferCampaignStatus.ACTIVE);
|
|
72
56
|
}
|
|
73
57
|
async expireCampaign(campaignId) {
|
|
74
|
-
|
|
75
|
-
if (!campaign)
|
|
76
|
-
throw (0, error_common_1.notFoundError)('Campaign not found');
|
|
77
|
-
const isRecurring = (await (0, feature_flags_1.isLtoScheduleEnabled)()) && (campaign.repeatDays ?? []).length > 0;
|
|
78
|
-
if (isRecurring) {
|
|
79
|
-
await this.expireRecurring(campaign);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
await this.repository.setStatus(campaignId, enum_1.LimitedTimeOfferCampaignStatus.EXPIRED, true);
|
|
83
|
-
}
|
|
84
|
-
await this.revertParticipantEffects(campaignId);
|
|
85
|
-
return isRecurring;
|
|
86
|
-
}
|
|
87
|
-
async demoteToScheduled(campaignId) {
|
|
88
|
-
await this.revertParticipantEffects(campaignId);
|
|
89
|
-
await this.participantRepository.clearLiveEffects(campaignId);
|
|
58
|
+
await this.repository.setStatus(campaignId, enum_1.LimitedTimeOfferCampaignStatus.EXPIRED, true);
|
|
90
59
|
}
|
|
91
60
|
async cancelCampaign(campaignId) {
|
|
92
|
-
const campaign = await this.repository.findById(campaignId);
|
|
93
|
-
if (!campaign)
|
|
94
|
-
throw (0, error_common_1.notFoundError)('Campaign not found');
|
|
95
|
-
if ((await (0, feature_flags_1.isLtoScheduleEnabled)()) &&
|
|
96
|
-
(campaign.repeatDays ?? []).length > 0 &&
|
|
97
|
-
campaign.status === enum_1.LimitedTimeOfferCampaignStatus.ACTIVE) {
|
|
98
|
-
const shopCount = await this.participantRepository.countNonWithdrawnByCampaign(campaign._id);
|
|
99
|
-
await this.sessionService.logSession(campaign, shopCount);
|
|
100
|
-
}
|
|
101
61
|
await this.repository.setStatus(campaignId, enum_1.LimitedTimeOfferCampaignStatus.CANCELLED, true);
|
|
102
|
-
await this.revertParticipantEffects(campaignId);
|
|
103
|
-
}
|
|
104
|
-
async revertParticipantEffects(campaignId) {
|
|
105
|
-
await this.marketingService.removeAllCampaignMarketings(campaignId);
|
|
106
|
-
if (!(await (0, feature_flags_1.isLtoScheduleEnabled)()))
|
|
107
|
-
return;
|
|
108
|
-
const pausedMarketingIds = await this.participantRepository.findPausedMarketingIdsByCampaign(campaignId);
|
|
109
|
-
await this.marketingService.resumeMarketings(pausedMarketingIds);
|
|
110
|
-
const participants = await this.participantRepository.findAllActiveByCampaign(campaignId);
|
|
111
|
-
for (const participant of participants) {
|
|
112
|
-
await this.participantRepository.restoreShopOrderCapacity(participant.shop, participant.pausedOrderCapacity, participant.pausedOrderCapacityEnabled);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async expireRecurring(campaign) {
|
|
116
|
-
const shopCount = await this.participantRepository.countNonWithdrawnByCampaign(campaign._id);
|
|
117
|
-
await this.sessionService.logSession(campaign, shopCount);
|
|
118
|
-
await this.repository.setStatus(campaign._id, enum_1.LimitedTimeOfferCampaignStatus.EXPIRED, true);
|
|
119
|
-
const { startDate, endDate } = (0, limited_time_offer_campaign_builder_1.nextOccurrenceDate)(campaign.repeatDays, campaign.startDate, campaign.endDate);
|
|
120
|
-
const nextCampaign = await this.createNextOccurrence(campaign, startDate, endDate);
|
|
121
|
-
await this.cloneParticipants(campaign._id, nextCampaign._id);
|
|
122
|
-
await this.scheduler.scheduleActivation(nextCampaign._id, startDate);
|
|
123
|
-
await this.scheduler.scheduleExpiry(nextCampaign._id, endDate);
|
|
124
|
-
}
|
|
125
|
-
async createNextOccurrence(campaign, startDate, endDate) {
|
|
126
|
-
return this.repository.create({
|
|
127
|
-
campaignNumber: await this.repository.nextCampaignNumber(),
|
|
128
|
-
title: campaign.title,
|
|
129
|
-
subTitle: campaign.subTitle,
|
|
130
|
-
startDate,
|
|
131
|
-
endDate,
|
|
132
|
-
status: enum_1.LimitedTimeOfferCampaignStatus.SCHEDULED,
|
|
133
|
-
campaignType: campaign.campaignType,
|
|
134
|
-
discountOptions: campaign.discountOptions,
|
|
135
|
-
maxDiscountCaps: campaign.maxDiscountCaps,
|
|
136
|
-
repeatDays: campaign.repeatDays,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
async cloneParticipants(fromCampaignId, toCampaignId) {
|
|
140
|
-
const participants = await this.participantRepository.findAllActiveByCampaign(fromCampaignId);
|
|
141
|
-
for (const participant of participants) {
|
|
142
|
-
await this.participantRepository.create(limited_time_offer_participant_builder_1.LtoParticipantQueryBuilder.buildCloneInput(toCampaignId, participant));
|
|
143
|
-
}
|
|
144
62
|
}
|
|
145
63
|
};
|
|
146
64
|
exports.LtoCampaignLifecycleService = LtoCampaignLifecycleService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-campaign-lifecycle.service.js","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAG1C,4DAAiF;AACjF,4EAAwE;AACxE,wIAAkH;AAClH,mHAA4F;AAC5F,wKAE2G;AAC3G,iJAE2F;AAC3F,2IAEwF;AACxF,iJAEyF;AACzF,gGAA0E;AAC1E,0DAA4D;AAGrD,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAC5B,UAAU,CAAwB;IAClC,SAAS,CAA8B;IACvC,qBAAqB,CAA2B;IAChD,gBAAgB,CAAiC;IACjD,cAAc,CAA4B;IAElD;QACI,IAAI,CAAC,UAAU,GAAG,gBAAS,CAAC,GAAG,CAAC,8DAAqB,CAAC,CAAC;QACvD,IAAI,CAAC,SAAS,GAAG,gBAAS,CAAC,GAAG,CAAC,2EAA2B,CAAC,CAAC;QAC5D,IAAI,CAAC,qBAAqB,GAAG,gBAAS,CAAC,GAAG,CAAC,oEAAwB,CAAC,CAAC;QACrE,IAAI,CAAC,gBAAgB,GAAG,gBAAS,CAAC,GAAG,CAAC,iFAA8B,CAAC,CAAC;QACtE,IAAI,CAAC,cAAc,GAAG,gBAAS,CAAC,GAAG,CAAC,uEAAyB,CAAC,CAAC;IACnE,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,UAAmC;QAC7D,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,qCAA8B,CAAC,MAAM,CAAC,CAAC;IACvF,CAAC;IAGM,KAAK,CAAC,cAAc,CAAC,UAAmC;QAC3D,MAAM,QAAQ,GAAG,MAAM,I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,CAAC;QAC9F,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;YACrC,MAAM,IAAI,CAAC,qBAAqB,CAAC,MAAM,CACnC,mEAA0B,CAAC,eAAe,CAAC,YAAY,EAAE,WAAW,CAAC,CACxE,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;AAhIY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,gBAAO,GAAE;;GACG,2BAA2B,CAgIvC;AAEY,QAAA,2BAA2B,GAAG,gBAAS,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {DocumentType, mongoose} from '@typegoose/typegoose';\nimport {LimitedTimeOfferCampaign} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {LimitedTimeOfferCampaignStatus} from '@lyxa.ai/core/dist/utilities/enum';\nimport {notFoundError} from '@lyxa.ai/core/dist/utilities/error-common';\nimport {LtoCampaignRepository} from '@modules/limited-time-offer/campaign/limited-time-offer-campaign.repository';\nimport {LtoCampaignSchedulerService} from './limited-time-offer-campaign-scheduler.service';\nimport {\n LtoParticipantMarketingService\n} from '@modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service';\nimport {\n LtoParticipantRepository\n} from '@modules/limited-time-offer/participant/limited-time-offer-participant.repository';\nimport {\n LtoParticipantQueryBuilder\n} from '@modules/limited-time-offer/participant/limited-time-offer-participant.builder';\nimport {\n LtoCampaignSessionService\n} from '@modules/limited-time-offer/session/limited-time-offer-campaign-session.service';\nimport {nextOccurrenceDate} from '../limited-time-offer-campaign.builder';\nimport {isLtoScheduleEnabled} from '@utility/feature-flags';\n\n@Service()\nexport class LtoCampaignLifecycleService {\n private repository: LtoCampaignRepository;\n private scheduler: LtoCampaignSchedulerService;\n private participantRepository: LtoParticipantRepository;\n private marketingService: LtoParticipantMarketingService;\n private sessionService: LtoCampaignSessionService;\n\n constructor() {\n this.repository = Container.get(LtoCampaignRepository);\n this.scheduler = Container.get(LtoCampaignSchedulerService);\n this.participantRepository = Container.get(LtoParticipantRepository);\n this.marketingService = Container.get(LtoParticipantMarketingService);\n this.sessionService = Container.get(LtoCampaignSessionService);\n }\n\n public async activateCampaign(campaignId: mongoose.Types.ObjectId): Promise<void> {\n await this.repository.setStatus(campaignId, LimitedTimeOfferCampaignStatus.ACTIVE);\n }\n\n // Returns whether the ended campaign was recurring (a fresh scheduled occurrence was spawned).\n public async expireCampaign(campaignId: mongoose.Types.ObjectId): Promise<boolean> {\n const campaign = await this.repository.findById(campaignId);\n if (!campaign) throw notFoundError('Campaign not found');\n\n const isRecurring = (await isLtoScheduleEnabled()) && (campaign.repeatDays ?? []).length > 0;\n if (isRecurring) {\n await this.expireRecurring(campaign);\n } else {\n await this.repository.setStatus(campaignId, LimitedTimeOfferCampaignStatus.EXPIRED, true);\n }\n\n await this.revertParticipantEffects(campaignId);\n return isRecurring;\n }\n\n // Undoes live-campaign effects when postponed back to SCHEDULED: same participants, same campaign\n // doc, no cloning. Reuses the same revert logic cancel/expire rely on, then clears the participants'\n // stale marketing/pause snapshots — safe to skip for cancel/expire since those either end the\n // participant's lifecycle or clone into fresh docs that already omit these fields.\n public async demoteToScheduled(campaignId: mongoose.Types.ObjectId): Promise<void> {\n await this.revertParticipantEffects(campaignId);\n await this.participantRepository.clearLiveEffects(campaignId);\n }\n\n public async cancelCampaign(campaignId: mongoose.Types.ObjectId): Promise<void> {\n const campaign = await this.repository.findById(campaignId);\n if (!campaign) throw notFoundError('Campaign not found');\n\n // Deleting a live recurring session logs that day's session before archiving the campaign.\n if (\n (await isLtoScheduleEnabled()) &&\n (campaign.repeatDays ?? []).length > 0 &&\n campaign.status === LimitedTimeOfferCampaignStatus.ACTIVE\n ) {\n const shopCount = await this.participantRepository.countNonWithdrawnByCampaign(campaign._id);\n await this.sessionService.logSession(campaign, shopCount);\n }\n\n await this.repository.setStatus(campaignId, LimitedTimeOfferCampaignStatus.CANCELLED, true);\n await this.revertParticipantEffects(campaignId);\n }\n\n // Undoes everything the campaign imposed on its participant shops: deletes the LTO discounts,\n // resumes the shops' own paused discounts, and restores each shop's saved order capacity. Runs on\n // every end-of-campaign path (scheduled expiry, admin immediate-expiry, and cancel) so the shops\n // are always reset — for a recurring campaign the next occurrence re-applies them at its activation.\n private async revertParticipantEffects(campaignId: mongoose.Types.ObjectId): Promise<void> {\n await this.marketingService.removeAllCampaignMarketings(campaignId);\n\n if (!(await isLtoScheduleEnabled())) return;\n\n const pausedMarketingIds = await this.participantRepository.findPausedMarketingIdsByCampaign(campaignId);\n await this.marketingService.resumeMarketings(pausedMarketingIds);\n\n const participants = await this.participantRepository.findAllActiveByCampaign(campaignId);\n for (const participant of participants) {\n await this.participantRepository.restoreShopOrderCapacity(\n participant.shop as mongoose.Types.ObjectId,\n participant.pausedOrderCapacity,\n participant.pausedOrderCapacityEnabled\n );\n }\n }\n\n private async expireRecurring(campaign: DocumentType<LimitedTimeOfferCampaign>): Promise<void> {\n const shopCount = await this.participantRepository.countNonWithdrawnByCampaign(campaign._id);\n await this.sessionService.logSession(campaign, shopCount);\n\n await this.repository.setStatus(campaign._id, LimitedTimeOfferCampaignStatus.EXPIRED, true);\n\n const {startDate, endDate} = nextOccurrenceDate(campaign.repeatDays, campaign.startDate, campaign.endDate);\n const nextCampaign = await this.createNextOccurrence(campaign, startDate, endDate);\n await this.cloneParticipants(campaign._id, nextCampaign._id);\n\n await this.scheduler.scheduleActivation(nextCampaign._id, startDate);\n await this.scheduler.scheduleExpiry(nextCampaign._id, endDate);\n }\n\n private async createNextOccurrence(\n campaign: DocumentType<LimitedTimeOfferCampaign>,\n startDate: Date,\n endDate: Date,\n ): Promise<DocumentType<LimitedTimeOfferCampaign>> {\n return this.repository.create({\n campaignNumber: await this.repository.nextCampaignNumber(),\n title: campaign.title,\n subTitle: campaign.subTitle,\n startDate,\n endDate,\n status: LimitedTimeOfferCampaignStatus.SCHEDULED,\n campaignType: campaign.campaignType,\n discountOptions: campaign.discountOptions,\n maxDiscountCaps: campaign.maxDiscountCaps,\n repeatDays: campaign.repeatDays,\n });\n }\n\n private async cloneParticipants(\n fromCampaignId: mongoose.Types.ObjectId,\n toCampaignId: mongoose.Types.ObjectId,\n ): Promise<void> {\n const participants = await this.participantRepository.findAllActiveByCampaign(fromCampaignId);\n for (const participant of participants) {\n await this.participantRepository.create(\n LtoParticipantQueryBuilder.buildCloneInput(toCampaignId, participant),\n );\n }\n }\n}\n\nexport const ltoCampaignLifecycleService = Container.get(LtoCampaignLifecycleService);\n"]}
|
|
1
|
+
{"version":3,"file":"limited-time-offer-campaign-lifecycle.service.js","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,4DAAiF;AACjF,wIAAkH;AAG3G,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAC5B,UAAU,CAAwB;IAE1C;QACI,IAAI,CAAC,UAAU,GAAG,gBAAS,CAAC,GAAG,CAAC,8DAAqB,CAAC,CAAC;IAC3D,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAAC,UAAmC;QAC7D,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,qCAA8B,CAAC,MAAM,CAAC,CAAC;IACvF,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,UAAmC;QAC3D,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,qCAA8B,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC9F,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,UAAmC;QAC3D,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,UAAU,EAAE,qCAA8B,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAChG,CAAC;CACJ,CAAA;AAlBY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,gBAAO,GAAE;;GACG,2BAA2B,CAkBvC;AAEY,QAAA,2BAA2B,GAAG,gBAAS,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {mongoose} from '@typegoose/typegoose';\nimport {LimitedTimeOfferCampaignStatus} from '@lyxa.ai/core/dist/utilities/enum';\nimport {LtoCampaignRepository} from '@modules/limited-time-offer/campaign/limited-time-offer-campaign.repository';\n\n@Service()\nexport class LtoCampaignLifecycleService {\n private repository: LtoCampaignRepository;\n\n constructor() {\n this.repository = Container.get(LtoCampaignRepository);\n }\n\n public async activateCampaign(campaignId: mongoose.Types.ObjectId): Promise<void> {\n await this.repository.setStatus(campaignId, LimitedTimeOfferCampaignStatus.ACTIVE);\n }\n\n public async expireCampaign(campaignId: mongoose.Types.ObjectId): Promise<void> {\n await this.repository.setStatus(campaignId, LimitedTimeOfferCampaignStatus.EXPIRED, true);\n }\n\n public async cancelCampaign(campaignId: mongoose.Types.ObjectId): Promise<void> {\n await this.repository.setStatus(campaignId, LimitedTimeOfferCampaignStatus.CANCELLED, true);\n }\n}\n\nexport const ltoCampaignLifecycleService = Container.get(LtoCampaignLifecycleService);\n"]}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { mongoose } from '@typegoose/typegoose';
|
|
2
2
|
export declare class LtoCampaignSchedulerService {
|
|
3
|
-
private repository;
|
|
4
|
-
constructor();
|
|
5
3
|
scheduleActivation(campaignId: mongoose.Types.ObjectId, startDate: Date): Promise<void>;
|
|
6
4
|
scheduleExpiry(campaignId: mongoose.Types.ObjectId, endDate: Date): Promise<void>;
|
|
7
|
-
private resolveJobDelay;
|
|
8
5
|
cancelJobs(campaignId: mongoose.Types.ObjectId): Promise<void>;
|
|
9
|
-
rescheduleOrphanedRecurring(): Promise<void>;
|
|
10
6
|
private activationJobId;
|
|
11
7
|
private expiryJobId;
|
|
12
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-campaign-scheduler.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"limited-time-offer-campaign-scheduler.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD,qBACa,2BAA2B;IACvB,kBAAkB,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAWvF,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAWjF,UAAU,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAK3E,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,WAAW;CAGtB"}
|
|
@@ -1,101 +1,33 @@
|
|
|
1
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
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
5
|
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
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
7
|
};
|
|
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
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
9
|
exports.LtoCampaignSchedulerService = void 0;
|
|
46
|
-
const typedi_1 =
|
|
10
|
+
const typedi_1 = require("typedi");
|
|
47
11
|
const limited_time_offer_campaign_producer_1 = require("../../../limited-time-offer/campaign/jobs/limited-time-offer-campaign.producer");
|
|
48
|
-
const limited_time_offer_campaign_repository_1 = require("../../../limited-time-offer/campaign/limited-time-offer-campaign.repository");
|
|
49
|
-
const feature_flags_1 = require("../../../../utility/feature-flags");
|
|
50
12
|
let LtoCampaignSchedulerService = class LtoCampaignSchedulerService {
|
|
51
|
-
repository;
|
|
52
|
-
constructor() {
|
|
53
|
-
this.repository = typedi_1.default.get(limited_time_offer_campaign_repository_1.LtoCampaignRepository);
|
|
54
|
-
}
|
|
55
13
|
async scheduleActivation(campaignId, startDate) {
|
|
56
|
-
const delay =
|
|
57
|
-
if (delay
|
|
14
|
+
const delay = startDate.getTime() - Date.now();
|
|
15
|
+
if (delay <= 0)
|
|
58
16
|
return;
|
|
59
17
|
await (0, limited_time_offer_campaign_producer_1.removeLtoCampaignJob)(this.activationJobId(campaignId));
|
|
60
18
|
await (0, limited_time_offer_campaign_producer_1.addLtoCampaignJob)(limited_time_offer_campaign_producer_1.LtoCampaignJobName.ACTIVATE, { campaignId: campaignId.toString() }, { delay, jobId: this.activationJobId(campaignId), removeOnComplete: true });
|
|
61
19
|
}
|
|
62
20
|
async scheduleExpiry(campaignId, endDate) {
|
|
63
|
-
const delay =
|
|
64
|
-
if (delay
|
|
21
|
+
const delay = endDate.getTime() - Date.now();
|
|
22
|
+
if (delay <= 0)
|
|
65
23
|
return;
|
|
66
24
|
await (0, limited_time_offer_campaign_producer_1.removeLtoCampaignJob)(this.expiryJobId(campaignId));
|
|
67
25
|
await (0, limited_time_offer_campaign_producer_1.addLtoCampaignJob)(limited_time_offer_campaign_producer_1.LtoCampaignJobName.EXPIRE, { campaignId: campaignId.toString() }, { delay, jobId: this.expiryJobId(campaignId), removeOnComplete: true });
|
|
68
26
|
}
|
|
69
|
-
async resolveJobDelay(targetTime) {
|
|
70
|
-
const delay = targetTime - Date.now();
|
|
71
|
-
if (await (0, feature_flags_1.isLtoScheduleEnabled)())
|
|
72
|
-
return Math.max(0, delay);
|
|
73
|
-
return delay > 0 ? delay : null;
|
|
74
|
-
}
|
|
75
27
|
async cancelJobs(campaignId) {
|
|
76
28
|
await (0, limited_time_offer_campaign_producer_1.removeLtoCampaignJob)(this.activationJobId(campaignId));
|
|
77
29
|
await (0, limited_time_offer_campaign_producer_1.removeLtoCampaignJob)(this.expiryJobId(campaignId));
|
|
78
30
|
}
|
|
79
|
-
async rescheduleOrphanedRecurring() {
|
|
80
|
-
const queue = (0, limited_time_offer_campaign_producer_1.getLtoCampaignQueue)();
|
|
81
|
-
const delayed = await queue.getDelayed();
|
|
82
|
-
const existingJobIds = new Set(delayed.map(j => j.opts.jobId).filter(Boolean));
|
|
83
|
-
const scheduled = await this.repository.findScheduledRecurring();
|
|
84
|
-
for (const campaign of scheduled) {
|
|
85
|
-
if (!existingJobIds.has(this.activationJobId(campaign._id))) {
|
|
86
|
-
await this.scheduleActivation(campaign._id, campaign.startDate);
|
|
87
|
-
}
|
|
88
|
-
if (!existingJobIds.has(this.expiryJobId(campaign._id))) {
|
|
89
|
-
await this.scheduleExpiry(campaign._id, campaign.endDate);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const active = await this.repository.findActiveRecurring();
|
|
93
|
-
for (const campaign of active) {
|
|
94
|
-
if (!existingJobIds.has(this.expiryJobId(campaign._id))) {
|
|
95
|
-
await this.scheduleExpiry(campaign._id, campaign.endDate);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
31
|
activationJobId(campaignId) {
|
|
100
32
|
return `lto-activate-${campaignId.toString()}`;
|
|
101
33
|
}
|
|
@@ -105,7 +37,6 @@ let LtoCampaignSchedulerService = class LtoCampaignSchedulerService {
|
|
|
105
37
|
};
|
|
106
38
|
exports.LtoCampaignSchedulerService = LtoCampaignSchedulerService;
|
|
107
39
|
exports.LtoCampaignSchedulerService = LtoCampaignSchedulerService = __decorate([
|
|
108
|
-
(0, typedi_1.Service)()
|
|
109
|
-
__metadata("design:paramtypes", [])
|
|
40
|
+
(0, typedi_1.Service)()
|
|
110
41
|
], LtoCampaignSchedulerService);
|
|
111
42
|
//# sourceMappingURL=limited-time-offer-campaign-scheduler.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-campaign-scheduler.service.js","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"limited-time-offer-campaign-scheduler.service.js","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mCAAiC;AAEjC,yIAA6J;AAGtJ,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAC7B,KAAK,CAAC,kBAAkB,CAAC,UAAmC,EAAE,SAAe;QAChF,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/C,IAAI,KAAK,IAAI,CAAC;YAAE,OAAO;QACvB,MAAM,IAAA,2DAAoB,EAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;QAC7D,MAAM,IAAA,wDAAiB,EACnB,yDAAkB,CAAC,QAAQ,EAC3B,EAAE,UAAU,EAAE,UAAU,CAAC,QAAQ,EAAE,EAAE,EACrC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE,CAC7E,CAAC;IACN,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,UAAmC,EAAE,OAAa;QAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7C,IAAI,KAAK,IAAI,CAAC;YAAE,OAAO;QACvB,MAAM,IAAA,2DAAoB,EAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;QACzD,MAAM,IAAA,wDAAiB,EACnB,yDAAkB,CAAC,MAAM,EACzB,EAAE,UAAU,EAAE,UAAU,CAAC,QAAQ,EAAE,EAAE,EACrC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,gBAAgB,EAAE,IAAI,EAAE,CACzE,CAAC;IACN,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,UAAmC;QACvD,MAAM,IAAA,2DAAoB,EAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;QAC7D,MAAM,IAAA,2DAAoB,EAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;IAC7D,CAAC;IAEO,eAAe,CAAC,UAAmC;QACvD,OAAO,gBAAgB,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC;IACnD,CAAC;IAEO,WAAW,CAAC,UAAmC;QACnD,OAAO,cAAc,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC;IACjD,CAAC;CACJ,CAAA;AAnCY,kEAA2B;sCAA3B,2BAA2B;IADvC,IAAA,gBAAO,GAAE;GACG,2BAA2B,CAmCvC","sourcesContent":["import { Service } from 'typedi';\nimport { mongoose } from '@typegoose/typegoose';\nimport { LtoCampaignJobName, addLtoCampaignJob, removeLtoCampaignJob } from '@modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.producer';\n\n@Service()\nexport class LtoCampaignSchedulerService {\n public async scheduleActivation(campaignId: mongoose.Types.ObjectId, startDate: Date): Promise<void> {\n const delay = startDate.getTime() - Date.now();\n if (delay <= 0) return;\n await removeLtoCampaignJob(this.activationJobId(campaignId));\n await addLtoCampaignJob(\n LtoCampaignJobName.ACTIVATE,\n { campaignId: campaignId.toString() },\n { delay, jobId: this.activationJobId(campaignId), removeOnComplete: true }\n );\n }\n\n public async scheduleExpiry(campaignId: mongoose.Types.ObjectId, endDate: Date): Promise<void> {\n const delay = endDate.getTime() - Date.now();\n if (delay <= 0) return;\n await removeLtoCampaignJob(this.expiryJobId(campaignId));\n await addLtoCampaignJob(\n LtoCampaignJobName.EXPIRE,\n { campaignId: campaignId.toString() },\n { delay, jobId: this.expiryJobId(campaignId), removeOnComplete: true }\n );\n }\n\n public async cancelJobs(campaignId: mongoose.Types.ObjectId): Promise<void> {\n await removeLtoCampaignJob(this.activationJobId(campaignId));\n await removeLtoCampaignJob(this.expiryJobId(campaignId));\n }\n\n private activationJobId(campaignId: mongoose.Types.ObjectId): string {\n return `lto-activate-${campaignId.toString()}`;\n }\n\n private expiryJobId(campaignId: mongoose.Types.ObjectId): string {\n return `lto-expire-${campaignId.toString()}`;\n }\n}\n"]}
|
|
@@ -9,7 +9,6 @@ export declare class LtoCampaignService {
|
|
|
9
9
|
private configService;
|
|
10
10
|
constructor();
|
|
11
11
|
create(dto: CreateLtoCampaignDTO): Promise<DocumentType<Model>>;
|
|
12
|
-
private deriveCampaignStatus;
|
|
13
12
|
getCurrent(): Promise<DocumentType<Model> | null>;
|
|
14
13
|
getActive(): Promise<LtoActiveCampaignDTO | null>;
|
|
15
14
|
getById(campaignId: mongoose.Types.ObjectId): Promise<DocumentType<Model>>;
|
|
@@ -31,6 +30,7 @@ export declare class LtoCampaignService {
|
|
|
31
30
|
}>;
|
|
32
31
|
update(dto: UpdateLtoCampaignDTO): Promise<DocumentType<Model>>;
|
|
33
32
|
cancel(campaignId: mongoose.Types.ObjectId): Promise<void>;
|
|
33
|
+
expire(campaignId: mongoose.Types.ObjectId): Promise<void>;
|
|
34
34
|
private assertUpdateAllowed;
|
|
35
35
|
private shouldExpireImmediately;
|
|
36
36
|
private applyImmediateExpiry;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-campaign.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAC,wBAAwB,IAAI,KAAK,EAAC,MAAM,2CAA2C,CAAC;AAC5F,OAAO,EAAC,8BAA8B,EAAgB,MAAM,mCAAmC,CAAC;AAEhG,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,oBAAoB,EACvB,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"limited-time-offer-campaign.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAC,wBAAwB,IAAI,KAAK,EAAC,MAAM,2CAA2C,CAAC;AAC5F,OAAO,EAAC,8BAA8B,EAAgB,MAAM,mCAAmC,CAAC;AAEhG,OAAO,EACH,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,EACpB,oBAAoB,EACvB,MAAM,2CAA2C,CAAC;AASnD,qBACa,kBAAkB;IAC3B,OAAO,CAAC,UAAU,CAAwB;IAC1C,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,SAAS,CAA8B;IAC/C,OAAO,CAAC,aAAa,CAAgC;;IASxC,MAAM,CAAC,GAAG,EAAE,oBAAoB;IAqBhC,UAAU;IAIV,SAAS,IAAI,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAajD,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ;IAM3C,UAAU,CAAC,GAAG,EAAE,wBAAwB;;;;;;;;;;;;;;;;IAQxC,MAAM,CAAC,GAAG,EAAE,oBAAoB;IAoBhC,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAS1D,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvE,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,uBAAuB;YAIjB,oBAAoB;YASpB,wBAAwB;YAmBxB,uBAAuB;IAMrC,OAAO,CAAC,cAAc;YAMR,kBAAkB;CAUnC;AAED,eAAO,MAAM,kBAAkB,oBAAoC,CAAC"}
|
package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js
CHANGED
|
@@ -51,7 +51,6 @@ const limited_time_offer_campaign_scheduler_service_1 = require("./limited-time-
|
|
|
51
51
|
const limited_time_offer_campaign_repository_1 = require("../../../limited-time-offer/campaign/limited-time-offer-campaign.repository");
|
|
52
52
|
const limited_time_offer_campaign_builder_1 = require("../../../limited-time-offer/campaign/limited-time-offer-campaign.builder");
|
|
53
53
|
const limited_time_offer_config_service_1 = require("../../../limited-time-offer/config/limited-time-offer-config.service");
|
|
54
|
-
const feature_flags_1 = require("../../../../utility/feature-flags");
|
|
55
54
|
const ACTIVE_STATUSES = [enum_1.LimitedTimeOfferCampaignStatus.SCHEDULED, enum_1.LimitedTimeOfferCampaignStatus.ACTIVE];
|
|
56
55
|
let LtoCampaignService = class LtoCampaignService {
|
|
57
56
|
repository;
|
|
@@ -66,27 +65,18 @@ let LtoCampaignService = class LtoCampaignService {
|
|
|
66
65
|
}
|
|
67
66
|
async create(dto) {
|
|
68
67
|
await this.assertNoCampaignRunning();
|
|
68
|
+
const now = new Date();
|
|
69
69
|
const config = await this.loadConfigSnapshot();
|
|
70
|
-
const status =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
campaignNumber: await this.repository.nextCampaignNumber(),
|
|
75
|
-
config,
|
|
76
|
-
startDate: dto.startDate,
|
|
77
|
-
endDate: dto.endDate,
|
|
78
|
-
}));
|
|
70
|
+
const status = dto.startDate <= now
|
|
71
|
+
? enum_1.LimitedTimeOfferCampaignStatus.ACTIVE
|
|
72
|
+
: enum_1.LimitedTimeOfferCampaignStatus.SCHEDULED;
|
|
73
|
+
const campaign = await this.repository.create(limited_time_offer_campaign_builder_1.LtoCampaignQueryBuilder.buildCreateInput(dto, status, await this.repository.nextCampaignNumber(), config));
|
|
79
74
|
if (status === enum_1.LimitedTimeOfferCampaignStatus.SCHEDULED) {
|
|
80
75
|
await this.scheduler.scheduleActivation(campaign._id, dto.startDate);
|
|
81
76
|
}
|
|
82
77
|
await this.scheduler.scheduleExpiry(campaign._id, dto.endDate);
|
|
83
78
|
return campaign;
|
|
84
79
|
}
|
|
85
|
-
deriveCampaignStatus(startDate) {
|
|
86
|
-
return startDate <= new Date()
|
|
87
|
-
? enum_1.LimitedTimeOfferCampaignStatus.ACTIVE
|
|
88
|
-
: enum_1.LimitedTimeOfferCampaignStatus.SCHEDULED;
|
|
89
|
-
}
|
|
90
80
|
async getCurrent() {
|
|
91
81
|
return this.repository.findCurrent();
|
|
92
82
|
}
|
|
@@ -112,12 +102,7 @@ let LtoCampaignService = class LtoCampaignService {
|
|
|
112
102
|
const { documents, total } = await this.repository.findHistory(dto);
|
|
113
103
|
return {
|
|
114
104
|
documents,
|
|
115
|
-
metadata: {
|
|
116
|
-
page: dto.page,
|
|
117
|
-
size: dto.size,
|
|
118
|
-
totalElements: total,
|
|
119
|
-
totalPages: Math.ceil(total / dto.size),
|
|
120
|
-
},
|
|
105
|
+
metadata: { page: dto.page, size: dto.size, totalElements: total, totalPages: Math.ceil(total / dto.size) },
|
|
121
106
|
};
|
|
122
107
|
}
|
|
123
108
|
async update(dto) {
|
|
@@ -129,24 +114,10 @@ let LtoCampaignService = class LtoCampaignService {
|
|
|
129
114
|
if (this.shouldExpireImmediately(campaign.status, dto.endDate)) {
|
|
130
115
|
return this.applyImmediateExpiry(dto._id, updates);
|
|
131
116
|
}
|
|
132
|
-
const ltoScheduleEnabled = await (0, feature_flags_1.isLtoScheduleEnabled)();
|
|
133
|
-
const repeatDays = (updates.repeatDays ?? campaign.repeatDays ?? []);
|
|
134
|
-
if (ltoScheduleEnabled &&
|
|
135
|
-
updates.status === enum_1.LimitedTimeOfferCampaignStatus.SCHEDULED &&
|
|
136
|
-
repeatDays.length > 0) {
|
|
137
|
-
const occurrence = (0, limited_time_offer_campaign_builder_1.nextOccurrenceDate)(repeatDays, dto.startDate, dto.endDate);
|
|
138
|
-
updates.startDate = occurrence.startDate;
|
|
139
|
-
updates.endDate = occurrence.endDate;
|
|
140
|
-
}
|
|
141
117
|
const result = await this.repository.updateById(dto._id, updates);
|
|
142
118
|
if (!result)
|
|
143
119
|
throw (0, error_common_1.notFoundError)('Campaign not found after update');
|
|
144
|
-
|
|
145
|
-
campaign.status === enum_1.LimitedTimeOfferCampaignStatus.ACTIVE &&
|
|
146
|
-
result.status === enum_1.LimitedTimeOfferCampaignStatus.SCHEDULED) {
|
|
147
|
-
await this.lifecycle.demoteToScheduled(dto._id);
|
|
148
|
-
}
|
|
149
|
-
await this.rescheduleIfDatesChanged(result, campaign);
|
|
120
|
+
await this.rescheduleIfDatesChanged(dto._id, result.status, campaign, dto);
|
|
150
121
|
return result;
|
|
151
122
|
}
|
|
152
123
|
async cancel(campaignId) {
|
|
@@ -157,6 +128,9 @@ let LtoCampaignService = class LtoCampaignService {
|
|
|
157
128
|
await this.scheduler.cancelJobs(campaignId);
|
|
158
129
|
await this.lifecycle.cancelCampaign(campaignId);
|
|
159
130
|
}
|
|
131
|
+
async expire(campaignId) {
|
|
132
|
+
await this.lifecycle.expireCampaign(campaignId);
|
|
133
|
+
}
|
|
160
134
|
assertUpdateAllowed(campaign, dto) {
|
|
161
135
|
this.assertEditable(campaign.status);
|
|
162
136
|
if (campaign.status === enum_1.LimitedTimeOfferCampaignStatus.ACTIVE && !dto.confirmActive) {
|
|
@@ -178,16 +152,16 @@ let LtoCampaignService = class LtoCampaignService {
|
|
|
178
152
|
throw (0, error_common_1.notFoundError)('Campaign not found after expiry');
|
|
179
153
|
return result;
|
|
180
154
|
}
|
|
181
|
-
async rescheduleIfDatesChanged(
|
|
182
|
-
const datesChanged =
|
|
183
|
-
|
|
155
|
+
async rescheduleIfDatesChanged(campaignId, currentStatus, original, dto) {
|
|
156
|
+
const datesChanged = dto.startDate.getTime() !== original.startDate.getTime() ||
|
|
157
|
+
dto.endDate.getTime() !== original.endDate.getTime();
|
|
184
158
|
if (!datesChanged)
|
|
185
159
|
return;
|
|
186
|
-
await this.scheduler.cancelJobs(
|
|
187
|
-
if (
|
|
188
|
-
await this.scheduler.scheduleActivation(
|
|
160
|
+
await this.scheduler.cancelJobs(campaignId);
|
|
161
|
+
if (currentStatus === enum_1.LimitedTimeOfferCampaignStatus.SCHEDULED) {
|
|
162
|
+
await this.scheduler.scheduleActivation(campaignId, dto.startDate);
|
|
189
163
|
}
|
|
190
|
-
await this.scheduler.scheduleExpiry(
|
|
164
|
+
await this.scheduler.scheduleExpiry(campaignId, dto.endDate);
|
|
191
165
|
}
|
|
192
166
|
async assertNoCampaignRunning() {
|
|
193
167
|
if (await this.repository.hasActiveCampaign()) {
|
|
@@ -200,9 +174,8 @@ let LtoCampaignService = class LtoCampaignService {
|
|
|
200
174
|
}
|
|
201
175
|
}
|
|
202
176
|
async loadConfigSnapshot() {
|
|
203
|
-
const config = await this.configService.getByType(enum_1.MarketingType.DISCOUNT)
|
|
204
|
-
throw (0, error_common_1.badRequestError)('Global config is incomplete. Set discount options and max caps first.');
|
|
205
|
-
});
|
|
177
|
+
const config = await this.configService.getByType(enum_1.MarketingType.DISCOUNT)
|
|
178
|
+
.catch(() => { throw (0, error_common_1.badRequestError)('Global config is incomplete. Set discount options and max caps first.'); });
|
|
206
179
|
if (config.discountOptions.length === 0 || config.maxDiscountCaps.length === 0) {
|
|
207
180
|
throw (0, error_common_1.badRequestError)('Global config is incomplete. Set discount options and max caps first.');
|
|
208
181
|
}
|