@lyxa.ai/marketing 1.0.29 → 1.0.31
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 +2 -0
- package/dist/lib/event/event-initializations.d.ts.map +1 -0
- package/dist/lib/event/event-initializations.js +8 -0
- package/dist/lib/event/event-initializations.js.map +1 -0
- package/dist/lib/event/event-listeners/event-listeners.d.ts +2 -0
- package/dist/lib/event/event-listeners/event-listeners.d.ts.map +1 -0
- package/dist/lib/event/event-listeners/event-listeners.js +12 -0
- package/dist/lib/event/event-listeners/event-listeners.js.map +1 -0
- package/dist/lib/index.d.ts +734 -78
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +17 -17
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts +710 -75
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js +4 -0
- package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.d.ts +2 -1
- package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.js +42 -18
- package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/global-coupon.service.js +2 -1
- package/dist/lib/modules/coupon/services/global-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/helper.service.js +1 -1
- package/dist/lib/modules/coupon/services/helper.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.js +4 -1
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/individual-user-coupon.service.js +1 -0
- package/dist/lib/modules/coupon/services/individual-user-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts +1 -0
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +123 -5
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.js +2 -0
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js +4 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js +4 -1
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts +153 -153
- package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/all-coupons.validation.js.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +33 -12
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js +12 -5
- package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
- package/dist/lib/modules/coupon/validations/custom-coupon.validation.d.ts +8 -8
- package/dist/lib/modules/coupon/validations/global-coupon.validation.d.ts +8 -8
- package/dist/lib/modules/coupon/validations/individual-store-coupon.validation.d.ts +10 -10
- package/dist/lib/modules/coupon/validations/individual-user-coupon.validation.d.ts +8 -8
- package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.d.ts +9 -9
- package/dist/lib/modules/coupon/validations/shops-categories-coupon.validation.d.ts +8 -8
- package/dist/lib/modules/deal-setting/validations/deal-setting.validation.d.ts +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts +21 -0
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.js +19 -8
- package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.d.ts +2 -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 +45 -102
- 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 +2 -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 +54 -163
- package/dist/lib/modules/marketing/services/discount-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/featured-marketing.service.d.ts +2 -0
- package/dist/lib/modules/marketing/services/featured-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/featured-marketing.service.js +30 -2
- package/dist/lib/modules/marketing/services/featured-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/free-delivery-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/free-delivery-marketing.service.js +6 -1
- package/dist/lib/modules/marketing/services/free-delivery-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/index.d.ts +1 -0
- package/dist/lib/modules/marketing/services/index.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/index.js +1 -0
- package/dist/lib/modules/marketing/services/index.js.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.d.ts +6 -0
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +230 -8
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +1 -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 +21 -3
- package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/punch-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/punch-marketing.service.js +6 -1
- package/dist/lib/modules/marketing/services/punch-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts +14 -0
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -0
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js +209 -0
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js.map +1 -0
- package/dist/lib/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +2 -2
- package/dist/lib/modules/marketing/transformers/discount-marketing.transformer.d.ts +2 -2
- package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +58 -58
- package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts +68 -68
- package/dist/lib/modules/marketing/validations/featured-marketing.validation.d.ts +21 -21
- package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.d.ts +18 -18
- package/dist/lib/modules/marketing/validations/marketing.validation.d.ts +14 -7
- package/dist/lib/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.js +4 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.js.map +1 -1
- package/dist/lib/modules/marketing/validations/product-marketing.validation.d.ts +4 -4
- package/dist/lib/modules/marketing/validations/punch-marketing.validation.d.ts +22 -22
- package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +3 -3
- package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js +2 -2
- package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js.map +1 -1
- package/dist/lib/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +6 -6
- package/dist/types/event/event-initializations.d.ts +2 -0
- package/dist/types/event/event-initializations.d.ts.map +1 -0
- package/dist/types/event/event-listeners/event-listeners.d.ts +2 -0
- package/dist/types/event/event-listeners/event-listeners.d.ts.map +1 -0
- package/dist/types/index.d.ts +734 -78
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts +710 -75
- package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/coupon.service.d.ts +2 -1
- package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/individual-store-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts +1 -0
- package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/shops-categories-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts +153 -153
- package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts +33 -12
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/custom-coupon.validation.d.ts +8 -8
- package/dist/types/modules/coupon/validations/global-coupon.validation.d.ts +8 -8
- package/dist/types/modules/coupon/validations/individual-store-coupon.validation.d.ts +10 -10
- package/dist/types/modules/coupon/validations/individual-user-coupon.validation.d.ts +8 -8
- package/dist/types/modules/coupon/validations/referral-reward-coupon.validation.d.ts +9 -9
- package/dist/types/modules/coupon/validations/shops-categories-coupon.validation.d.ts +8 -8
- package/dist/types/modules/deal-setting/validations/deal-setting.validation.d.ts +1 -1
- package/dist/types/modules/marketing/routers/marketing.router.d.ts +21 -0
- 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 +2 -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 +2 -1
- package/dist/types/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/featured-marketing.service.d.ts +2 -0
- package/dist/types/modules/marketing/services/featured-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/free-delivery-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/index.d.ts +1 -0
- package/dist/types/modules/marketing/services/index.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/marketing.service.d.ts +6 -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 +1 -0
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/punch-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts +14 -0
- package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -0
- package/dist/types/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +2 -2
- package/dist/types/modules/marketing/transformers/discount-marketing.transformer.d.ts +2 -2
- package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +58 -58
- package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts +68 -68
- package/dist/types/modules/marketing/validations/featured-marketing.validation.d.ts +21 -21
- package/dist/types/modules/marketing/validations/free-delivery-marketing.validation.d.ts +18 -18
- package/dist/types/modules/marketing/validations/marketing.validation.d.ts +14 -7
- package/dist/types/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/product-marketing.validation.d.ts +4 -4
- package/dist/types/modules/marketing/validations/punch-marketing.validation.d.ts +22 -22
- package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts +3 -3
- package/dist/types/modules/punch-marketing-history/validations/punch-marketing-history.validation.d.ts +6 -6
- package/package.json +2 -2
|
@@ -52,18 +52,18 @@ declare const ShopsCategoriesCouponValidationSchema: z.ZodObject<{
|
|
|
52
52
|
createdBy: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, import("mongoose").Types.ObjectId, string>, z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
53
53
|
isExpired: z.ZodOptional<z.ZodBoolean>;
|
|
54
54
|
}, "strict", z.ZodTypeAny, {
|
|
55
|
-
value: number;
|
|
56
55
|
code: string;
|
|
56
|
+
value: number;
|
|
57
57
|
status: import("@lyxa.ai/core/dist/utilities/enum").Status;
|
|
58
|
+
valueType: import("@lyxa.ai/core/dist/utilities/enum").ValueType;
|
|
59
|
+
maxDiscountLimit: number | null;
|
|
60
|
+
isMaxDiscountLimitEnabled: boolean;
|
|
58
61
|
duration: {
|
|
59
62
|
start: Date;
|
|
60
63
|
end?: Date | undefined;
|
|
61
64
|
};
|
|
62
|
-
valueType: import("@lyxa.ai/core/dist/utilities/enum").ValueType;
|
|
63
65
|
spendLimit: number | null;
|
|
64
66
|
isSpendLimitEnabled: boolean;
|
|
65
|
-
maxDiscountLimit: number | null;
|
|
66
|
-
isMaxDiscountLimitEnabled: boolean;
|
|
67
67
|
totalOrderLimit: number | null;
|
|
68
68
|
isTotalOrderLimitEnabled: boolean;
|
|
69
69
|
minOrderValue: number | null;
|
|
@@ -86,21 +86,21 @@ declare const ShopsCategoriesCouponValidationSchema: z.ZodObject<{
|
|
|
86
86
|
createdBy?: import("mongoose").Types.ObjectId | undefined;
|
|
87
87
|
isExpired?: boolean | undefined;
|
|
88
88
|
}, {
|
|
89
|
-
value: number;
|
|
90
89
|
code: string;
|
|
90
|
+
value: number;
|
|
91
|
+
valueType: import("@lyxa.ai/core/dist/utilities/enum").ValueType;
|
|
91
92
|
duration: {
|
|
92
93
|
start: string | Date;
|
|
93
94
|
end?: string | Date | undefined;
|
|
94
95
|
};
|
|
95
|
-
valueType: import("@lyxa.ai/core/dist/utilities/enum").ValueType;
|
|
96
96
|
couponType: CouponType.SHOPS_CATEGORIES;
|
|
97
97
|
status?: import("@lyxa.ai/core/dist/utilities/enum").Status | undefined;
|
|
98
|
-
spendLimit?: number | null | undefined;
|
|
99
|
-
isSpendLimitEnabled?: boolean | undefined;
|
|
100
98
|
secondaryCurrencyValue?: number | undefined;
|
|
101
99
|
maxDiscountLimit?: number | null | undefined;
|
|
102
100
|
secondaryCurrencyMaxDiscountLimit?: number | undefined;
|
|
103
101
|
isMaxDiscountLimitEnabled?: boolean | undefined;
|
|
102
|
+
spendLimit?: number | null | undefined;
|
|
103
|
+
isSpendLimitEnabled?: boolean | undefined;
|
|
104
104
|
totalOrderLimit?: number | null | undefined;
|
|
105
105
|
isTotalOrderLimitEnabled?: boolean | undefined;
|
|
106
106
|
minOrderValue?: number | null | undefined;
|
|
@@ -9,8 +9,8 @@ declare const DealSettingValidationSchema: z.ZodObject<{
|
|
|
9
9
|
isFreeDelivery: z.ZodDefault<z.ZodBoolean>;
|
|
10
10
|
isPunchMarketing: z.ZodDefault<z.ZodBoolean>;
|
|
11
11
|
}, "strict", z.ZodTypeAny, {
|
|
12
|
-
isBuy1Get1: boolean;
|
|
13
12
|
itemType: ItemType;
|
|
13
|
+
isBuy1Get1: boolean;
|
|
14
14
|
percentageBundles: number[];
|
|
15
15
|
isDiscount: boolean;
|
|
16
16
|
isFreeDelivery: boolean;
|
|
@@ -90,5 +90,26 @@ export declare const marketingRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
90
90
|
};
|
|
91
91
|
meta: object;
|
|
92
92
|
}>;
|
|
93
|
+
syncAllProductsMarketingInfo: import("@trpc/server").TRPCQueryProcedure<{
|
|
94
|
+
input: void;
|
|
95
|
+
output: string;
|
|
96
|
+
meta: object;
|
|
97
|
+
}>;
|
|
98
|
+
syncProductMarketingInfoByProductId: import("@trpc/server").TRPCQueryProcedure<{
|
|
99
|
+
input: void;
|
|
100
|
+
output: string;
|
|
101
|
+
meta: object;
|
|
102
|
+
}>;
|
|
103
|
+
evaluateMarketingSpendLimits: import("@trpc/server").TRPCMutationProcedure<{
|
|
104
|
+
input: {
|
|
105
|
+
marketings: (string | mongoose.Types.ObjectId)[];
|
|
106
|
+
};
|
|
107
|
+
output: {
|
|
108
|
+
success: boolean;
|
|
109
|
+
message: string;
|
|
110
|
+
data: unknown;
|
|
111
|
+
};
|
|
112
|
+
meta: object;
|
|
113
|
+
}>;
|
|
93
114
|
}>>;
|
|
94
115
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"marketing.router.d.ts","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAYD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoE1B,CAAC"}
|
|
@@ -4,6 +4,7 @@ exports.marketingRouter = void 0;
|
|
|
4
4
|
const trpc_1 = require("@lyxa.ai/core/dist/libraries/trpc");
|
|
5
5
|
const auth_1 = require("@lyxa.ai/core/dist/libraries/trpc/middlewares/auth");
|
|
6
6
|
const services_1 = require("../../marketing/services");
|
|
7
|
+
const services_2 = require("../../marketing/services");
|
|
7
8
|
const validations_1 = require("../../marketing/validations");
|
|
8
9
|
const response_1 = require("@lyxa.ai/core/dist/utilities/response");
|
|
9
10
|
const validation_1 = require("@lyxa.ai/core/dist/utilities/validation");
|
|
@@ -19,15 +20,11 @@ exports.marketingRouter = (0, trpc_1.createTRPCRouter)({
|
|
|
19
20
|
await services_1.marketingService.create(input, isAdmin ? new typegoose_1.mongoose.Types.ObjectId(ctx.entity?.id) : undefined);
|
|
20
21
|
return (0, response_1.response)('Marketing created successfully');
|
|
21
22
|
})),
|
|
22
|
-
getById: trpc_1.publicProcedure
|
|
23
|
-
.input(validation_1.GetByIdInputSchema)
|
|
24
|
-
.query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
23
|
+
getById: trpc_1.publicProcedure.input(validation_1.GetByIdInputSchema).query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
25
24
|
const result = await services_1.marketingService.findById(input);
|
|
26
25
|
return (0, response_1.response)('Marketing fetched successfully', result);
|
|
27
26
|
})),
|
|
28
|
-
get: trpc_1.publicProcedure
|
|
29
|
-
.input(validation_1.FilterSchema)
|
|
30
|
-
.query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
27
|
+
get: trpc_1.publicProcedure.input(validation_1.FilterSchema).query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
31
28
|
const result = await services_1.marketingService.find(input);
|
|
32
29
|
return (0, response_1.response)('Marketing fetched successfully', result);
|
|
33
30
|
})),
|
|
@@ -40,11 +37,12 @@ exports.marketingRouter = (0, trpc_1.createTRPCRouter)({
|
|
|
40
37
|
await services_1.marketingService.update(_id, rest, isAdmin ? new typegoose_1.mongoose.Types.ObjectId(ctx.entity?.id) : undefined);
|
|
41
38
|
return (0, response_1.response)('Marketing updated successfully');
|
|
42
39
|
})),
|
|
43
|
-
deleteById: (0, auth_1.createAuthenticatedProcedure)({ entityTypes: [auth_2.AuthEntityType.CRM] })
|
|
40
|
+
deleteById: (0, auth_1.createAuthenticatedProcedure)({ entityTypes: [auth_2.AuthEntityType.CRM, auth_2.AuthEntityType.SELLER] })
|
|
44
41
|
.input(validation_1.DeleteSchema)
|
|
45
42
|
.output(validations_1.MarketingResponseSchema)
|
|
46
43
|
.mutation(async ({ ctx, input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
47
|
-
|
|
44
|
+
const isAdmin = ctx.entity?.type == auth_2.AuthEntityType.CRM;
|
|
45
|
+
await services_1.marketingService.deleteById(input, isAdmin ? new typegoose_1.mongoose.Types.ObjectId(ctx.entity?.id) : undefined);
|
|
48
46
|
return (0, response_1.response)('Marketing deleted successfully');
|
|
49
47
|
})),
|
|
50
48
|
handleNewProductForEntireMenuMarketing: trpc_1.publicProcedure
|
|
@@ -53,5 +51,18 @@ exports.marketingRouter = (0, trpc_1.createTRPCRouter)({
|
|
|
53
51
|
await services_1.marketingService.handleNewProductForEntireMenuMarketing(input);
|
|
54
52
|
return (0, response_1.response)('Product handled successfully');
|
|
55
53
|
})),
|
|
54
|
+
syncAllProductsMarketingInfo: trpc_1.publicProcedure.query(async ({}) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
55
|
+
return await services_2.synchronizeProductMarketingService.publishAllProductsProductMarketingInfoProcessEvent();
|
|
56
|
+
})),
|
|
57
|
+
syncProductMarketingInfoByProductId: trpc_1.publicProcedure.query(async ({}) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
58
|
+
const productId = new typegoose_1.mongoose.Types.ObjectId("68f663c355f42c826a129fc6");
|
|
59
|
+
return await services_2.synchronizeProductMarketingService.syncProductMarketingInfoByProductId(productId);
|
|
60
|
+
})),
|
|
61
|
+
evaluateMarketingSpendLimits: trpc_1.publicProcedure
|
|
62
|
+
.input(validations_1.MarketingSpendLimitsEvaluationSchema)
|
|
63
|
+
.mutation(async ({ ctx, input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
64
|
+
await services_1.marketingService.evaluateMarketingSpendLimits(input.marketings);
|
|
65
|
+
return (0, response_1.response)('Evaluating marketing spend limits');
|
|
66
|
+
})),
|
|
56
67
|
});
|
|
57
68
|
//# 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,
|
|
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,gEAMwC;AACxC,oEAAiE;AACjE,wEAAyG;AACzG,8EAA0E;AAC1E,4DAAmE;AACnE,oDAAgD;AAEnC,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,GAAG,CAAC,MAAM,EAAE,IAAI,IAAI,qBAAc,CAAC,GAAG,CAAC;QACvD,MAAM,2BAAO,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAC/F,OAAO,IAAA,mBAA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AK,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAChE,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,OAAO,MAAM,6CAA+B,CAAC,kDAAkD,EAAE,CAAC;IACnG,CAAC,CAAC,CACF;IAED,mCAAmC,EAAE,sBAAe,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CACvE,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,SAAS,GAAG,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,0BAA0B,CAAC,CAAC;QAC1E,OAAO,MAAM,6CAA+B,CAAC,mCAAmC,CAAC,SAAS,CAAC,CAAC;IAC7F,CAAC,CAAC,CACF;IAED,4BAA4B,EAAE,sBAAe;SAC3C,KAAK,CAAC,kDAAoC,CAAC;SAC3C,QAAQ,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAClC,4BAAY,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,2BAAO,CAAC,4BAA4B,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC7D,OAAO,IAAA,mBAAQ,EAAC,mCAAmC,CAAC,CAAC;IACtD,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} from '@modules/marketing/validations';\nimport { response } from '@lyxa.ai/core/dist/utilities/response';\nimport { FilterSchema, DeleteSchema, GetByIdInputSchema } 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';\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\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\tevaluateMarketingSpendLimits: publicProcedure\n\t\t.input(MarketingSpendLimitsEvaluationSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tawait service.evaluateMarketingSpendLimits(input.marketings);\n\t\t\t\treturn response('Evaluating marketing spend limits');\n\t\t\t})\n\t\t),\n});\n"]}
|
|
@@ -7,7 +7,8 @@ export declare class Buy1Get1MarketingService {
|
|
|
7
7
|
constructor();
|
|
8
8
|
create(data: CreateDTO): Promise<DocumentType<Model>>;
|
|
9
9
|
update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>>;
|
|
10
|
-
|
|
10
|
+
private createSingleProductMarketing;
|
|
11
|
+
private createProductMarketings;
|
|
11
12
|
}
|
|
12
13
|
export declare const buy1Get1MarketingService: Buy1Get1MarketingService;
|
|
13
14
|
//# sourceMappingURL=buy1-get1-marketing.service.d.ts.map
|
|
@@ -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;IAuBrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YA6ClF,4BAA4B;YAW5B,uBAAuB;CAoCrC;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
|
|
@@ -44,6 +44,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
45
|
exports.buy1Get1MarketingService = exports.Buy1Get1MarketingService = void 0;
|
|
46
46
|
const typedi_1 = __importStar(require("typedi"));
|
|
47
|
+
const typegoose_1 = require("@typegoose/typegoose");
|
|
47
48
|
const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models/");
|
|
48
49
|
const _1 = require("./");
|
|
49
50
|
const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
|
|
@@ -56,133 +57,75 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
|
|
|
56
57
|
}
|
|
57
58
|
async create(data) {
|
|
58
59
|
const result = await this.model.create(data);
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
(!data.categories || data.categories.length === 0) &&
|
|
62
|
-
!data.isEntireMenu) {
|
|
63
|
-
for (const product of data.products) {
|
|
64
|
-
if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
|
|
65
|
-
this.productMarketingsCreate(result._id, product.product);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
else if (data.categories &&
|
|
70
|
-
data.categories.length > 0 &&
|
|
71
|
-
(!data.products || data.products.length === 0) &&
|
|
72
|
-
!data.isEntireMenu) {
|
|
73
|
-
const categoryWiseProducts = await this.productModel
|
|
74
|
-
.find({
|
|
75
|
-
shopCategory: { $in: data.categories },
|
|
76
|
-
})
|
|
77
|
-
.lean();
|
|
78
|
-
for (const product of categoryWiseProducts) {
|
|
79
|
-
if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
|
|
80
|
-
this.productMarketingsCreate(result._id, product._id);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else if (data.categories &&
|
|
85
|
-
data.categories.length > 0 &&
|
|
86
|
-
data.products &&
|
|
87
|
-
data.products.length > 0 &&
|
|
88
|
-
!data.isEntireMenu) {
|
|
89
|
-
const categoryWiseProducts = await this.productModel
|
|
90
|
-
.find({
|
|
91
|
-
shopCategory: { $in: data.categories },
|
|
92
|
-
})
|
|
93
|
-
.lean();
|
|
94
|
-
for (const product of categoryWiseProducts) {
|
|
95
|
-
if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
|
|
96
|
-
this.productMarketingsCreate(result._id, product._id);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
for (const product of data.products) {
|
|
100
|
-
if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
|
|
101
|
-
this.productMarketingsCreate(result._id, product.product);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else if (data.isEntireMenu) {
|
|
106
|
-
this.productModel
|
|
107
|
-
.find({ shop: data.shop })
|
|
108
|
-
.select('_id')
|
|
109
|
-
.exec()
|
|
110
|
-
.then(productDocuments => {
|
|
111
|
-
for (const product of productDocuments) {
|
|
112
|
-
if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {
|
|
113
|
-
this.productMarketingsCreate(result._id, product._id);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
});
|
|
60
|
+
if (!result) {
|
|
61
|
+
(0, error_common_1.internalServerError)('Unable to create marketing');
|
|
117
62
|
}
|
|
63
|
+
await this.createProductMarketings(result.shop._id, result._id, data.products.map(p => p.product) ?? [], data.categories ?? [], data.isEntireMenu ?? false);
|
|
118
64
|
return result;
|
|
119
65
|
}
|
|
120
66
|
async update(_id, data) {
|
|
121
67
|
const { products, ...rest } = data;
|
|
122
|
-
const record = await this.model
|
|
68
|
+
const record = await this.model
|
|
69
|
+
.findOneAndUpdate({
|
|
123
70
|
_id: _id,
|
|
124
71
|
deletedAt: null,
|
|
125
72
|
}, rest, {
|
|
126
73
|
new: true,
|
|
127
74
|
runValidators: true,
|
|
75
|
+
})
|
|
76
|
+
.populate({
|
|
77
|
+
path: 'shop',
|
|
78
|
+
select: '_id name shopId',
|
|
128
79
|
});
|
|
80
|
+
if (!record) {
|
|
81
|
+
(0, error_common_1.notFoundError)('Marketing not found');
|
|
82
|
+
}
|
|
129
83
|
if ((data.products && data.products.length > 0) ||
|
|
130
84
|
(data.categories && data.categories.length > 0) ||
|
|
131
85
|
data.isEntireMenu) {
|
|
132
86
|
await _1.productMarketingService.deleteMany({ marketing: _id }, true);
|
|
133
87
|
}
|
|
134
|
-
|
|
135
|
-
for (const product of data.products) {
|
|
136
|
-
this.productMarketingsCreate(_id, product.product);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
else if (data.categories &&
|
|
140
|
-
data.categories.length > 0 &&
|
|
141
|
-
(!data.products || data.products.length === 0)) {
|
|
142
|
-
const categoryWiseProducts = await this.productModel
|
|
143
|
-
.find({
|
|
144
|
-
shopCategory: { $in: data.categories },
|
|
145
|
-
})
|
|
146
|
-
.lean();
|
|
147
|
-
for (const product of categoryWiseProducts) {
|
|
148
|
-
this.productMarketingsCreate(_id, product._id);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {
|
|
152
|
-
const categoryWiseProducts = await this.productModel
|
|
153
|
-
.find({
|
|
154
|
-
shopCategory: { $in: data.categories },
|
|
155
|
-
})
|
|
156
|
-
.lean();
|
|
157
|
-
for (const product of categoryWiseProducts) {
|
|
158
|
-
this.productMarketingsCreate(_id, product._id);
|
|
159
|
-
}
|
|
160
|
-
for (const product of data.products) {
|
|
161
|
-
this.productMarketingsCreate(_id, product.product);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
else if (data.isEntireMenu) {
|
|
165
|
-
this.productModel
|
|
166
|
-
.find({ shop: data.shop })
|
|
167
|
-
.select('_id')
|
|
168
|
-
.exec()
|
|
169
|
-
.then(productDocuments => {
|
|
170
|
-
for (const product of productDocuments) {
|
|
171
|
-
this.productMarketingsCreate(_id, product._id);
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
88
|
+
await this.createProductMarketings(record.shop._id, _id, data.products?.map((p) => p.product) ?? [], data.categories ?? [], data.isEntireMenu ?? false);
|
|
175
89
|
if (!record)
|
|
176
90
|
(0, error_common_1.notFoundError)('Record not found');
|
|
177
91
|
return record;
|
|
178
92
|
}
|
|
179
|
-
async
|
|
180
|
-
_1.productMarketingService.create({
|
|
93
|
+
async createSingleProductMarketing(marketingId, productId) {
|
|
94
|
+
await _1.productMarketingService.create({
|
|
181
95
|
marketing: marketingId,
|
|
182
96
|
product: productId,
|
|
183
97
|
isBuy1Get1: true,
|
|
184
98
|
});
|
|
185
99
|
}
|
|
100
|
+
async createProductMarketings(shop, marketingId, products, categories, isEntireMenu) {
|
|
101
|
+
if (isEntireMenu) {
|
|
102
|
+
await this.productModel
|
|
103
|
+
.find({ shop })
|
|
104
|
+
.select('_id')
|
|
105
|
+
.exec()
|
|
106
|
+
.then(async (productDocuments) => {
|
|
107
|
+
for (const product of productDocuments) {
|
|
108
|
+
await this.createSingleProductMarketing(marketingId, product._id);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const productsToProcess = new Set(products.map(p => p._id.toString()));
|
|
114
|
+
const categoryWiseProducts = await this.productModel
|
|
115
|
+
.find({
|
|
116
|
+
shopCategory: { $in: categories },
|
|
117
|
+
})
|
|
118
|
+
.lean();
|
|
119
|
+
if (categoryWiseProducts) {
|
|
120
|
+
categoryWiseProducts.forEach(p => {
|
|
121
|
+
productsToProcess.add(p._id.toString());
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
for (const product of productsToProcess) {
|
|
125
|
+
await this.createSingleProductMarketing(marketingId, new typegoose_1.mongoose.Types.ObjectId(product));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
186
129
|
};
|
|
187
130
|
exports.Buy1Get1MarketingService = Buy1Get1MarketingService;
|
|
188
131
|
exports.Buy1Get1MarketingService = Buy1Get1MarketingService = __decorate([
|
|
@@ -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,4EAA0E;AAGnE,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;QAG7C,IACC,IAAI,CAAC,QAAQ;YACb,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;YACxB,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC;YAClD,CAAC,IAAI,CAAC,YAAY,EACjB,CAAC;YACF,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACrC,IAAI,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO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IAAI,gBAAgB,EAAE,CAAC;oBACxC,IAAI,CAAC,uBAAuB,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBAChD,CAAC;YACF,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM;YAAE,IAAA,4BAAa,EAAC,kBAAkB,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,uBAAuB,CACnC,WAAoC,EACpC,SAAkC;QAElC,0BAAuB,CAAC,MAAM,CAAC;YAC9B,SAAS,EAAE,WAAW;YACtB,OAAO,EAAE,SAAS;YAClB,UAAU,EAAE,IAAI;SAChB,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAxLY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAwLpC;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 { 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\t// Only products\n\t\tif (\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t(!data.categories || data.categories.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\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.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: _id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\trest,\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\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\t// Only products\n\t\tif (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0)\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async productMarketingsCreate(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tproductMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tisBuy1Get1: true,\n\t\t});\n\t}\n}\n\nexport const buy1Get1MarketingService = Container.get(Buy1Get1MarketingService);\n"]}
|
|
1
|
+
{"version":3,"file":"buy1-get1-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAE5C,oDAA8D;AAC9D,uEAIoD;AAKpD,yBAA6C;AAC7C,4EAA+F;AAGxF,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;I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,GAAG,CAAC,CAAC;gBACnE,CAAC;YACF,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACP,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;YACvE,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,YAAY;iBAClD,IAAI,CAAC;gBACL,YAAY,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE;aACjC,CAAC;iBACD,IAAI,EAAE,CAAC;YAET,IAAI,oBAAoB,EAAE,CAAC;gBAC1B,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;oBAChC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;gBACzC,CAAC,CAAC,CAAC;YACJ,CAAC;YAED,KAAK,MAAM,OAAO,IAAI,iBAAiB,EAAE,CAAC;gBACzC,MAAM,IAAI,CAAC,4BAA4B,CAAC,WAAW,EAAE,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;YAC5F,CAAC;QACF,CAAC;IACF,CAAC;CACD,CAAA;AAhIY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAgIpC;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\tawait this.createProductMarketings(\n\t\t\tresult.shop._id,\n\t\t\tresult._id,\n\t\t\tdata.products.map(p => p.product) ?? [],\n\t\t\tdata.categories ?? [],\n\t\t\tdata.isEntireMenu ?? false\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\t\t\n\t\tif (!record) {\n\t\t\tnotFoundError('Marketing not found');\n\t\t}\n\t\t\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 this.createProductMarketings(\n\t\t\trecord.shop._id,\n\t\t\t_id,\n\t\t\tdata.products?.map((p: any) => p.product) ?? [],\n\t\t\tdata.categories ?? [],\n\t\t\tdata.isEntireMenu ?? false\n\t\t);\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tprivate async createSingleProductMarketing(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tawait productMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tisBuy1Get1: true,\n\t\t});\n\t}\n\n\tprivate async createProductMarketings(\n\t\tshop: mongoose.Types.ObjectId,\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproducts: mongoose.Types.ObjectId[],\n\t\tcategories: mongoose.Types.ObjectId[],\n\t\tisEntireMenu: boolean\n\t): Promise<void> {\n\t\tif (isEntireMenu) {\n\t\t\tawait this.productModel\n\t\t\t\t.find({ shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(async productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tawait this.createSingleProductMarketing(marketingId, product._id);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t} else {\n\t\t\tconst productsToProcess = new Set(products.map(p => p._id.toString()));\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tif (categoryWiseProducts) {\n\t\t\t\tcategoryWiseProducts.forEach(p => {\n\t\t\t\t\tproductsToProcess.add(p._id.toString());\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tfor (const product of productsToProcess) {\n\t\t\t\tawait this.createSingleProductMarketing(marketingId, new mongoose.Types.ObjectId(product));\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport const buy1Get1MarketingService = Container.get(Buy1Get1MarketingService);\n"]}
|
|
@@ -8,7 +8,8 @@ export declare class DiscountMarketingService {
|
|
|
8
8
|
constructor();
|
|
9
9
|
create(data: CreateDTO): Promise<DocumentType<Model>>;
|
|
10
10
|
update(_id: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>>;
|
|
11
|
-
|
|
11
|
+
createSingleProductMarketing(marketingId: mongoose.Types.ObjectId, productId: mongoose.Types.ObjectId, value: number, valueType: ValueType): Promise<void>;
|
|
12
|
+
private createProductMarketings;
|
|
12
13
|
}
|
|
13
14
|
export declare const discountMarketingService: DiscountMarketingService;
|
|
14
15
|
//# sourceMappingURL=discount-marketing.service.d.ts.map
|
|
@@ -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;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,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;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAO9D,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;IAuBrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAiDnF,4BAA4B,CACxC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACpC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAClC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,IAAI,CAAC;YASF,uBAAuB;CAkErC;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
|