@lyxa.ai/marketing 1.0.42 → 1.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/event/event-initializations.d.ts.map +1 -1
- package/dist/lib/event/event-initializations.js +1 -0
- package/dist/lib/event/event-initializations.js.map +1 -1
- package/dist/lib/event/event-listeners/event-listeners.d.ts +1 -0
- package/dist/lib/event/event-listeners/event-listeners.d.ts.map +1 -1
- package/dist/lib/event/event-listeners/event-listeners.js +52 -0
- package/dist/lib/event/event-listeners/event-listeners.js.map +1 -1
- package/dist/lib/event/events/marketing-product-seed.event.d.ts +17 -0
- package/dist/lib/event/events/marketing-product-seed.event.d.ts.map +1 -0
- package/dist/lib/event/events/marketing-product-seed.event.js +12 -0
- package/dist/lib/event/events/marketing-product-seed.event.js.map +1 -0
- package/dist/lib/index.d.ts +165 -83
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts +116 -0
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js +33 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts +32 -0
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -0
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js +503 -0
- package/dist/lib/modules/coupon/services/patterns/repository/CouponMetricsRepository.js.map +1 -0
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +407 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js +39 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
- package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts +1118 -0
- package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -0
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js +13 -0
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js.map +1 -0
- package/dist/lib/modules/coupon/validations/index.d.ts +1 -0
- package/dist/lib/modules/coupon/validations/index.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/index.js +1 -0
- package/dist/lib/modules/coupon/validations/index.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts +29 -72
- 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 +3 -16
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +36 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js +48 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +22 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js +131 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +78 -78
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +1 -2
- 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 +6 -11
- 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.service.d.ts +16 -51
- 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 +33 -156
- 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/config/limited-time-offer-config.builder.d.ts +8 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.builder.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.builder.js +13 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.builder.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.repository.d.ts +14 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.repository.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.repository.js +77 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.repository.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts +1 -2
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.js +19 -26
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer-config.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/config/limited-time-offer.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +35 -78
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +53 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js +55 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +18 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js +126 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +6 -6
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js +1 -2
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.d.ts.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js +2 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.service.js.map +1 -0
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +24 -24
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +3 -1
- 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 +13 -38
- 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 +19 -8
- 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 +19 -27
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts +12 -3
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.js +7 -0
- package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js +11 -9
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/discount-marketing.service.js +15 -13
- package/dist/lib/modules/marketing/services/discount-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.d.ts +1 -0
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +57 -7
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +11 -0
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.js +23 -0
- package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js +6 -31
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.d.ts +2 -2
- package/dist/lib/modules/marketing/validations/product-marketing.validation.d.ts +2 -2
- package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +2 -2
- package/dist/lib/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +4 -4
- package/dist/types/event/event-initializations.d.ts.map +1 -1
- package/dist/types/event/event-listeners/event-listeners.d.ts +1 -0
- package/dist/types/event/event-listeners/event-listeners.d.ts.map +1 -1
- package/dist/types/event/events/marketing-product-seed.event.d.ts +17 -0
- package/dist/types/event/events/marketing-product-seed.event.d.ts.map +1 -0
- package/dist/types/index.d.ts +165 -83
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts +116 -0
- package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts +32 -0
- package/dist/types/modules/coupon/services/patterns/repository/CouponMetricsRepository.d.ts.map +1 -0
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts +407 -1
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts +1118 -0
- package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -0
- package/dist/types/modules/coupon/validations/index.d.ts +1 -0
- package/dist/types/modules/coupon/validations/index.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts +29 -72
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +36 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +22 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +78 -78
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +1 -2
- 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.service.d.ts +16 -51
- 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/config/limited-time-offer-config.builder.d.ts +8 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.builder.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.repository.d.ts +14 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.repository.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts +1 -2
- package/dist/types/modules/limited-time-offer/config/limited-time-offer-config.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/config/limited-time-offer.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +35 -78
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +53 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +18 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -0
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +6 -6
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +24 -24
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +3 -1
- 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 +19 -8
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/routers/marketing.router.d.ts +12 -3
- package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/marketing.service.d.ts +1 -0
- package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts +11 -0
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/marketing.validation.d.ts +2 -2
- package/dist/types/modules/marketing/validations/product-marketing.validation.d.ts +2 -2
- package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +2 -2
- package/dist/types/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +4 -4
- package/package.json +2 -2
- package/dist/types/events/event-initializations.d.ts +0 -2
- package/dist/types/events/event-initializations.d.ts.map +0 -1
|
@@ -1,18 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DocumentType, mongoose } from '@typegoose/typegoose';
|
|
2
2
|
import { JoinLtoCampaignDTO, ParticipantStatusDTO } from '../limited-time-offer-participant.validation';
|
|
3
|
-
import {
|
|
3
|
+
import { GetLtoCampaignParticipantsDTO } from '../../campaign/limited-time-offer-campaign.validation';
|
|
4
4
|
export declare class LimitedTimeOfferParticipantService {
|
|
5
|
-
private
|
|
5
|
+
private repository;
|
|
6
6
|
private campaignService;
|
|
7
7
|
private marketingService;
|
|
8
8
|
constructor();
|
|
9
|
-
join(shopId: mongoose.Types.ObjectId, dto: JoinLtoCampaignDTO): Promise<
|
|
10
|
-
_id: mongoose.Types.ObjectId;
|
|
11
|
-
} & {
|
|
12
|
-
__v: number;
|
|
13
|
-
}>;
|
|
9
|
+
join(shopId: mongoose.Types.ObjectId, dto: JoinLtoCampaignDTO): Promise<DocumentType<import("@lyxa.ai/core/dist/libraries/mongo/models").LimitedTimeOfferParticipant>>;
|
|
14
10
|
withdraw(shopId: mongoose.Types.ObjectId): Promise<void>;
|
|
15
11
|
getStatus(shopId: mongoose.Types.ObjectId): Promise<ParticipantStatusDTO>;
|
|
12
|
+
getParticipants(dto: GetLtoCampaignParticipantsDTO): Promise<{
|
|
13
|
+
documents: {
|
|
14
|
+
joinedAt: Date;
|
|
15
|
+
shopName: string | null;
|
|
16
|
+
shopPhoto?: string | null | undefined;
|
|
17
|
+
discountPercentage?: number | undefined;
|
|
18
|
+
maxDiscountCap?: number | undefined;
|
|
19
|
+
}[];
|
|
20
|
+
metadata: {
|
|
21
|
+
page: number;
|
|
22
|
+
size: number;
|
|
23
|
+
totalElements: number;
|
|
24
|
+
totalPages: number;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
16
27
|
private fetchActiveCampaignOrThrow;
|
|
17
28
|
private assertNotAlreadyJoined;
|
|
18
29
|
private validateDiscountSelections;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-participant.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/participant/services/limited-time-offer-participant.service.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"limited-time-offer-participant.service.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/participant/services/limited-time-offer-participant.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAM5D,OAAO,EAAC,kBAAkB,EAAgB,oBAAoB,EAAC,MAAM,8CAA8C,CAAC;AAGpH,OAAO,EAAC,6BAA6B,EAAC,MAAM,uDAAuD,CAAC;AAEpG,qBACa,kCAAkC;IAC3C,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,eAAe,CAAqB;IAC5C,OAAO,CAAC,gBAAgB,CAAiC;;IAQ5C,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,EAAE,kBAAkB;IAa7D,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAaxD,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgBzE,eAAe,CAAC,GAAG,EAAE,6BAA6B;;;;;;;;;;;;;;;YAQjD,0BAA0B;YAQ1B,sBAAsB;IAMpC,OAAO,CAAC,0BAA0B;CAQrC;AAED,eAAO,MAAM,qBAAqB,oCAAoD,CAAC"}
|
|
@@ -44,18 +44,19 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
45
|
exports.ltoParticipantService = exports.LimitedTimeOfferParticipantService = void 0;
|
|
46
46
|
const typedi_1 = __importStar(require("typedi"));
|
|
47
|
-
const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models");
|
|
48
47
|
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
49
48
|
const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
|
|
50
49
|
const limited_time_offer_campaign_service_1 = require("../../../limited-time-offer/campaign/services/limited-time-offer-campaign.service");
|
|
51
50
|
const limited_time_offer_participant_marketing_service_1 = require("./limited-time-offer-participant-marketing.service");
|
|
52
51
|
const limited_time_offer_participant_validation_1 = require("../limited-time-offer-participant.validation");
|
|
52
|
+
const limited_time_offer_participant_builder_1 = require("../limited-time-offer-participant.builder");
|
|
53
|
+
const limited_time_offer_participant_repository_1 = require("../limited-time-offer-participant.repository");
|
|
53
54
|
let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantService {
|
|
54
|
-
|
|
55
|
+
repository;
|
|
55
56
|
campaignService;
|
|
56
57
|
marketingService;
|
|
57
58
|
constructor() {
|
|
58
|
-
this.
|
|
59
|
+
this.repository = typedi_1.default.get(limited_time_offer_participant_repository_1.LtoParticipantRepository);
|
|
59
60
|
this.campaignService = typedi_1.default.get(limited_time_offer_campaign_service_1.LtoCampaignService);
|
|
60
61
|
this.marketingService = typedi_1.default.get(limited_time_offer_participant_marketing_service_1.LtoParticipantMarketingService);
|
|
61
62
|
}
|
|
@@ -64,24 +65,11 @@ let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantServic
|
|
|
64
65
|
await this.assertNotAlreadyJoined(campaign._id, shopId);
|
|
65
66
|
this.validateDiscountSelections(campaign, dto.discountPercentage, dto.maxDiscountCap);
|
|
66
67
|
const marketingId = await this.marketingService.applyMarketing(shopId, campaign, dto);
|
|
67
|
-
|
|
68
|
-
campaign: campaign._id,
|
|
69
|
-
shop: shopId,
|
|
70
|
-
marketing: marketingId,
|
|
71
|
-
joinedAt: new Date(),
|
|
72
|
-
products: dto.products ?? [],
|
|
73
|
-
isEntireMenu: dto.isEntireMenu,
|
|
74
|
-
discountPercentage: dto.discountPercentage,
|
|
75
|
-
maxDiscountCap: dto.maxDiscountCap,
|
|
76
|
-
isOrderCapacityEnabled: dto.isOrderCapacityEnabled,
|
|
77
|
-
maxOrderCapacity: dto.maxOrderCapacity,
|
|
78
|
-
isWithdrawn: false,
|
|
79
|
-
});
|
|
80
|
-
return participant.toObject();
|
|
68
|
+
return this.repository.create(limited_time_offer_participant_builder_1.LtoParticipantQueryBuilder.buildCreateInput(campaign._id, shopId, marketingId, dto));
|
|
81
69
|
}
|
|
82
70
|
async withdraw(shopId) {
|
|
83
71
|
const campaign = await this.fetchActiveCampaignOrThrow();
|
|
84
|
-
const participant = await this.
|
|
72
|
+
const participant = await this.repository.withdraw(campaign._id, shopId);
|
|
85
73
|
if (!participant)
|
|
86
74
|
throw (0, error_common_1.notFoundError)('You have not joined this campaign.');
|
|
87
75
|
if (participant.marketing) {
|
|
@@ -93,15 +81,19 @@ let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantServic
|
|
|
93
81
|
if (!campaign)
|
|
94
82
|
return { campaignState: limited_time_offer_participant_validation_1.LtoCardState.NONE };
|
|
95
83
|
if (campaign.status === enum_1.LimitedTimeOfferCampaignStatus.SCHEDULED) {
|
|
96
|
-
return { campaignState: limited_time_offer_participant_validation_1.LtoCardState.SCHEDULED, campaign };
|
|
84
|
+
return { campaignState: limited_time_offer_participant_validation_1.LtoCardState.SCHEDULED, campaign: campaign };
|
|
97
85
|
}
|
|
98
|
-
const participant = await this.
|
|
99
|
-
.findOne({ campaign: campaign._id, shop: shopId, isWithdrawn: false })
|
|
100
|
-
.select('discountPercentage maxDiscountCap joinedAt isEntireMenu isOrderCapacityEnabled maxOrderCapacity')
|
|
101
|
-
.lean();
|
|
86
|
+
const participant = await this.repository.findActiveByCampaignAndShop(campaign._id, shopId);
|
|
102
87
|
return participant
|
|
103
|
-
? { campaignState: limited_time_offer_participant_validation_1.LtoCardState.JOINED, campaign, participant }
|
|
104
|
-
: { campaignState: limited_time_offer_participant_validation_1.LtoCardState.LIVE, campaign };
|
|
88
|
+
? { campaignState: limited_time_offer_participant_validation_1.LtoCardState.JOINED, campaign: campaign, participant }
|
|
89
|
+
: { campaignState: limited_time_offer_participant_validation_1.LtoCardState.LIVE, campaign: campaign };
|
|
90
|
+
}
|
|
91
|
+
async getParticipants(dto) {
|
|
92
|
+
const { documents, total } = await this.repository.findByCampaign(dto);
|
|
93
|
+
return {
|
|
94
|
+
documents,
|
|
95
|
+
metadata: { page: dto.page, size: dto.size, totalElements: total, totalPages: Math.ceil(total / dto.size) },
|
|
96
|
+
};
|
|
105
97
|
}
|
|
106
98
|
async fetchActiveCampaignOrThrow() {
|
|
107
99
|
const campaign = await this.campaignService.getCurrent();
|
|
@@ -111,9 +103,9 @@ let LimitedTimeOfferParticipantService = class LimitedTimeOfferParticipantServic
|
|
|
111
103
|
return campaign;
|
|
112
104
|
}
|
|
113
105
|
async assertNotAlreadyJoined(campaignId, shopId) {
|
|
114
|
-
|
|
115
|
-
if (exists)
|
|
106
|
+
if (await this.repository.existsActiveByCampaignAndShop(campaignId, shopId)) {
|
|
116
107
|
throw (0, error_common_1.conflictError)('Your shop has already joined this campaign.');
|
|
108
|
+
}
|
|
117
109
|
}
|
|
118
110
|
validateDiscountSelections(campaign, discountPercentage, maxDiscountCap) {
|
|
119
111
|
if (!campaign.discountOptions.includes(discountPercentage)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-participant.service.js","sourceRoot":"/","sources":["modules/limited-time-offer/participant/services/limited-time-offer-participant.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;
|
|
1
|
+
{"version":3,"file":"limited-time-offer-participant.service.js","sourceRoot":"/","sources":["modules/limited-time-offer/participant/services/limited-time-offer-participant.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAG1C,4DAAiF;AACjF,4EAAwG;AACxG,2IAAqH;AACrH,yHAAkG;AAClG,4GAAoH;AACpH,sGAAqF;AACrF,4GAAsF;AAI/E,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IACnC,UAAU,CAA2B;IACrC,eAAe,CAAqB;IACpC,gBAAgB,CAAiC;IAEzD;QACI,IAAI,CAAC,UAAU,GAAG,gBAAS,CAAC,GAAG,CAAC,oEAAwB,CAAC,CAAC;QAC1D,IAAI,CAAC,eAAe,GAAG,gBAAS,CAAC,GAAG,CAAC,wDAAkB,CAAC,CAAC;QACzD,IAAI,CAAC,gBAAgB,GAAG,gBAAS,CAAC,GAAG,CAAC,iFAA8B,CAAC,CAAC;IAC1E,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,MAA+B,EAAE,GAAuB;QACtE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAEzD,MAAM,IAAI,CAAC,sBAAsB,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACxD,IAAI,CAAC,0BAA0B,CAAC,QAAQ,EAAE,GAAG,CAAC,kBAAkB,EAAE,GAAG,CAAC,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AAE,CAAC;YACzD,MAAM,IAAA,8BAAe,EAAC,iEAAiE,CAAC,CAAC;QAC7F,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YACrD,MAAM,IAAA,8BAAe,EAAC,yEAAyE,CAAC,CAAC;QACrG,CAAC;IACL,CAAC;CACJ,CAAA;AAnFY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,gBAAO,GAAE;;GACG,kCAAkC,CAmF9C;AAEY,QAAA,qBAAqB,GAAG,gBAAS,CAAC,GAAG,CAAC,kCAAkC,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 {badRequestError, conflictError, notFoundError} from '@lyxa.ai/core/dist/utilities/error-common';\nimport {LtoCampaignService} from '@modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service';\nimport {LtoParticipantMarketingService} from './limited-time-offer-participant-marketing.service';\nimport {JoinLtoCampaignDTO, LtoCardState, ParticipantStatusDTO} from '../limited-time-offer-participant.validation';\nimport {LtoParticipantQueryBuilder} from '../limited-time-offer-participant.builder';\nimport {LtoParticipantRepository} from '../limited-time-offer-participant.repository';\nimport {GetLtoCampaignParticipantsDTO} from '../../campaign/limited-time-offer-campaign.validation';\n\n@Service()\nexport class LimitedTimeOfferParticipantService {\n private repository: LtoParticipantRepository;\n private campaignService: LtoCampaignService;\n private marketingService: LtoParticipantMarketingService;\n\n constructor() {\n this.repository = Container.get(LtoParticipantRepository);\n this.campaignService = Container.get(LtoCampaignService);\n this.marketingService = Container.get(LtoParticipantMarketingService);\n }\n\n public async join(shopId: mongoose.Types.ObjectId, dto: JoinLtoCampaignDTO) {\n const campaign = await this.fetchActiveCampaignOrThrow();\n\n await this.assertNotAlreadyJoined(campaign._id, shopId);\n this.validateDiscountSelections(campaign, dto.discountPercentage, dto.maxDiscountCap);\n\n const marketingId = await this.marketingService.applyMarketing(shopId, campaign, dto);\n\n return this.repository.create(\n LtoParticipantQueryBuilder.buildCreateInput(campaign._id, shopId, marketingId, dto),\n );\n }\n\n public async withdraw(shopId: mongoose.Types.ObjectId): Promise<void> {\n const campaign = await this.fetchActiveCampaignOrThrow();\n\n const participant = await this.repository.withdraw(campaign._id, shopId);\n if (!participant) throw notFoundError('You have not joined this campaign.');\n\n if (participant.marketing) {\n await this.marketingService.removeMarketing(\n participant.marketing as mongoose.Types.ObjectId,\n );\n }\n }\n\n public async getStatus(shopId: mongoose.Types.ObjectId): Promise<ParticipantStatusDTO> {\n const campaign = await this.campaignService.getCurrent();\n\n if (!campaign) return {campaignState: LtoCardState.NONE};\n\n if (campaign.status === LimitedTimeOfferCampaignStatus.SCHEDULED) {\n return {campaignState: LtoCardState.SCHEDULED, campaign: campaign as any};\n }\n\n const participant = await this.repository.findActiveByCampaignAndShop(campaign._id, shopId);\n\n return participant\n ? {campaignState: LtoCardState.JOINED, campaign: campaign as any, participant}\n : {campaignState: LtoCardState.LIVE, campaign: campaign as any};\n }\n\n public async getParticipants(dto: GetLtoCampaignParticipantsDTO) {\n const {documents, total} = await this.repository.findByCampaign(dto);\n return {\n documents,\n metadata: {page: dto.page, size: dto.size, totalElements: total, totalPages: Math.ceil(total / dto.size)},\n };\n }\n\n private async fetchActiveCampaignOrThrow(): Promise<DocumentType<LimitedTimeOfferCampaign>> {\n const campaign = await this.campaignService.getCurrent();\n if (!campaign || campaign.status !== LimitedTimeOfferCampaignStatus.ACTIVE) {\n throw badRequestError('No active campaign is currently running.');\n }\n return campaign;\n }\n\n private async assertNotAlreadyJoined(campaignId: mongoose.Types.ObjectId, shopId: mongoose.Types.ObjectId): Promise<void> {\n if (await this.repository.existsActiveByCampaignAndShop(campaignId, shopId)) {\n throw conflictError('Your shop has already joined this campaign.');\n }\n }\n\n private validateDiscountSelections(campaign: DocumentType<LimitedTimeOfferCampaign>, discountPercentage: number, maxDiscountCap: number): void {\n if (!campaign.discountOptions.includes(discountPercentage)) {\n throw badRequestError('Selected discount is not an available option for this campaign.');\n }\n if (!campaign.maxDiscountCaps.includes(maxDiscountCap)) {\n throw badRequestError('Selected max discount cap is not an available option for this campaign.');\n }\n }\n}\n\nexport const ltoParticipantService = Container.get(LimitedTimeOfferParticipantService);\n"]}
|
|
@@ -173,8 +173,8 @@ export declare const marketingRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
173
173
|
getOrdersGraph: import("@trpc/server").TRPCQueryProcedure<{
|
|
174
174
|
input: {
|
|
175
175
|
startDate: string | Date;
|
|
176
|
-
marketingId: string | mongoose.Types.ObjectId;
|
|
177
176
|
endDate: string | Date;
|
|
177
|
+
marketingId: string | mongoose.Types.ObjectId;
|
|
178
178
|
type?: import("@lyxa.ai/core/dist/utilities/enum").GraphType | undefined;
|
|
179
179
|
};
|
|
180
180
|
output: {
|
|
@@ -190,8 +190,8 @@ export declare const marketingRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
190
190
|
getCustomersGraph: import("@trpc/server").TRPCQueryProcedure<{
|
|
191
191
|
input: {
|
|
192
192
|
startDate: string | Date;
|
|
193
|
-
marketingId: string | mongoose.Types.ObjectId;
|
|
194
193
|
endDate: string | Date;
|
|
194
|
+
marketingId: string | mongoose.Types.ObjectId;
|
|
195
195
|
type?: import("@lyxa.ai/core/dist/utilities/enum").GraphType | undefined;
|
|
196
196
|
};
|
|
197
197
|
output: {
|
|
@@ -207,8 +207,8 @@ export declare const marketingRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
207
207
|
getAmountSpentGraph: import("@trpc/server").TRPCQueryProcedure<{
|
|
208
208
|
input: {
|
|
209
209
|
startDate: string | Date;
|
|
210
|
-
marketingId: string | mongoose.Types.ObjectId;
|
|
211
210
|
endDate: string | Date;
|
|
211
|
+
marketingId: string | mongoose.Types.ObjectId;
|
|
212
212
|
type?: import("@lyxa.ai/core/dist/utilities/enum").GraphType | undefined;
|
|
213
213
|
};
|
|
214
214
|
output: {
|
|
@@ -221,5 +221,14 @@ export declare const marketingRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
221
221
|
};
|
|
222
222
|
meta: object;
|
|
223
223
|
}>;
|
|
224
|
+
reseedEntireMenuMarketing: import("@trpc/server").TRPCMutationProcedure<{
|
|
225
|
+
input: string | mongoose.Types.ObjectId;
|
|
226
|
+
output: {
|
|
227
|
+
message: string;
|
|
228
|
+
success: boolean;
|
|
229
|
+
data?: any;
|
|
230
|
+
};
|
|
231
|
+
meta: object;
|
|
232
|
+
}>;
|
|
224
233
|
}>>;
|
|
225
234
|
//# sourceMappingURL=marketing.router.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.router.d.ts","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAOmB,CAAC
|
|
1
|
+
{"version":3,"file":"marketing.router.d.ts","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAOmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiJ9C,CAAC"}
|
|
@@ -99,5 +99,12 @@ exports.marketingRouter = (0, trpc_1.createTRPCRouter)({
|
|
|
99
99
|
const result = await MarketingMetricsRepository_1.marketingMetricsRepository.getAmountSpentGraph(input);
|
|
100
100
|
return (0, response_1.response)('Marketing amount spent graph data fetched successfully', result);
|
|
101
101
|
})),
|
|
102
|
+
reseedEntireMenuMarketing: (0, auth_1.createAuthenticatedProcedure)({ entityTypes: [auth_2.AuthEntityType.CRM] })
|
|
103
|
+
.input(validation_1.IdSchema)
|
|
104
|
+
.output(validations_1.MarketingResponseSchema)
|
|
105
|
+
.mutation(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
106
|
+
await services_1.marketingService.reseedEntireMenuMarketing(new typegoose_1.mongoose.Types.ObjectId(input));
|
|
107
|
+
return (0, response_1.response)('Entire menu marketing reseed dispatched successfully');
|
|
108
|
+
})),
|
|
102
109
|
});
|
|
103
110
|
//# sourceMappingURL=marketing.router.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.router.js","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":";;;AAAA,4DAAsF;AACtF,6EAAkG;AAClG,0DAA0E;AAC1E,0DAAoH;AACpH,gEAQwC;AACxC,oEAAiE;AACjE,wEAKiD;AACjD,8EAA0E;AAC1E,4DAAmE;AACnE,oDAAgD;AAChD,kGAA+F;AAElF,QAAA,eAAe,GAAG,IAAA,uBAAgB,EAAC;IAC/C,MAAM,EAAE,IAAA,mCAA4B,EAAC,EAAE,WAAW,EAAE,CAAC,qBAAc,CAAC,GAAG,EAAE,qBAAc,CAAC,MAAM,CAAC,EAAE,CAAC;SAChG,KAAK,CAAC,2CAA6B,CAAC;SACpC,MAAM,CAAC,qCAAc,CAAC;SACtB,QAAQ,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAClC,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,OAAO,GAAG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AI,EAAE;QACjC,MAAM,MAAM,GAAG,MAAM,uDAA0B,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC3E,OAAO,IAAA,mBAAQ,EAAC,wDAAwD,EAAE,MAAM,CAAC,CAAC;IACnF,CAAC,CAAC,CACF;CACD,CAAC,CAAC","sourcesContent":["import { createTRPCRouter, publicProcedure } from '@lyxa.ai/core/dist/libraries/trpc';\nimport { createAuthenticatedProcedure } from '@lyxa.ai/core/dist/libraries/trpc/middlewares/auth';\nimport { marketingService as service } from '@modules/marketing/services';\nimport { synchronizeProductMarketingService as syncMarketingProductInfoService } from '@modules/marketing/services';\nimport {\n\tAllMarketingsValidationSchema,\n\tMarketingResponseSchema as ResponseSchema,\n\tAllMarketingsUpdateSchema,\n\tProductEntireMenuMarketingHandlerSchema,\n\tMarketingSpendLimitsEvaluationSchema,\n\tSyncProductMarketingForMultipleProductsSchema,\n\tMarketingGraphInputSchema,\n} from '@modules/marketing/validations';\nimport { response } from '@lyxa.ai/core/dist/utilities/response';\nimport {\n\tFilterSchema,\n\tDeleteSchema,\n\tGetByIdInputSchema,\n\tIdSchema,\n} from '@lyxa.ai/core/dist/utilities/validation';\nimport { ErrorHandler } from '@lyxa.ai/core/dist/utilities/error-handler';\nimport { AuthEntityType } from '@lyxa.ai/core/dist/libraries/auth';\nimport { mongoose } from '@typegoose/typegoose';\nimport { marketingMetricsRepository } from '../patterns/repository/MarketingMetricsRepository';\n\nexport const marketingRouter = createTRPCRouter({\n\tcreate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsValidationSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.create(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing created successfully');\n\t\t\t})\n\t\t),\n\n\tgetById: publicProcedure.input(GetByIdInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.findById(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tget: publicProcedure.input(FilterSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.find(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tupdate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsUpdateSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst { _id, ...rest } = input;\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\n\t\t\t\tawait service.update(_id, rest, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing updated successfully');\n\t\t\t})\n\t\t),\n\n\tdeleteById: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(DeleteSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.deleteById(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing deleted successfully');\n\t\t\t})\n\t\t),\n\n\thandleNewProductForEntireMenuMarketing: publicProcedure\n\t\t.input(ProductEntireMenuMarketingHandlerSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tawait service.handleNewProductForEntireMenuMarketing(input);\n\t\t\t\treturn response('Product handled successfully');\n\t\t\t})\n\t\t),\n\n\tsyncAllProductsMarketingInfo: publicProcedure.query(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\treturn await syncMarketingProductInfoService.publishAllProductsProductMarketingInfoProcessEvent();\n\t\t})\n\t),\n\n\tsyncAllProductsMarketingInfoLocal: publicProcedure.mutation(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\treturn await syncMarketingProductInfoService.syncAllProductsMarketingInfo();\n\t\t})\n\t),\n\n\t// DEV purpose only\n\tsyncProductMarketingInfoByProductId: publicProcedure.query(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst productId = new mongoose.Types.ObjectId('68f663c355f42c826a129fc6'); // Todo: use productId sent from param\n\t\t\treturn await syncMarketingProductInfoService.syncProductMarketingInfoByProductId(productId);\n\t\t})\n\t),\n\n\tsyncProductMarketingInfoByProductIds: publicProcedure\n\t\t.input(SyncProductMarketingForMultipleProductsSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\treturn await syncMarketingProductInfoService.syncProductMarketingInfoByProductIds(input.productIds);\n\t\t\t})\n\t\t),\n\n\tcalculateMarketingSpent: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.calculateMarketingSpent(input);\n\t\t\treturn response('Marketing amount spent calculated successfully', result);\n\t\t})\n\t),\n\n\tincrementMarketingSpentFromOrder: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.incrementMarketingSpentFromOrder(input);\n\t\t\treturn response('Marketing amount spent incremented successfully', result);\n\t\t})\n\t),\n\n\tdecrementMarketingSpentFromOrder: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.decrementMarketingSpentFromOrder(input);\n\t\t\treturn response('Marketing amount spent decremented successfully', result);\n\t\t})\n\t),\n\n\trecomputeAndSyncAllMarketingSpent: publicProcedure.mutation(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.recomputeAndSyncAllMarketingSpent();\n\t\t\treturn response('Marketing amount spent recomputed and synced successfully', result);\n\t\t})\n\t),\n\n\tgetMetrics: publicProcedure.input(IdSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getMetrics(input);\n\t\t\treturn response('Marketing metrics fetched successfully', result);\n\t\t})\n\t),\n\n\tgetOrdersGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getOrdersGraph(input);\n\t\t\treturn response('Marketing orders graph data fetched successfully', result);\n\t\t})\n\t),\n\n\tgetCustomersGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getCustomersGraph(input);\n\t\t\treturn response('Marketing customers graph data fetched successfully', result);\n\t\t})\n\t),\n\n\tgetAmountSpentGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getAmountSpentGraph(input);\n\t\t\treturn response('Marketing amount spent graph data fetched successfully', result);\n\t\t})\n\t),\n});\n"]}
|
|
1
|
+
{"version":3,"file":"marketing.router.js","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":";;;AAAA,4DAAsF;AACtF,6EAAkG;AAClG,0DAA0E;AAC1E,0DAAoH;AACpH,gEAQwC;AACxC,oEAAiE;AACjE,wEAKiD;AACjD,8EAA0E;AAC1E,4DAAmE;AACnE,oDAAgD;AAChD,kGAA+F;AAElF,QAAA,eAAe,GAAG,IAAA,uBAAgB,EAA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,IAAI,EAAE;QACjC,MAAM,MAAM,GAAG,MAAM,uDAA0B,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;QACzE,OAAO,IAAA,mBAAQ,EAAC,qDAAqD,EAAE,MAAM,CAAC,CAAC;IAChF,CAAC,CAAC,CACF;IAED,mBAAmB,EAAE,sBAAe,CAAC,KAAK,CAAC,uCAAyB,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAC/F,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,MAAM,GAAG,MAAM,uDAA0B,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAC3E,OAAO,IAAA,mBAAQ,EAAC,wDAAwD,EAAE,MAAM,CAAC,CAAC;IACnF,CAAC,CAAC,CACF;IAED,yBAAyB,EAAE,IAAA,mCAA4B,EAAC,EAAE,WAAW,EAAE,CAAC,qBAAc,CAAC,GAAG,CAAC,EAAE,CAAC;SAC5F,KAAK,CAAC,qBAAQ,CAAC;SACf,MAAM,CAAC,qCAAc,CAAC;SACtB,QAAQ,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAC7B,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,2BAAO,CAAC,yBAAyB,CAAC,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;QAC5E,OAAO,IAAA,mBAAQ,EAAC,sDAAsD,CAAC,CAAC;IACzE,CAAC,CAAC,CACF;CACF,CAAC,CAAC","sourcesContent":["import { createTRPCRouter, publicProcedure } from '@lyxa.ai/core/dist/libraries/trpc';\nimport { createAuthenticatedProcedure } from '@lyxa.ai/core/dist/libraries/trpc/middlewares/auth';\nimport { marketingService as service } from '@modules/marketing/services';\nimport { synchronizeProductMarketingService as syncMarketingProductInfoService } from '@modules/marketing/services';\nimport {\n\tAllMarketingsValidationSchema,\n\tMarketingResponseSchema as ResponseSchema,\n\tAllMarketingsUpdateSchema,\n\tProductEntireMenuMarketingHandlerSchema,\n\tMarketingSpendLimitsEvaluationSchema,\n\tSyncProductMarketingForMultipleProductsSchema,\n\tMarketingGraphInputSchema,\n} from '@modules/marketing/validations';\nimport { response } from '@lyxa.ai/core/dist/utilities/response';\nimport {\n\tFilterSchema,\n\tDeleteSchema,\n\tGetByIdInputSchema,\n\tIdSchema,\n} from '@lyxa.ai/core/dist/utilities/validation';\nimport { ErrorHandler } from '@lyxa.ai/core/dist/utilities/error-handler';\nimport { AuthEntityType } from '@lyxa.ai/core/dist/libraries/auth';\nimport { mongoose } from '@typegoose/typegoose';\nimport { marketingMetricsRepository } from '../patterns/repository/MarketingMetricsRepository';\n\nexport const marketingRouter = createTRPCRouter({\n\tcreate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsValidationSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.create(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing created successfully');\n\t\t\t})\n\t\t),\n\n\tgetById: publicProcedure.input(GetByIdInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.findById(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tget: publicProcedure.input(FilterSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.find(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tupdate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsUpdateSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst { _id, ...rest } = input;\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\n\t\t\t\tawait service.update(_id, rest, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing updated successfully');\n\t\t\t})\n\t\t),\n\n\tdeleteById: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(DeleteSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.deleteById(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing deleted successfully');\n\t\t\t})\n\t\t),\n\n\thandleNewProductForEntireMenuMarketing: publicProcedure\n\t\t.input(ProductEntireMenuMarketingHandlerSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tawait service.handleNewProductForEntireMenuMarketing(input);\n\t\t\t\treturn response('Product handled successfully');\n\t\t\t})\n\t\t),\n\n\tsyncAllProductsMarketingInfo: publicProcedure.query(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\treturn await syncMarketingProductInfoService.publishAllProductsProductMarketingInfoProcessEvent();\n\t\t})\n\t),\n\n\tsyncAllProductsMarketingInfoLocal: publicProcedure.mutation(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\treturn await syncMarketingProductInfoService.syncAllProductsMarketingInfo();\n\t\t})\n\t),\n\n\t// DEV purpose only\n\tsyncProductMarketingInfoByProductId: publicProcedure.query(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst productId = new mongoose.Types.ObjectId('68f663c355f42c826a129fc6'); // Todo: use productId sent from param\n\t\t\treturn await syncMarketingProductInfoService.syncProductMarketingInfoByProductId(productId);\n\t\t})\n\t),\n\n\tsyncProductMarketingInfoByProductIds: publicProcedure\n\t\t.input(SyncProductMarketingForMultipleProductsSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\treturn await syncMarketingProductInfoService.syncProductMarketingInfoByProductIds(input.productIds);\n\t\t\t})\n\t\t),\n\n\tcalculateMarketingSpent: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.calculateMarketingSpent(input);\n\t\t\treturn response('Marketing amount spent calculated successfully', result);\n\t\t})\n\t),\n\n\tincrementMarketingSpentFromOrder: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.incrementMarketingSpentFromOrder(input);\n\t\t\treturn response('Marketing amount spent incremented successfully', result);\n\t\t})\n\t),\n\n\tdecrementMarketingSpentFromOrder: publicProcedure.input(IdSchema).mutation(async ({ ctx, input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.decrementMarketingSpentFromOrder(input);\n\t\t\treturn response('Marketing amount spent decremented successfully', result);\n\t\t})\n\t),\n\n\trecomputeAndSyncAllMarketingSpent: publicProcedure.mutation(async ({}) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.recomputeAndSyncAllMarketingSpent();\n\t\t\treturn response('Marketing amount spent recomputed and synced successfully', result);\n\t\t})\n\t),\n\n\tgetMetrics: publicProcedure.input(IdSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getMetrics(input);\n\t\t\treturn response('Marketing metrics fetched successfully', result);\n\t\t})\n\t),\n\n\tgetOrdersGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getOrdersGraph(input);\n\t\t\treturn response('Marketing orders graph data fetched successfully', result);\n\t\t})\n\t),\n\n\tgetCustomersGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getCustomersGraph(input);\n\t\t\treturn response('Marketing customers graph data fetched successfully', result);\n\t\t})\n\t),\n\n\tgetAmountSpentGraph: publicProcedure.input(MarketingGraphInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await marketingMetricsRepository.getAmountSpentGraph(input);\n\t\t\treturn response('Marketing amount spent graph data fetched successfully', result);\n\t\t})\n\t),\n\n\treseedEntireMenuMarketing: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM] })\n\t\t.input(IdSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tawait service.reseedEntireMenuMarketing(new mongoose.Types.ObjectId(input));\n\t\t\t\treturn response('Entire menu marketing reseed dispatched successfully');\n\t\t\t})\n\t\t),\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buy1-get1-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAIxC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"buy1-get1-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAIxC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA2BrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;CA8ChG;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
|
|
@@ -59,15 +59,17 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
|
|
|
59
59
|
if (!result) {
|
|
60
60
|
(0, error_common_1.internalServerError)('Unable to create marketing');
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
if (!data.isEntireMenu) {
|
|
63
|
+
await _1.productMarketingService.createProductMarketings({
|
|
64
|
+
shop: result.shop._id,
|
|
65
|
+
marketingId: result._id,
|
|
66
|
+
isEntireMenu: data.isEntireMenu,
|
|
67
|
+
isAppliedByCompany: data.isAppliedByCompany,
|
|
68
|
+
categories: data.categories,
|
|
69
|
+
products: data.products,
|
|
70
|
+
isBuy1Get1: true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
71
73
|
return result;
|
|
72
74
|
}
|
|
73
75
|
async update(_id, data) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buy1-get1-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,uEAIoD;AAKpD,yBAA6C;AAC7C,4EAA+F;AAGxF,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,KAAK,CAAgC;IACrC,YAAY,CAAsB;IAE1C;QACC,IAAI,CAAC,KAAK,GAAG,+BAAsB,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,qBAAY,CAAC;IAClC,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAE7C,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,IAAA,kCAAmB,EAAC,4BAA4B,CAAC,CAAC;QACnD,CAAC;QAED,MAAM,0BAAuB,CAAC,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"buy1-get1-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,uEAIoD;AAKpD,yBAA6C;AAC7C,4EAA+F;AAGxF,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,KAAK,CAAgC;IACrC,YAAY,CAAsB;IAE1C;QACC,IAAI,CAAC,KAAK,GAAG,+BAAsB,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,qBAAY,CAAC;IAClC,CAAC;IAMM,KAAK,CAAC,MAAM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I,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;YAC/C,IAAI,CAAC,YAAY,EAChB,CAAC;YACF,MAAM,0BAAuB,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;QACpE,CAAC;QAED,MAAM,0BAAuB,CAAC,uBAAuB,CAAC;YACrD,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG;YACrB,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;YAC3C,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI;SAChB,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM;YAAE,IAAA,4BAAa,EAAC,kBAAkB,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC;IACf,CAAC;CACD,CAAA;AAtFY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAsFpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tBuy1Get1MarketingModel,\n\tBuy1Get1Marketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateBuy1Get1MarketingDTO as CreateDTO,\n\tUpdateBuy1Get1MarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { internalServerError, notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class Buy1Get1MarketingService {\n\tprivate model: typeof Buy1Get1MarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = Buy1Get1MarketingModel;\n\t\tthis.productModel = ProductModel;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\n\t\tif (!result) {\n\t\t\tinternalServerError('Unable to create marketing');\n\t\t}\n\n\t\tif (!data.isEntireMenu) {\n\t\t\tawait productMarketingService.createProductMarketings({\n\t\t\t\tshop: result.shop._id,\n\t\t\t\tmarketingId: result._id,\n\t\t\t\tisEntireMenu: data.isEntireMenu,\n\t\t\t\tisAppliedByCompany: data.isAppliedByCompany,\n\t\t\t\tcategories: data.categories,\n\t\t\t\tproducts: data.products,\n\t\t\t\tisBuy1Get1: true,\n\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update record\n\t * @param _id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { products, ...rest } = data;\n\t\tconst record = await this.model\n\t\t\t.findOneAndUpdate(\n\t\t\t\t{\n\t\t\t\t\t_id: _id,\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t},\n\t\t\t\trest,\n\t\t\t\t{\n\t\t\t\t\tnew: true,\n\t\t\t\t\trunValidators: true,\n\t\t\t\t}\n\t\t\t)\n\t\t\t.populate({\n\t\t\t\tpath: 'shop',\n\t\t\t\tselect: '_id name shopId',\n\t\t\t});\n\n\t\tif (!record) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\n\t\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\tawait productMarketingService.createProductMarketings({\n\t\t\tshop: record.shop._id,\n\t\t\tmarketingId: _id,\n\t\t\tisEntireMenu: data.isEntireMenu,\n\t\t\tisAppliedByCompany: data.isAppliedByCompany,\n\t\t\tcategories: data.categories,\n\t\t\tproducts: data.products,\n\t\t\tisBuy1Get1: true,\n\t\t});\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n}\n\nexport const buy1Get1MarketingService = Container.get(Buy1Get1MarketingService);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discount-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AASxC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"discount-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AASxC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA2BrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;CAkDhG;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
|
|
@@ -56,19 +56,21 @@ let DiscountMarketingService = class DiscountMarketingService {
|
|
|
56
56
|
}
|
|
57
57
|
async create(data) {
|
|
58
58
|
const result = await this.model.create(data);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
if (!data.isEntireMenu) {
|
|
60
|
+
await _1.productMarketingService.createProductMarketings({
|
|
61
|
+
shop: data.shop,
|
|
62
|
+
marketingId: result._id,
|
|
63
|
+
isEntireMenu: data.isEntireMenu,
|
|
64
|
+
isAppliedByCompany: data.isAppliedByCompany,
|
|
65
|
+
categories: data.categories,
|
|
66
|
+
categoryValue: data.categoryValue,
|
|
67
|
+
categoryValueType: data.categoryValueType,
|
|
68
|
+
products: data.products,
|
|
69
|
+
value: data.value,
|
|
70
|
+
valueType: data.valueType,
|
|
71
|
+
isBuy1Get1: false,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
72
74
|
return result;
|
|
73
75
|
}
|
|
74
76
|
async update(_id, data) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discount-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAE5C,sEAImD;AAKnD,yBAA6C;AAE7C,4EAImD;AAG5C,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,KAAK,CAAgC;IACrC,YAAY,CAAsB;IAE1C;QACC,IAAI,CAAC,KAAK,GAAG,+BAAsB,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,qBAAY,CAAC;IAClC,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAE7C,MAAM,0BAAuB,CAAC,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"discount-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAE5C,sEAImD;AAKnD,yBAA6C;AAE7C,4EAImD;AAG5C,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,KAAK,CAAgC;IACrC,YAAY,CAAsB;IAE1C;QACC,IAAI,CAAC,KAAK,GAAG,+BAAsB,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,qBAAY,CAAC;IAClC,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAE7C,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACxB,MAAM,0BAAuB,CAAC,uBAAuB,CAAC;gBACrD,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,WAAW,EAAE,MAAM,CAAC,GAAG;gBACvB,YAAY,EAAE,IAAI,CAAC,YAAY;gBAC/B,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;gBAC3C,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;gBACjC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;gBACzC,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,SAAS,EAAE,I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a;YACjC,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;YACzC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,UAAU,EAAE,KAAK;SACjB,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM;YAAE,IAAA,4BAAa,EAAC,kBAAkB,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC;IACf,CAAC;CACD,CAAA;AA1FY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CA0FpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tDiscountMarketingModel,\n\tDiscountMarketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tCreateDiscountMarketingDTO as CreateDTO,\n\tUpdateDiscountMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tbadRequestError,\n\tinternalServerError,\n\tnotFoundError,\n} from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class DiscountMarketingService {\n\tprivate model: typeof DiscountMarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = DiscountMarketingModel;\n\t\tthis.productModel = ProductModel;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\n\t\tif (!data.isEntireMenu) {\n\t\t\tawait productMarketingService.createProductMarketings({\n\t\t\t\tshop: data.shop,\n\t\t\t\tmarketingId: result._id,\n\t\t\t\tisEntireMenu: data.isEntireMenu,\n\t\t\t\tisAppliedByCompany: data.isAppliedByCompany,\n\t\t\t\tcategories: data.categories,\n\t\t\t\tcategoryValue: data.categoryValue,\n\t\t\t\tcategoryValueType: data.categoryValueType,\n\t\t\t\tproducts: data.products,\n\t\t\t\tvalue: data.value,\n\t\t\t\tvalueType: data.valueType,\n\t\t\t\tisBuy1Get1: false,\n\t\t\t});\n\t\t}\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update record\n\t * @param _id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { categories, products, ...rest } = data;\n\t\tconst record = await this.model\n\t\t\t.findOneAndUpdate(\n\t\t\t\t{\n\t\t\t\t\t_id: _id,\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t},\n\t\t\t\t{ categories, ...rest },\n\t\t\t\t{\n\t\t\t\t\tnew: true,\n\t\t\t\t\trunValidators: true,\n\t\t\t\t}\n\t\t\t)\n\t\t\t.populate({\n\t\t\t\tpath: 'shop',\n\t\t\t\tselect: '_id name shopId',\n\t\t\t});\n\n\t\tif (!record) {\n\t\t\tinternalServerError('Could not update marketing');\n\t\t}\n\n\t\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\tawait productMarketingService.createProductMarketings({\n\t\t\tshop: record.shop._id,\n\t\t\tmarketingId: record._id,\n\t\t\tisEntireMenu: data.isEntireMenu,\n\t\t\tisAppliedByCompany: data.isAppliedByCompany,\n\t\t\tcategories: data.categories,\n\t\t\tcategoryValue: data.categoryValue,\n\t\t\tcategoryValueType: data.categoryValueType,\n\t\t\tproducts: data.products,\n\t\t\tvalue: data.value,\n\t\t\tvalueType: data.valueType,\n\t\t\tisBuy1Get1: false,\n\t\t});\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n}\n\nexport const discountMarketingService = Container.get(DiscountMarketingService);\n"]}
|
|
@@ -23,6 +23,7 @@ export declare class MarketingService {
|
|
|
23
23
|
private expireMarketingsExceedingSpendLimits;
|
|
24
24
|
private unExpireMarketingsBelowSpendLimits;
|
|
25
25
|
recomputeAndSyncAllMarketingSpent(): Promise<void>;
|
|
26
|
+
reseedEntireMenuMarketing(marketingId: mongoose.Types.ObjectId): Promise<void>;
|
|
26
27
|
}
|
|
27
28
|
export declare const marketingService: MarketingService;
|
|
28
29
|
//# sourceMappingURL=marketing.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAMN,SAAS,IAAI,KAAK,EAMlB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAEN,0BAA0B,EAE1B,oCAAoC,EACpC,kBAAkB,IAAI,SAAS,EAC/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACN,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,eAAe,EACf,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAwC3D,qBACa,gBAAgB;IAC5B,OAAO,CAAC,KAAK,CAAiD;IAC9D,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,UAAU,CAA2D;IAC7E,OAAO,CAAC,0BAA0B,CAA6B;;IAalD,MAAM,CAClB,IAAI,EAAE,0BAA0B,EAChC,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAC7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46,7 @@ exports.marketingService = exports.MarketingService = void 0;
|
|
|
46
46
|
const typedi_1 = __importStar(require("typedi"));
|
|
47
47
|
const server_1 = require("@trpc/server");
|
|
48
48
|
const dayjs_1 = require("@lyxa.ai/core/dist/utilities/dayjs");
|
|
49
|
+
const core_1 = require("@lyxa.ai/core");
|
|
49
50
|
const typegoose_1 = require("@typegoose/typegoose");
|
|
50
51
|
const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models");
|
|
51
52
|
const pagination_1 = require("@lyxa.ai/core/dist/utilities/pagination");
|
|
@@ -53,6 +54,7 @@ const events_common_methods_1 = require("@lyxa.ai/core/dist/utilities/events-com
|
|
|
53
54
|
const admin_logs_event_1 = require("@lyxa.ai/core/dist/libraries/event/events/admin-logs-event");
|
|
54
55
|
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
55
56
|
const event_1 = require("@lyxa.ai/core/dist/libraries/event");
|
|
57
|
+
const marketing_product_seed_event_1 = require("../../../event/events/marketing-product-seed.event");
|
|
56
58
|
const _1 = require(".");
|
|
57
59
|
const enum_2 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
58
60
|
const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
|
|
@@ -151,7 +153,33 @@ let MarketingService = class MarketingService {
|
|
|
151
153
|
marketing = await this.model.create(data, admin);
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
|
-
|
|
156
|
+
if (data.isEntireMenu) {
|
|
157
|
+
const logger = (0, core_1.getLibraries)().getLoggerKit();
|
|
158
|
+
const PAGE_SIZE = 500;
|
|
159
|
+
const marketingId = marketing._id.toString();
|
|
160
|
+
const shopId = data.shop.toString();
|
|
161
|
+
const count = await models_1.ProductModel.countDocuments({ shop: data.shop });
|
|
162
|
+
const pages = Math.ceil(count / PAGE_SIZE);
|
|
163
|
+
if (pages > 0) {
|
|
164
|
+
await Promise.all(Array.from({ length: pages }, (_, page) => (0, event_1.publishEvent)(new marketing_product_seed_event_1.MarketingEntireMenuSeedEvent({
|
|
165
|
+
marketingId,
|
|
166
|
+
shopId,
|
|
167
|
+
isAppliedByCompany: data.isAppliedByCompany ?? false,
|
|
168
|
+
isBuy1Get1: data.marketingType === enum_2.MarketingType.BUY1GET1,
|
|
169
|
+
value: data.value,
|
|
170
|
+
valueType: data.valueType,
|
|
171
|
+
page,
|
|
172
|
+
pageSize: PAGE_SIZE,
|
|
173
|
+
}))));
|
|
174
|
+
logger.debug(`entire-menu marketing seed dispatched — ${pages} pages for ${count} products`, {
|
|
175
|
+
tag: 'marketing.seed.entire-menu',
|
|
176
|
+
data: { marketingId, shopId, pages, productCount: count },
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
await _1.productMarketingService.syncProductMarketingInfo(marketing._id);
|
|
182
|
+
}
|
|
155
183
|
await this.model.populate(marketing, {
|
|
156
184
|
path: 'shop',
|
|
157
185
|
model: this.shopModel,
|
|
@@ -160,7 +188,7 @@ let MarketingService = class MarketingService {
|
|
|
160
188
|
if (admin) {
|
|
161
189
|
this.logMarketingAdminAction(admin, enum_1.AdminLogsUpdatedFieldsType.ACTIVATED_MARKETING_PROMOTIONS, '', marketing);
|
|
162
190
|
}
|
|
163
|
-
if (marketing)
|
|
191
|
+
if (marketing && !data.isEntireMenu)
|
|
164
192
|
(0, events_common_methods_1.publishSyncSingleShopSectionsInCacheProcessEvent)({
|
|
165
193
|
shopId: data.shop,
|
|
166
194
|
operation: mongo_stream_changes_batch_process_shops_event_1.ChangeStreamOperationTypes.UPDATE,
|
|
@@ -448,7 +476,6 @@ let MarketingService = class MarketingService {
|
|
|
448
476
|
}, { $set: { status: enum_1.MarketingStatus.ACTIVE }, $unset: { expiredAt: 1 } });
|
|
449
477
|
}
|
|
450
478
|
async recomputeAndSyncAllMarketingSpent() {
|
|
451
|
-
console.time('Recomputing all marketing spend');
|
|
452
479
|
const cursor = this.model
|
|
453
480
|
.find({ marketingType: { $ne: enum_2.MarketingType.FEATURED } }, { _id: 1 })
|
|
454
481
|
.lean()
|
|
@@ -456,7 +483,6 @@ let MarketingService = class MarketingService {
|
|
|
456
483
|
const bulkOps = [];
|
|
457
484
|
const marketingIds = [];
|
|
458
485
|
for await (const marketing of cursor) {
|
|
459
|
-
console.log(`Recomputing marketing spend for marketing ID: ${marketing._id}`);
|
|
460
486
|
const { amount } = await this.marketingMetricsRepository.calculateMarketingSpent(marketing._id);
|
|
461
487
|
bulkOps.push({
|
|
462
488
|
updateOne: {
|
|
@@ -468,18 +494,42 @@ let MarketingService = class MarketingService {
|
|
|
468
494
|
});
|
|
469
495
|
marketingIds.push(marketing._id);
|
|
470
496
|
if (bulkOps.length >= 500) {
|
|
471
|
-
console.log(`Flushing 500 marketing spend updates...`);
|
|
472
497
|
await this.model.bulkWrite(bulkOps);
|
|
473
498
|
bulkOps.length = 0;
|
|
474
499
|
}
|
|
475
500
|
}
|
|
476
501
|
if (bulkOps.length) {
|
|
477
|
-
console.log(`Flushing remaining ${bulkOps.length} marketing spend updates...`);
|
|
478
502
|
await this.model.bulkWrite(bulkOps);
|
|
479
503
|
}
|
|
480
504
|
await this.expireMarketingsExceedingSpendLimits(marketingIds);
|
|
481
505
|
await this.unExpireMarketingsBelowSpendLimits(marketingIds);
|
|
482
|
-
|
|
506
|
+
}
|
|
507
|
+
async reseedEntireMenuMarketing(marketingId) {
|
|
508
|
+
const logger = (0, core_1.getLibraries)().getLoggerKit();
|
|
509
|
+
const marketing = await this.model.findOne({ _id: marketingId, deletedAt: null });
|
|
510
|
+
if (!marketing)
|
|
511
|
+
(0, error_common_1.internalServerError)('Marketing not found');
|
|
512
|
+
const PAGE_SIZE = 500;
|
|
513
|
+
const mid = marketingId.toString();
|
|
514
|
+
const shopId = marketing.shop.toString();
|
|
515
|
+
const count = await models_1.ProductModel.countDocuments({ shop: marketing.shop });
|
|
516
|
+
const pages = Math.ceil(count / PAGE_SIZE);
|
|
517
|
+
if (!pages)
|
|
518
|
+
return;
|
|
519
|
+
await Promise.all(Array.from({ length: pages }, (_, page) => (0, event_1.publishEvent)(new marketing_product_seed_event_1.MarketingEntireMenuSeedEvent({
|
|
520
|
+
marketingId: mid,
|
|
521
|
+
shopId,
|
|
522
|
+
isAppliedByCompany: marketing.isAppliedByCompany ?? false,
|
|
523
|
+
isBuy1Get1: marketing.marketingType === enum_2.MarketingType.BUY1GET1,
|
|
524
|
+
value: marketing.value,
|
|
525
|
+
valueType: marketing.valueType,
|
|
526
|
+
page,
|
|
527
|
+
pageSize: PAGE_SIZE,
|
|
528
|
+
}))));
|
|
529
|
+
logger.debug(`entire-menu reseed dispatched — ${pages} pages for ${count} products`, {
|
|
530
|
+
tag: 'marketing.seed.entire-menu',
|
|
531
|
+
data: { marketingId: mid, shopId, pages, productCount: count },
|
|
532
|
+
});
|
|
483
533
|
}
|
|
484
534
|
};
|
|
485
535
|
exports.MarketingService = MarketingService;
|