@lyxa.ai/marketing 1.0.20 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/index.d.ts +343 -1
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts +338 -0
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.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 +1 -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 +5 -0
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/transformers/coupon.transformer.d.ts +26 -0
- package/dist/lib/modules/coupon/transformers/coupon.transformer.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts +546 -0
- package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +126 -0
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js +5 -0
- package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
- package/dist/lib/modules/coupon/validations/custom-coupon.validation.d.ts +45 -0
- package/dist/lib/modules/coupon/validations/custom-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/global-coupon.validation.d.ts +45 -0
- package/dist/lib/modules/coupon/validations/global-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/individual-store-coupon.validation.d.ts +45 -0
- package/dist/lib/modules/coupon/validations/individual-store-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/individual-user-coupon.validation.d.ts +45 -0
- package/dist/lib/modules/coupon/validations/individual-user-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/referral-code-coupon.validation.d.ts +9 -0
- package/dist/lib/modules/coupon/validations/referral-code-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.d.ts +45 -0
- package/dist/lib/modules/coupon/validations/referral-reward-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/loyalty-point-setting/routers/index.d.ts +2 -0
- package/dist/lib/modules/loyalty-point-setting/routers/index.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/routers/index.js +18 -0
- package/dist/lib/modules/loyalty-point-setting/routers/index.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/routers/loyalty-point-setting.router.d.ts +321 -0
- package/dist/lib/modules/loyalty-point-setting/routers/loyalty-point-setting.router.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/routers/loyalty-point-setting.router.js +82 -0
- package/dist/lib/modules/loyalty-point-setting/routers/loyalty-point-setting.router.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/services/index.d.ts +3 -0
- package/dist/lib/modules/loyalty-point-setting/services/index.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/services/index.js +19 -0
- package/dist/lib/modules/loyalty-point-setting/services/index.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/services/loyalty-point-category.service.d.ts +16 -0
- package/dist/lib/modules/loyalty-point-setting/services/loyalty-point-category.service.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/services/loyalty-point-category.service.js +133 -0
- package/dist/lib/modules/loyalty-point-setting/services/loyalty-point-category.service.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/services/loyalty-point-setting.service.d.ts +16 -0
- package/dist/lib/modules/loyalty-point-setting/services/loyalty-point-setting.service.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/services/loyalty-point-setting.service.js +156 -0
- package/dist/lib/modules/loyalty-point-setting/services/loyalty-point-setting.service.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/index.d.ts +3 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/index.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/index.js +19 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/index.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/loyalty-point-category.transformer.d.ts +8 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/loyalty-point-category.transformer.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/loyalty-point-category.transformer.js +7 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/loyalty-point-category.transformer.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/loyalty-point-setting.transformer.d.ts +9 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/loyalty-point-setting.transformer.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/loyalty-point-setting.transformer.js +7 -0
- package/dist/lib/modules/loyalty-point-setting/transformers/loyalty-point-setting.transformer.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/validations/index.d.ts +3 -0
- package/dist/lib/modules/loyalty-point-setting/validations/index.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/validations/index.js +19 -0
- package/dist/lib/modules/loyalty-point-setting/validations/index.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/validations/loyalty-point-category.validation.d.ts +170 -0
- package/dist/lib/modules/loyalty-point-setting/validations/loyalty-point-category.validation.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/validations/loyalty-point-category.validation.js +19 -0
- package/dist/lib/modules/loyalty-point-setting/validations/loyalty-point-category.validation.js.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/validations/loyalty-point-setting.validation.d.ts +188 -0
- package/dist/lib/modules/loyalty-point-setting/validations/loyalty-point-setting.validation.d.ts.map +1 -0
- package/dist/lib/modules/loyalty-point-setting/validations/loyalty-point-setting.validation.js +19 -0
- package/dist/lib/modules/loyalty-point-setting/validations/loyalty-point-setting.validation.js.map +1 -0
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts +5 -1
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.js +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
- package/dist/lib/modules/marketing/services/loyalty-point-marketing.service.d.ts +12 -0
- package/dist/lib/modules/marketing/services/loyalty-point-marketing.service.d.ts.map +1 -0
- package/dist/lib/modules/marketing/services/loyalty-point-marketing.service.js +149 -0
- package/dist/lib/modules/marketing/services/loyalty-point-marketing.service.js.map +1 -0
- package/dist/lib/modules/marketing/services/marketing.service.d.ts +2 -2
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +2 -5
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +1 -0
- package/dist/lib/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts.map +1 -1
- package/dist/lib/modules/marketing/transformers/discount-marketing.transformer.d.ts +2 -0
- package/dist/lib/modules/marketing/transformers/discount-marketing.transformer.d.ts.map +1 -1
- package/dist/lib/modules/marketing/transformers/free-delivery-marketing.transformer.d.ts +1 -0
- package/dist/lib/modules/marketing/transformers/free-delivery-marketing.transformer.d.ts.map +1 -1
- package/dist/lib/modules/marketing/transformers/loyalty-point-marketing.transformer.d.ts +47 -0
- package/dist/lib/modules/marketing/transformers/loyalty-point-marketing.transformer.d.ts.map +1 -0
- package/dist/lib/modules/marketing/transformers/loyalty-point-marketing.transformer.js +7 -0
- package/dist/lib/modules/marketing/transformers/loyalty-point-marketing.transformer.js.map +1 -0
- package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +14 -0
- package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.js +1 -0
- package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.js.map +1 -1
- package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts +28 -0
- package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/discount-marketing.validation.js +2 -0
- package/dist/lib/modules/marketing/validations/discount-marketing.validation.js.map +1 -1
- package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.d.ts +9 -0
- package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.js +1 -0
- package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.js.map +1 -1
- package/dist/lib/modules/marketing/validations/loyalty-point-marketing.validation.d.ts +504 -0
- package/dist/lib/modules/marketing/validations/loyalty-point-marketing.validation.d.ts.map +1 -0
- package/dist/lib/modules/marketing/validations/loyalty-point-marketing.validation.js +34 -0
- package/dist/lib/modules/marketing/validations/loyalty-point-marketing.validation.js.map +1 -0
- package/dist/types/index.d.ts +343 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts +338 -0
- package/dist/types/modules/coupon/routers/coupon.router.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/transformers/coupon.transformer.d.ts +26 -0
- package/dist/types/modules/coupon/transformers/coupon.transformer.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts +546 -0
- package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts +126 -0
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/custom-coupon.validation.d.ts +45 -0
- package/dist/types/modules/coupon/validations/custom-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/global-coupon.validation.d.ts +45 -0
- package/dist/types/modules/coupon/validations/global-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/individual-store-coupon.validation.d.ts +45 -0
- package/dist/types/modules/coupon/validations/individual-store-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/individual-user-coupon.validation.d.ts +45 -0
- package/dist/types/modules/coupon/validations/individual-user-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/referral-code-coupon.validation.d.ts +9 -0
- package/dist/types/modules/coupon/validations/referral-code-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/referral-reward-coupon.validation.d.ts +45 -0
- package/dist/types/modules/coupon/validations/referral-reward-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/loyalty-point-setting/routers/index.d.ts +2 -0
- package/dist/types/modules/loyalty-point-setting/routers/index.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/routers/loyalty-point-setting.router.d.ts +321 -0
- package/dist/types/modules/loyalty-point-setting/routers/loyalty-point-setting.router.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/services/index.d.ts +3 -0
- package/dist/types/modules/loyalty-point-setting/services/index.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/services/loyalty-point-category.service.d.ts +37 -0
- package/dist/types/modules/loyalty-point-setting/services/loyalty-point-category.service.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/services/loyalty-point-setting.service.d.ts +34 -0
- package/dist/types/modules/loyalty-point-setting/services/loyalty-point-setting.service.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/transformers/index.d.ts +3 -0
- package/dist/types/modules/loyalty-point-setting/transformers/index.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/transformers/loyalty-point-category.transformer.d.ts +8 -0
- package/dist/types/modules/loyalty-point-setting/transformers/loyalty-point-category.transformer.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/transformers/loyalty-point-setting.transformer.d.ts +9 -0
- package/dist/types/modules/loyalty-point-setting/transformers/loyalty-point-setting.transformer.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/validations/index.d.ts +3 -0
- package/dist/types/modules/loyalty-point-setting/validations/index.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/validations/loyalty-point-category.validation.d.ts +179 -0
- package/dist/types/modules/loyalty-point-setting/validations/loyalty-point-category.validation.d.ts.map +1 -0
- package/dist/types/modules/loyalty-point-setting/validations/loyalty-point-setting.validation.d.ts +197 -0
- package/dist/types/modules/loyalty-point-setting/validations/loyalty-point-setting.validation.d.ts.map +1 -0
- package/dist/types/modules/marketing/routers/marketing.router.d.ts +5 -1
- package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/loyalty-point-marketing.service.d.ts +21 -0
- package/dist/types/modules/marketing/services/loyalty-point-marketing.service.d.ts.map +1 -0
- package/dist/types/modules/marketing/services/marketing.service.d.ts +2 -2
- package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts +1 -0
- package/dist/types/modules/marketing/transformers/buy1-get1-marketing.transformer.d.ts.map +1 -1
- package/dist/types/modules/marketing/transformers/discount-marketing.transformer.d.ts +2 -0
- package/dist/types/modules/marketing/transformers/discount-marketing.transformer.d.ts.map +1 -1
- package/dist/types/modules/marketing/transformers/free-delivery-marketing.transformer.d.ts +1 -0
- package/dist/types/modules/marketing/transformers/free-delivery-marketing.transformer.d.ts.map +1 -1
- package/dist/types/modules/marketing/transformers/loyalty-point-marketing.transformer.d.ts +47 -0
- package/dist/types/modules/marketing/transformers/loyalty-point-marketing.transformer.d.ts.map +1 -0
- package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +14 -0
- package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts +28 -0
- package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/free-delivery-marketing.validation.d.ts +9 -0
- package/dist/types/modules/marketing/validations/free-delivery-marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/loyalty-point-marketing.validation.d.ts +513 -0
- package/dist/types/modules/marketing/validations/loyalty-point-marketing.validation.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.loyaltyPointMarketingService = exports.LoyaltyPointMarketingService = void 0;
|
|
46
|
+
const typedi_1 = __importStar(require("typedi"));
|
|
47
|
+
const server_1 = require("@trpc/server");
|
|
48
|
+
const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models");
|
|
49
|
+
const _1 = require("./");
|
|
50
|
+
let LoyaltyPointMarketingService = class LoyaltyPointMarketingService {
|
|
51
|
+
model;
|
|
52
|
+
productModel;
|
|
53
|
+
constructor() {
|
|
54
|
+
this.model = models_1.LoyaltyPointMarketingModel;
|
|
55
|
+
this.productModel = models_1.ProductModel;
|
|
56
|
+
}
|
|
57
|
+
async create(data) {
|
|
58
|
+
const result = await this.model.create(data);
|
|
59
|
+
if (data.products && data.products.length > 0) {
|
|
60
|
+
for (const product of data.products) {
|
|
61
|
+
_1.productMarketingService.create({
|
|
62
|
+
marketing: result._id,
|
|
63
|
+
product: product.product,
|
|
64
|
+
value: data.value,
|
|
65
|
+
valueType: data.valueType,
|
|
66
|
+
loyaltyPointCategory: product.loyaltyPointCategory,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else if (data.isEntireMenu) {
|
|
71
|
+
const products = this.productModel
|
|
72
|
+
.find({
|
|
73
|
+
shop: data.shop,
|
|
74
|
+
})
|
|
75
|
+
.select('_id')
|
|
76
|
+
.exec()
|
|
77
|
+
.then(productDocuments => {
|
|
78
|
+
for (const product of productDocuments) {
|
|
79
|
+
_1.productMarketingService.create({
|
|
80
|
+
marketing: result._id,
|
|
81
|
+
product: product._id,
|
|
82
|
+
value: data.value,
|
|
83
|
+
valueType: data.valueType,
|
|
84
|
+
loyaltyPointCategory: data.category,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
async update(_id, data) {
|
|
92
|
+
const { products, ...rest } = data;
|
|
93
|
+
const record = await this.model.findOneAndUpdate({
|
|
94
|
+
_id: _id,
|
|
95
|
+
deletedAt: null,
|
|
96
|
+
}, rest, {
|
|
97
|
+
new: true,
|
|
98
|
+
runValidators: true,
|
|
99
|
+
});
|
|
100
|
+
if (data.products) {
|
|
101
|
+
const productIds = [];
|
|
102
|
+
for (const product of data.products) {
|
|
103
|
+
_1.productMarketingService.updateOne({
|
|
104
|
+
product: product.product,
|
|
105
|
+
marketing: _id,
|
|
106
|
+
}, product);
|
|
107
|
+
productIds.push(product.product);
|
|
108
|
+
}
|
|
109
|
+
_1.productMarketingService.deleteMultipleProducts({
|
|
110
|
+
marketing: _id,
|
|
111
|
+
products: productIds,
|
|
112
|
+
}, true);
|
|
113
|
+
}
|
|
114
|
+
else if (data.isEntireMenu) {
|
|
115
|
+
this.productModel
|
|
116
|
+
.find({
|
|
117
|
+
shop: data.shop,
|
|
118
|
+
})
|
|
119
|
+
.select('_id')
|
|
120
|
+
.exec()
|
|
121
|
+
.then(productDocuments => {
|
|
122
|
+
for (const product of productDocuments) {
|
|
123
|
+
_1.productMarketingService.updateOne({
|
|
124
|
+
product: product._id,
|
|
125
|
+
marketing: _id,
|
|
126
|
+
}, {
|
|
127
|
+
value: data.value,
|
|
128
|
+
valueType: data.valueType,
|
|
129
|
+
loyaltyPointCategory: data.category,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (!record) {
|
|
135
|
+
throw new server_1.TRPCError({
|
|
136
|
+
code: 'NOT_FOUND',
|
|
137
|
+
message: `Record not found`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return record;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
exports.LoyaltyPointMarketingService = LoyaltyPointMarketingService;
|
|
144
|
+
exports.LoyaltyPointMarketingService = LoyaltyPointMarketingService = __decorate([
|
|
145
|
+
(0, typedi_1.Service)(),
|
|
146
|
+
__metadata("design:paramtypes", [])
|
|
147
|
+
], LoyaltyPointMarketingService);
|
|
148
|
+
exports.loyaltyPointMarketingService = typedi_1.default.get(LoyaltyPointMarketingService);
|
|
149
|
+
//# sourceMappingURL=loyalty-point-marketing.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loyalty-point-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/loyalty-point-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AAEzC,sEAImD;AAKnD,yBAA6C;AAGtC,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAChC,KAAK,CAAoC;IACzC,YAAY,CAAsB;IAE1C;QACC,IAAI,CAAC,KAAK,GAAG,mCAA0B,CAAC;QACxC,IAAI,CAAC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AQ;qBACnC,CACD,CAAC;gBACH,CAAC;YACF,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,kBAAkB;aAC3B,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;CACD,CAAA;AA1HY,oEAA4B;uCAA5B,4BAA4B;IADxC,IAAA,gBAAO,GAAE;;GACG,4BAA4B,CA0HxC;AAEY,QAAA,4BAA4B,GAAG,gBAAS,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tLoyaltyPointMarketingModel,\n\tLoyaltyPointMarketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tCreateLoyaltyPointMarketingDTO as CreateDTO,\n\tUpdateLoyaltyPointMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\n\n@Service()\nexport class LoyaltyPointMarketingService {\n\tprivate model: typeof LoyaltyPointMarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = LoyaltyPointMarketingModel;\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.products && data.products.length > 0) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tproductMarketingService.create({\n\t\t\t\t\tmarketing: result._id,\n\t\t\t\t\tproduct: product.product,\n\t\t\t\t\tvalue: data.value,\n\t\t\t\t\tvalueType: data.valueType,\n\t\t\t\t\tloyaltyPointCategory: product.loyaltyPointCategory,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\tconst products = this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshop: data.shop,\n\t\t\t\t})\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\tproductMarketingService.create({\n\t\t\t\t\t\t\tmarketing: result._id,\n\t\t\t\t\t\t\tproduct: product._id,\n\t\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t\t\tvalueType: data.valueType,\n\t\t\t\t\t\t\tloyaltyPointCategory: data.category,\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\tif (data.products) {\n\t\t\tconst productIds: Array<mongoose.Types.ObjectId> = [];\n\t\t\tfor (const product of data.products) {\n\t\t\t\tproductMarketingService.updateOne(\n\t\t\t\t\t{\n\t\t\t\t\t\tproduct: product.product,\n\t\t\t\t\t\tmarketing: _id,\n\t\t\t\t\t},\n\t\t\t\t\tproduct\n\t\t\t\t);\n\t\t\t\tproductIds.push(product.product);\n\t\t\t}\n\n\t\t\t// remove products that had marketing but not anymore\n\t\t\tproductMarketingService.deleteMultipleProducts(\n\t\t\t\t{\n\t\t\t\t\tmarketing: _id,\n\t\t\t\t\tproducts: productIds,\n\t\t\t\t},\n\t\t\t\ttrue\n\t\t\t);\n\t\t} else if (data.isEntireMenu) {\n\t\t\tthis.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshop: data.shop,\n\t\t\t\t})\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\tproductMarketingService.updateOne(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tproduct: product._id,\n\t\t\t\t\t\t\t\tmarketing: _id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: data.value,\n\t\t\t\t\t\t\t\tvalueType: data.valueType,\n\t\t\t\t\t\t\t\tloyaltyPointCategory: data.category,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Record not found`,\n\t\t\t});\n\t\t}\n\n\t\treturn record;\n\t}\n}\n\nexport const loyaltyPointMarketingService = Container.get(LoyaltyPointMarketingService);\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { DocumentType, mongoose } from '@typegoose/typegoose';
|
|
2
2
|
import { Marketing as Model } from '@lyxa.ai/core/dist/libraries/mongo/models';
|
|
3
3
|
import { AllMarketingsValidationDTO, UpdateMarketingDTO as UpdateDTO } from '../../marketing/validations';
|
|
4
|
-
import { FilterDTO, PaginatedResponse, DeleteDTO } from '@lyxa.ai/core/dist/utilities/validation';
|
|
4
|
+
import { FilterDTO, PaginatedResponse, DeleteDTO, GetByIdInputDTO } from '@lyxa.ai/core/dist/utilities/validation';
|
|
5
5
|
import { ModelType } from '@typegoose/typegoose/lib/types';
|
|
6
6
|
export declare class MarketingService {
|
|
7
7
|
private model;
|
|
8
8
|
constructor();
|
|
9
9
|
create(data: AllMarketingsValidationDTO, admin?: mongoose.Types.ObjectId): Promise<DocumentType<Model>>;
|
|
10
|
-
findById(
|
|
10
|
+
findById(data: GetByIdInputDTO): Promise<DocumentType<Model>>;
|
|
11
11
|
find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>>;
|
|
12
12
|
update(_id: mongoose.Types.ObjectId, data: UpdateDTO, admin?: mongoose.Types.ObjectId): Promise<DocumentType<Model>>;
|
|
13
13
|
private logMarketingAdminAction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAEN,SAAS,IAAI,KAAK,EAElB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAEN,0BAA0B,EAE1B,kBAAkB,IAAI,SAAS,EAC/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAEN,SAAS,IAAI,KAAK,EAElB,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAEN,0BAA0B,EAE1B,kBAAkB,IAAI,SAAS,EAC/B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAGnH,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAkB3D,qBACa,gBAAgB;IAC5B,OAAO,CAAC,KAAK,CAAiD;;IAUjD,MAAM,CAClB,IAAI,EAAE,0BAA0B,EAChC,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAC7B,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA0GlB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAe7D,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IA0B3F,MAAM,CAClB,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAC5B,IAAI,EAAE,SAAS,EACf,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAC7B,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YA0FjB,uBAAuB;IAmBxB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CA2B1F;AAED,eAAO,MAAM,gBAAgB,kBAAkC,CAAC"}
|
|
@@ -141,11 +141,8 @@ let MarketingService = class MarketingService {
|
|
|
141
141
|
}
|
|
142
142
|
return marketing;
|
|
143
143
|
}
|
|
144
|
-
async findById(
|
|
145
|
-
const result = await this.model.
|
|
146
|
-
_id: id,
|
|
147
|
-
deletedAt: null,
|
|
148
|
-
});
|
|
144
|
+
async findById(data) {
|
|
145
|
+
const result = await this.model.findRecordById(data);
|
|
149
146
|
if (!result) {
|
|
150
147
|
throw new server_1.TRPCError({
|
|
151
148
|
code: 'NOT_FOUND',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AAEzC,sEAImD;AASnD,wEAA6G;AAE7G,8FAA6G;AAC7G,i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AE,uBAAuB;gBAC7B,OAAO,EAAE,4BAA4B;aACrC,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,iCAA0B,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC;QACtG,CAAC;QAED,0BAAuB,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAE7E,OAAO,6BAA6B,CAAC;IACtC,CAAC;CACD,CAAA;AAhTY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,gBAAO,GAAE;;GACG,gBAAgB,CAgT5B;AAEY,QAAA,gBAAgB,GAAG,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport {\n\tMarketingModel,\n\tMarketing as Model,\n\tPunchMarketingHistory,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tAllMarketingsDTO,\n\tAllMarketingsValidationDTO,\n\tCreateProductMarketingDTO,\n\tUpdateMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { FilterDTO, PaginatedResponse, DeleteDTO } from '@lyxa.ai/core/dist/utilities/validation';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { filterRelevantChanges, getChangedFields } from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType, MarketingStatus } from '@lyxa.ai/core/dist/utilities/enum';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\n\nimport {\n\tbuy1Get1MarketingService,\n\tdiscountMarketingService,\n\tfeaturedMarketingService,\n\tfreeDeliveryMarketingService,\n\tproductMarketingService,\n\tpunchMarketingService,\n} from '.';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { internalServerError, notFoundError, unauthorizedError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class MarketingService {\n\tprivate model: typeof MarketingModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.model = MarketingModel as typeof MarketingModel & SoftDeleteModel<Model>;\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(\n\t\tdata: AllMarketingsValidationDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tconst now = new Date();\n\n\t\tconst existingRecord = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: data.marketingType,\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t});\n\t\tif (existingRecord) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `This shop already has a ${data.marketingType} marketing`,\n\t\t\t});\n\t\t}\n\n\t\tif (data.isEntireMenu) {\n\t\t\tconst existingMarketing = await this.model.findOne({\n\t\t\t\tshop: data.shop,\n\t\t\t\t'duration.start': { $lt: now },\n\t\t\t\t'duration.end': { $gt: now },\n\t\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\t});\n\t\t\tif (existingMarketing) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Cannot create marketing for entire menu while another marketing exists for the shop`,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (data.products && data.products.length > 0) {\n\t\t\tconst productIds = data.products.map((product: CreateProductMarketingDTO) => product.product);\n\n\t\t\tconst hasDuplicates = new Set(productIds.map(String)).size !== productIds.length;\n\n\t\t\tif (hasDuplicates) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'BAD_REQUEST',\n\t\t\t\t\tmessage: `Product list contains duplicate products`,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability(productIds);\n\n\t\t\tif (!isAvailable) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Product list contains products which already have marketing applied`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tswitch (data.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: 'UNAUTHORIZED',\n\t\t\t\t\t\tmessage: `Only admin is allowed to create ${data.marketingType} marketing`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.create(data);\n\t\t\t}\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.ACTIVATED_MARKETING_PROMOTIONS,\n\t\t\t\t'',\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\treturn marketing;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(id: string | mongoose.Types.ObjectId): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.findOne({\n\t\t\t_id: id,\n\t\t\tdeletedAt: null,\n\t\t});\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\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(\n\t\t_id: mongoose.Types.ObjectId,\n\t\tdata: UpdateDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tconst oldMarketing = await this.model.findById(_id);\n\t\t\n\t\tif (!oldMarketing) {\n\t\t\tnotFoundError('Could not find marketing');\n\t\t}\n\n\t\tswitch (oldMarketing.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tunauthorizedError(`Only admin is allowed to update ${data.marketingType} marketing`);\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.findOneAndUpdate(\n\t\t\t\t\t{\n\t\t\t\t\t\t_id: _id,\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t\tdata,\n\t\t\t\t\t{\n\t\t\t\t\t\tnew: true,\n\t\t\t\t\t\trunValidators: true,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!marketing) {\n\t\t\tinternalServerError('Could not update marketing');\n\t\t}\n\n\t\tif (admin) {\n\t\t\tconst allChanges = getChangedFields(oldMarketing, marketing);\n\t\t\tconst relevantChanges = filterRelevantChanges(allChanges, data);\n\n\t\t\tif (Object.keys(relevantChanges).includes('pausedAt')) {\n\t\t\t\tif (data.pausedAt == null) {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.CONTINUED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.PAUSED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.EDITED_MARKETING_PROMOTIONS,\n\t\t\t\toldMarketing,\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\treturn marketing;\n\t}\n\n\tprivate async logMarketingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: mongoose.Types.ObjectId): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tconst record = await this.model.findById(_id);\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete marketing',\n\t\t\t});\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(admin, AdminLogsUpdatedFieldsType.DELETED_MARKETING_PROMOTIONS, record);\n\t\t}\n\n\t\tproductMarketingService.deleteMany({ marketing: data._id }, data.softDelete);\n\n\t\treturn 'Record deleted successfully';\n\t}\n}\n\nexport const marketingService = Container.get(MarketingService);\n"]}
|
|
1
|
+
{"version":3,"file":"marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AAEzC,sEAImD;AASnD,wEAA6G;AAE7G,8FAA6G;AAC7G,iGAAoG;AACpG,4DAAgG;AAChG,8DAAkE;AAGlE,wBAOW;AACX,4DAAkE;AAClE,4EAAkH;AAG3G,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACpB,KAAK,CAAiD;IAE9D;QACC,IAAI,CAAC,KAAK,GAAG,uBAAgE,CAAC;IAC/E,CAAC;IAMM,KAAK,CAAC,MAAM,CAClB,IAAgC,EAChC,KAA+B;QAE/B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QAEvB,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;YAC/C,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,cAAc,EAAE,EAAE,GAAG,EAAE,IAAI,IAAI,EAAE,EAAE;YACnC,MAAM,EAAE,sBAAe,CAAC,MAAM;SAC9B,CAAC,CAAC;QACH,IAAI,cAAc,EAAE,CAAC;YACpB,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,2BAA2B,IAAI,CAAC,aAAa,YAAY;aAClE,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,IAAI,CAAC,YAAY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,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAE9C,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,kBAAkB;aAC3B,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,uBAAuB;gBAC7B,OAAO,EAAE,4BAA4B;aACrC,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,iCAA0B,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC;QACtG,CAAC;QAED,0BAAuB,CAAC,UAAU,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAE7E,OAAO,6BAA6B,CAAC;IACtC,CAAC;CACD,CAAA;AA7SY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,gBAAO,GAAE;;GACG,gBAAgB,CA6S5B;AAEY,QAAA,gBAAgB,GAAG,gBAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport {\n\tMarketingModel,\n\tMarketing as Model,\n\tPunchMarketingHistory,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tAllMarketingsDTO,\n\tAllMarketingsValidationDTO,\n\tCreateProductMarketingDTO,\n\tUpdateMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { FilterDTO, PaginatedResponse, DeleteDTO, GetByIdInputDTO } from '@lyxa.ai/core/dist/utilities/validation';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { filterRelevantChanges, getChangedFields } from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType, MarketingStatus } from '@lyxa.ai/core/dist/utilities/enum';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\n\nimport {\n\tbuy1Get1MarketingService,\n\tdiscountMarketingService,\n\tfeaturedMarketingService,\n\tfreeDeliveryMarketingService,\n\tproductMarketingService,\n\tpunchMarketingService,\n} from '.';\nimport { MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { internalServerError, notFoundError, unauthorizedError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class MarketingService {\n\tprivate model: typeof MarketingModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.model = MarketingModel as typeof MarketingModel & SoftDeleteModel<Model>;\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(\n\t\tdata: AllMarketingsValidationDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tconst now = new Date();\n\n\t\tconst existingRecord = await this.model.findOne({\n\t\t\tshop: data.shop,\n\t\t\tmarketingType: data.marketingType,\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t});\n\t\tif (existingRecord) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `This shop already has a ${data.marketingType} marketing`,\n\t\t\t});\n\t\t}\n\n\t\tif (data.isEntireMenu) {\n\t\t\tconst existingMarketing = await this.model.findOne({\n\t\t\t\tshop: data.shop,\n\t\t\t\t'duration.start': { $lt: now },\n\t\t\t\t'duration.end': { $gt: now },\n\t\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\t});\n\t\t\tif (existingMarketing) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Cannot create marketing for entire menu while another marketing exists for the shop`,\n\t\t\t\t});\n\t\t\t}\n\t\t} else if (data.products && data.products.length > 0) {\n\t\t\tconst productIds = data.products.map((product: CreateProductMarketingDTO) => product.product);\n\n\t\t\tconst hasDuplicates = new Set(productIds.map(String)).size !== productIds.length;\n\n\t\t\tif (hasDuplicates) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'BAD_REQUEST',\n\t\t\t\t\tmessage: `Product list contains duplicate products`,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst isAvailable = await productMarketingService.checkProductMarketingAvailability(productIds);\n\n\t\t\tif (!isAvailable) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'CONFLICT',\n\t\t\t\t\tmessage: `Product list contains products which already have marketing applied`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tswitch (data.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: 'UNAUTHORIZED',\n\t\t\t\t\t\tmessage: `Only admin is allowed to create ${data.marketingType} marketing`,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.create(data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.create(data);\n\t\t\t}\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.ACTIVATED_MARKETING_PROMOTIONS,\n\t\t\t\t'',\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\treturn marketing;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(data: GetByIdInputDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.findRecordById(data);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\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(\n\t\t_id: mongoose.Types.ObjectId,\n\t\tdata: UpdateDTO,\n\t\tadmin?: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model>> {\n\t\tlet marketing: AllMarketingsDTO;\n\n\t\tconst oldMarketing = await this.model.findById(_id);\n\t\t\n\t\tif (!oldMarketing) {\n\t\t\tnotFoundError('Could not find marketing');\n\t\t}\n\n\t\tswitch (oldMarketing.marketingType) {\n\t\t\tcase MarketingType.DISCOUNT: {\n\t\t\t\tmarketing = await discountMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.BUY1GET1: {\n\t\t\t\tmarketing = await buy1Get1MarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FEATURED: {\n\t\t\t\tif (!admin) {\n\t\t\t\t\tunauthorizedError(`Only admin is allowed to update ${data.marketingType} marketing`);\n\t\t\t\t}\n\t\t\t\tmarketing = await featuredMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.FREE_DELIVERY: {\n\t\t\t\tmarketing = await freeDeliveryMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcase MarketingType.PUNCH_MARKETING: {\n\t\t\t\tmarketing = await punchMarketingService.update(_id, data);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tdefault: {\n\t\t\t\tmarketing = await this.model.findOneAndUpdate(\n\t\t\t\t\t{\n\t\t\t\t\t\t_id: _id,\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t\tdata,\n\t\t\t\t\t{\n\t\t\t\t\t\tnew: true,\n\t\t\t\t\t\trunValidators: true,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!marketing) {\n\t\t\tinternalServerError('Could not update marketing');\n\t\t}\n\n\t\tif (admin) {\n\t\t\tconst allChanges = getChangedFields(oldMarketing, marketing);\n\t\t\tconst relevantChanges = filterRelevantChanges(allChanges, data);\n\n\t\t\tif (Object.keys(relevantChanges).includes('pausedAt')) {\n\t\t\t\tif (data.pausedAt == null) {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.CONTINUED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.logMarketingAdminAction(\n\t\t\t\t\t\tadmin,\n\t\t\t\t\t\tAdminLogsUpdatedFieldsType.PAUSED_MARKETING_PROMOTIONS,\n\t\t\t\t\t\toldMarketing,\n\t\t\t\t\t\tmarketing\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.logMarketingAdminAction(\n\t\t\t\tadmin,\n\t\t\t\tAdminLogsUpdatedFieldsType.EDITED_MARKETING_PROMOTIONS,\n\t\t\t\toldMarketing,\n\t\t\t\tmarketing\n\t\t\t);\n\t\t}\n\n\t\treturn marketing;\n\t}\n\n\tprivate async logMarketingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: mongoose.Types.ObjectId): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tconst record = await this.model.findById(_id);\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete marketing',\n\t\t\t});\n\t\t}\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingAdminAction(admin, AdminLogsUpdatedFieldsType.DELETED_MARKETING_PROMOTIONS, record);\n\t\t}\n\n\t\tproductMarketingService.deleteMany({ marketing: data._id }, data.softDelete);\n\n\t\treturn 'Record deleted successfully';\n\t}\n}\n\nexport const marketingService = Container.get(MarketingService);\n"]}
|
|
@@ -23,6 +23,7 @@ export declare const buy1Get1MarketingTransformer: import("@lyxa.ai/core/dist/ut
|
|
|
23
23
|
valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
|
|
24
24
|
}>, "many">>>>;
|
|
25
25
|
spendLimit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
|
|
26
|
+
isSpendLimitEnabled: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
26
27
|
isOnlyForSubscriber: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
27
28
|
shop: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
28
29
|
isAppliedByCompany: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buy1-get1-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/buy1-get1-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,+EAA+E,CAAC;AAM3H,eAAO,MAAM,4BAA4B
|
|
1
|
+
{"version":3,"file":"buy1-get1-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/buy1-get1-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,+EAA+E,CAAC;AAM3H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
|
|
@@ -27,7 +27,9 @@ export declare const discountMarketingTransformer: import("@lyxa.ai/core/dist/ut
|
|
|
27
27
|
valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
|
|
28
28
|
}>, "many">>>>;
|
|
29
29
|
maxDiscountPerOrder: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
|
|
30
|
+
isMaxDiscountPerOrderEnabled: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
30
31
|
spendLimit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
|
|
32
|
+
isSpendLimitEnabled: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
31
33
|
isOnlyForSubscriber: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
32
34
|
shop: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
33
35
|
isAppliedByCompany: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discount-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/discount-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,8EAA8E,CAAC;AAM1H,eAAO,MAAM,4BAA4B
|
|
1
|
+
{"version":3,"file":"discount-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/discount-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,IAAI,KAAK,EAAE,MAAM,8EAA8E,CAAC;AAM1H,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { FreeDeliveryMarketing as Model } from '@lyxa.ai/core/dist/libraries/mon
|
|
|
2
2
|
export declare const freeDeliveryMarketingTransformer: import("@lyxa.ai/core/dist/utilities/transformers").GlobalTransformer<Model, import("zod").objectOutputType<{
|
|
3
3
|
marketingType: import("zod").ZodOptional<import("zod").ZodLiteral<import("@lyxa.ai/core/dist/utilities/enum").MarketingType.FREE_DELIVERY>>;
|
|
4
4
|
spendLimit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
|
|
5
|
+
isSpendLimitEnabled: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
5
6
|
shop: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
6
7
|
isAppliedByCompany: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
7
8
|
duration: import("zod").ZodOptional<import("zod").ZodObject<{
|
package/dist/lib/modules/marketing/transformers/free-delivery-marketing.transformer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"free-delivery-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/free-delivery-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,mFAAmF,CAAC;AAMnI,eAAO,MAAM,gCAAgC
|
|
1
|
+
{"version":3,"file":"free-delivery-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/free-delivery-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,mFAAmF,CAAC;AAMnI,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { LoyaltyPointMarketing as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/providers/loyalty-point-marketing.model';
|
|
2
|
+
export declare const loyaltyPointMarketingTransformer: import("@lyxa.ai/core/dist/utilities/transformers").GlobalTransformer<Model, import("zod").objectOutputType<{
|
|
3
|
+
marketingType: import("zod").ZodOptional<import("zod").ZodLiteral<import("@lyxa.ai/core/dist/utilities/enum").MarketingType.LOYALTY_POINT>>;
|
|
4
|
+
isEntireMenu: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
5
|
+
valueType: import("zod").ZodOptional<import("zod").ZodNativeEnum<typeof import("@lyxa.ai/core/dist/utilities/enum").ValueType>>;
|
|
6
|
+
value: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
7
|
+
category: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
8
|
+
products: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
|
|
9
|
+
product: import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>;
|
|
10
|
+
marketing: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
11
|
+
loyaltyPointCategory: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
12
|
+
isBuy1Get1: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodBoolean>>;
|
|
13
|
+
valueType: import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNativeEnum<typeof import("@lyxa.ai/core/dist/utilities/enum").ValueType>>>>;
|
|
14
|
+
value: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
15
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
16
|
+
product: import("mongoose").Types.ObjectId;
|
|
17
|
+
value?: number | undefined;
|
|
18
|
+
marketing?: import("mongoose").Types.ObjectId | undefined;
|
|
19
|
+
loyaltyPointCategory?: import("mongoose").Types.ObjectId | undefined;
|
|
20
|
+
isBuy1Get1?: boolean | undefined;
|
|
21
|
+
valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
product: string | import("mongoose").Types.ObjectId;
|
|
24
|
+
value?: number | undefined;
|
|
25
|
+
marketing?: string | import("mongoose").Types.ObjectId | undefined;
|
|
26
|
+
loyaltyPointCategory?: string | import("mongoose").Types.ObjectId | undefined;
|
|
27
|
+
isBuy1Get1?: boolean | undefined;
|
|
28
|
+
valueType?: import("@lyxa.ai/core/dist/utilities/enum").ValueType | null | undefined;
|
|
29
|
+
}>, "many">>>>;
|
|
30
|
+
spendLimit: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNumber>>;
|
|
31
|
+
shop: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
32
|
+
isAppliedByCompany: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
33
|
+
duration: import("zod").ZodOptional<import("zod").ZodObject<{
|
|
34
|
+
start: import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Date, string>, import("zod").ZodDate]>, Date, string | Date>, Date, string | Date>;
|
|
35
|
+
end: import("zod").ZodOptional<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Date, string>, import("zod").ZodDate]>, Date, string | Date>, Date, string | Date>>;
|
|
36
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
37
|
+
start: Date;
|
|
38
|
+
end?: Date | undefined;
|
|
39
|
+
}, {
|
|
40
|
+
start: string | Date;
|
|
41
|
+
end?: string | Date | undefined;
|
|
42
|
+
}>>;
|
|
43
|
+
status: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNativeEnum<typeof import("@lyxa.ai/core/dist/utilities/enum").MarketingStatus>>>;
|
|
44
|
+
pausedAt: import("zod").ZodOptional<import("zod").ZodDefault<import("zod").ZodNullable<import("zod").ZodOptional<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, Date, string>, import("zod").ZodDate]>, Date, string | Date>, Date, string | Date>>>>>;
|
|
45
|
+
_id: import("zod").ZodOptional<import("zod").ZodUnion<[import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, import("mongoose").Types.ObjectId, string>, import("zod").ZodType<import("mongoose").Types.ObjectId, import("zod").ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
46
|
+
}, import("zod").ZodTypeAny, "passthrough">>;
|
|
47
|
+
//# sourceMappingURL=loyalty-point-marketing.transformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loyalty-point-marketing.transformer.d.ts","sourceRoot":"/","sources":["modules/marketing/transformers/loyalty-point-marketing.transformer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,IAAI,KAAK,EAAE,MAAM,mFAAmF,CAAC;AAMnI,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAAwC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loyaltyPointMarketingTransformer = void 0;
|
|
4
|
+
const transformers_1 = require("@lyxa.ai/core/dist/utilities/transformers");
|
|
5
|
+
const loyalty_point_marketing_validation_1 = require("../../marketing/validations/loyalty-point-marketing.validation");
|
|
6
|
+
exports.loyaltyPointMarketingTransformer = (0, transformers_1.createTransformer)(loyalty_point_marketing_validation_1.LoyaltyPointMarketingSchema);
|
|
7
|
+
//# sourceMappingURL=loyalty-point-marketing.transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loyalty-point-marketing.transformer.js","sourceRoot":"/","sources":["modules/marketing/transformers/loyalty-point-marketing.transformer.ts"],"names":[],"mappings":";;;AAAA,4EAA8E;AAE9E,0HAG2E;AAE9D,QAAA,gCAAgC,GAAG,IAAA,gCAAiB,EAAa,gEAAM,CAAC,CAAC","sourcesContent":["import { createTransformer } from '@lyxa.ai/core/dist/utilities/transformers';\nimport { LoyaltyPointMarketing as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/providers/loyalty-point-marketing.model';\nimport {\n\tLoyaltyPointMarketingSchema as Schema,\n\tLoyaltyPointMarketingDTO as DTO,\n} from '@modules/marketing/validations/loyalty-point-marketing.validation';\n\nexport const loyaltyPointMarketingTransformer = createTransformer<Model, DTO>(Schema);\n"]}
|
|
@@ -25,6 +25,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
25
25
|
valueType?: ValueType | null | undefined;
|
|
26
26
|
}>, "many">>>;
|
|
27
27
|
spendLimit: z.ZodDefault<z.ZodNumber>;
|
|
28
|
+
isSpendLimitEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
28
29
|
isOnlyForSubscriber: z.ZodDefault<z.ZodBoolean>;
|
|
29
30
|
shop: 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>]>;
|
|
30
31
|
isAppliedByCompany: z.ZodBoolean;
|
|
@@ -60,6 +61,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
60
61
|
categories: import("mongoose").Types.ObjectId[];
|
|
61
62
|
isEntireMenu: boolean;
|
|
62
63
|
spendLimit: number;
|
|
64
|
+
isSpendLimitEnabled: boolean;
|
|
63
65
|
isOnlyForSubscriber: boolean;
|
|
64
66
|
}, {
|
|
65
67
|
isAppliedByCompany: boolean;
|
|
@@ -81,6 +83,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
81
83
|
categories?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
82
84
|
isEntireMenu?: boolean | undefined;
|
|
83
85
|
spendLimit?: number | undefined;
|
|
86
|
+
isSpendLimitEnabled?: boolean | undefined;
|
|
84
87
|
isOnlyForSubscriber?: boolean | undefined;
|
|
85
88
|
}>, Buy1Get1MarketingSchema: z.ZodObject<{
|
|
86
89
|
marketingType: z.ZodOptional<z.ZodLiteral<MarketingType.BUY1GET1>>;
|
|
@@ -106,6 +109,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
106
109
|
valueType?: ValueType | null | undefined;
|
|
107
110
|
}>, "many">>>>;
|
|
108
111
|
spendLimit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
112
|
+
isSpendLimitEnabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
109
113
|
isOnlyForSubscriber: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
110
114
|
shop: 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>]>>;
|
|
111
115
|
isAppliedByCompany: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -146,6 +150,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
146
150
|
valueType?: ValueType | null | undefined;
|
|
147
151
|
}>, "many">>>>;
|
|
148
152
|
spendLimit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
153
|
+
isSpendLimitEnabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
149
154
|
isOnlyForSubscriber: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
150
155
|
shop: 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>]>>;
|
|
151
156
|
isAppliedByCompany: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -186,6 +191,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
186
191
|
valueType?: ValueType | null | undefined;
|
|
187
192
|
}>, "many">>>>;
|
|
188
193
|
spendLimit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
194
|
+
isSpendLimitEnabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
189
195
|
isOnlyForSubscriber: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
190
196
|
shop: 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>]>>;
|
|
191
197
|
isAppliedByCompany: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -232,6 +238,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
232
238
|
valueType?: ValueType | null | undefined;
|
|
233
239
|
}>, "many">>>>;
|
|
234
240
|
spendLimit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
241
|
+
isSpendLimitEnabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
235
242
|
isOnlyForSubscriber: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
236
243
|
shop: 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>]>>;
|
|
237
244
|
isAppliedByCompany: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -272,6 +279,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
272
279
|
valueType?: ValueType | null | undefined;
|
|
273
280
|
}>, "many">>>>;
|
|
274
281
|
spendLimit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
282
|
+
isSpendLimitEnabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
275
283
|
isOnlyForSubscriber: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
276
284
|
shop: 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>]>>;
|
|
277
285
|
isAppliedByCompany: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -312,6 +320,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
312
320
|
valueType?: ValueType | null | undefined;
|
|
313
321
|
}>, "many">>>>;
|
|
314
322
|
spendLimit: z.ZodOptional<z.ZodDefault<z.ZodNumber>>;
|
|
323
|
+
isSpendLimitEnabled: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
315
324
|
isOnlyForSubscriber: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
316
325
|
shop: 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>]>>;
|
|
317
326
|
isAppliedByCompany: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -353,6 +362,7 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
353
362
|
valueType?: ValueType | null | undefined;
|
|
354
363
|
}>, "many">>>;
|
|
355
364
|
spendLimit: z.ZodDefault<z.ZodNumber>;
|
|
365
|
+
isSpendLimitEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
356
366
|
isOnlyForSubscriber: z.ZodDefault<z.ZodBoolean>;
|
|
357
367
|
shop: 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>]>;
|
|
358
368
|
isAppliedByCompany: z.ZodBoolean;
|
|
@@ -388,6 +398,7 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
388
398
|
categories: import("mongoose").Types.ObjectId[];
|
|
389
399
|
isEntireMenu: boolean;
|
|
390
400
|
spendLimit: number;
|
|
401
|
+
isSpendLimitEnabled: boolean;
|
|
391
402
|
isOnlyForSubscriber: boolean;
|
|
392
403
|
}, {
|
|
393
404
|
isAppliedByCompany: boolean;
|
|
@@ -409,6 +420,7 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
409
420
|
categories?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
410
421
|
isEntireMenu?: boolean | undefined;
|
|
411
422
|
spendLimit?: number | undefined;
|
|
423
|
+
isSpendLimitEnabled?: boolean | undefined;
|
|
412
424
|
isOnlyForSubscriber?: boolean | undefined;
|
|
413
425
|
}>, {
|
|
414
426
|
isAppliedByCompany: boolean;
|
|
@@ -430,6 +442,7 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
430
442
|
categories: import("mongoose").Types.ObjectId[];
|
|
431
443
|
isEntireMenu: boolean;
|
|
432
444
|
spendLimit: number;
|
|
445
|
+
isSpendLimitEnabled: boolean;
|
|
433
446
|
isOnlyForSubscriber: boolean;
|
|
434
447
|
}, {
|
|
435
448
|
isAppliedByCompany: boolean;
|
|
@@ -451,6 +464,7 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
451
464
|
categories?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
452
465
|
isEntireMenu?: boolean | undefined;
|
|
453
466
|
spendLimit?: number | undefined;
|
|
467
|
+
isSpendLimitEnabled?: boolean | undefined;
|
|
454
468
|
isOnlyForSubscriber?: boolean | undefined;
|
|
455
469
|
}>;
|
|
456
470
|
export { Buy1Get1MarketingValidationSchemaRefined as Buy1Get1MarketingValidationSchema, Buy1Get1MarketingSchema, Buy1Get1MarketingIdSchema as Buy1Get1MarketingIdValidationSchema, UpdateBuy1Get1MarketingSchema, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buy1-get1-marketing.validation.d.ts","sourceRoot":"/","sources":["modules/marketing/validations/buy1-get1-marketing.validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGN,GAAG,EACH,MAAM,2DAA2D,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"buy1-get1-marketing.validation.d.ts","sourceRoot":"/","sources":["modules/marketing/validations/buy1-get1-marketing.validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGN,GAAG,EACH,MAAM,2DAA2D,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AA2B7E,QAAA,MACa,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAC/B,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAC3B,yBAAyB,mNACrB,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCACQ,CAAC;AAErD,QAAA,MAAM,wCAAwC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2B7C,CAAC;AAKF,OAAO,EACN,wCAAwC,IAAI,iCAAiC,EAC7E,uBAAuB,EACvB,yBAAyB,IAAI,mCAAmC,EAChE,6BAA6B,GAC7B,CAAC;AAKF,MAAM,MAAM,0BAA0B,GAAG,GAAG,CAAC,OAAO,iCAAiC,CAAC,CAAC;AACvF,MAAM,MAAM,oBAAoB,GAAG,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACvE,MAAM,MAAM,0BAA0B,GAAG,GAAG,CAAC,OAAO,6BAA6B,CAAC,CAAC"}
|
|
@@ -13,6 +13,7 @@ const baseFields = {
|
|
|
13
13
|
isEntireMenu: global_validation_1.ZodValidation.boolean('IsEntireMenu').default(false),
|
|
14
14
|
products: global_validation_1.ZodValidation.array(zod_1.z.object(product_marketing_validation_1.baseFields), "Products").optional().default([]),
|
|
15
15
|
spendLimit: global_validation_1.ZodValidation.number('Spend limit').default(0),
|
|
16
|
+
isSpendLimitEnabled: global_validation_1.ZodValidation.boolean('Is spend limit enabled').default(false),
|
|
16
17
|
isOnlyForSubscriber: global_validation_1.ZodValidation.boolean('IsOnlyForSubscriber').default(false),
|
|
17
18
|
};
|
|
18
19
|
const schemaBuilder = (0, global_validation_1.createSchemaBuilder)(baseFields);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buy1-get1-marketing.validation.js","sourceRoot":"/","sources":["modules/marketing/validations/buy1-get1-marketing.validation.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,iEAA6D;AAC7D,4DAA6E;AAC7E,iFAA0F;AAK1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,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,iDAAiD;YAC1D,IAAI,EAAE,CAAC,YAAY,EAAE,cAAc,CAAC;SACpC,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;QACnD,GAAG,CAAC,QAAQ,CAAC;YACZ,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,+CAA+C;YACxD,IAAI,EAAE,CAAC,UAAU,EAAE,cAAc,CAAC;SAClC,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClF,GAAG,CAAC,QAAQ,CAAC;YACZ,IAAI,EAAE,OAAC,CAAC,YAAY,CAAC,MAAM;YAC3B,OAAO,EAAE,6DAA6D;YACtE,IAAI,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,cAAc,CAAC;SAChD,CAAC,CAAC;IACJ,CAAC;AACF,CAAC,CACD,CAAC;AAM2C,qFAAiC","sourcesContent":["import { z } from 'zod';\nimport {\n\tZodValidation,\n\tcreateSchemaBuilder,\n\tDTO\n} from '@lyxa.ai/core/dist/utilities/validation/global-validation';\nimport { baseMarketingFields } from './marketing.validation';\nimport { MarketingType, ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { baseFields as baseProductMarketingFields } from './product-marketing.validation';\n\n/**\n * Define the base parent schema fields\n */\nconst baseFields = {\n\t...baseMarketingFields,\n\tmarketingType: z.literal(MarketingType.BUY1GET1),\n\tcategories: ZodValidation.array(ZodValidation.objectId('Category'), 'Categories').optional().default([]),\n\tisEntireMenu: ZodValidation.boolean('IsEntireMenu').default(false),\n\tproducts: ZodValidation.array(z.object(baseProductMarketingFields), \"Products\").optional().default([]),\n\tspendLimit: ZodValidation.number('Spend limit').default(0),\n\tisOnlyForSubscriber: ZodValidation.boolean('IsOnlyForSubscriber').default(false),\n};\n\n/**\n * Create schema builder for Parent entity\n * - Includes timestamps\n * - Excludes 'createdAt' from update operations\n */\nconst schemaBuilder = createSchemaBuilder(baseFields);\n\n/**\n * Get all schemas for the Parent entity\n */\nconst {\n\tBaseSchema: Buy1Get1MarketingValidationSchema,\n\tEntitySchema: Buy1Get1MarketingSchema,\n\tIdSchema: Buy1Get1MarketingIdSchema,\n\tUpdateSchema: UpdateBuy1Get1MarketingSchema,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\nconst Buy1Get1MarketingValidationSchemaRefined = Buy1Get1MarketingValidationSchema.superRefine(\n\t(data, ctx) => {\n\n\t\tif (data.categories.length > 0 && data.isEntireMenu) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Please provide either categories or entire menu',\n\t\t\t\tpath: ['categories', 'isEntireMenu'],\n\t\t\t});\n\t\t}\n\n\t\tif (data.products.length > 0 && data.isEntireMenu) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Please provide either products or entire menu',\n\t\t\t\tpath: ['products', 'isEntireMenu'],\n\t\t\t});\n\t\t}\n\n\t\tif (data.categories.length < 1 && data.products.length < 1 && !data.isEntireMenu) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Please provide either categories or products or entire menu',\n\t\t\t\tpath: ['categories', 'products', 'isEntireMenu'],\n\t\t\t});\n\t\t}\n\t}\n);\n\n/**\n * Export schemas\n */\nexport {\n\tBuy1Get1MarketingValidationSchemaRefined as Buy1Get1MarketingValidationSchema,\n\tBuy1Get1MarketingSchema,\n\tBuy1Get1MarketingIdSchema as Buy1Get1MarketingIdValidationSchema,\n\tUpdateBuy1Get1MarketingSchema,\n};\n\n/**\n * Export DTO types\n */\nexport type CreateBuy1Get1MarketingDTO = DTO<typeof Buy1Get1MarketingValidationSchema>;\nexport type Buy1Get1MarketingDTO = DTO<typeof Buy1Get1MarketingSchema>;\nexport type UpdateBuy1Get1MarketingDTO = DTO<typeof UpdateBuy1Get1MarketingSchema>;\n"]}
|
|
1
|
+
{"version":3,"file":"buy1-get1-marketing.validation.js","sourceRoot":"/","sources":["modules/marketing/validations/buy1-get1-marketing.validation.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,iEAA6D;AAC7D,4DAA6E;AAC7E,iFAA0F;AAK1F,MAAM,UAAU,GAAG;IAClB,GAAG,0CAAmB;IACtB,aAAa,EAAE,OAAC,CAAC,OAAO,CAAC,oBAAa,CAAC,QAAQ,CAAC;IAChD,UAAU,EAAE,iCAAa,CAAC,KAAK,CAAC,iCAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IACxG,YAAY,EAAE,iCAAa,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAClE,QAAQ,EAAE,iCAAa,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,CAAC,yCAA0B,CAAC,EAAE,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IACtG,UAAU,EAAE,iCAAa,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,mBAAmB,EAAE,iCAAa,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IACnF,mBAAmB,EAAE,iCAAa,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;CAChF,CAAC;AAOF,MAAM,aAAa,GAAG,IAAA,uCAAmB,EAAC,UAAU,CAAC,CAAC;AAKtD,MAAM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,CAAC;AAM2C,qFAAiC","sourcesContent":["import { z } from 'zod';\nimport {\n\tZodValidation,\n\tcreateSchemaBuilder,\n\tDTO\n} from '@lyxa.ai/core/dist/utilities/validation/global-validation';\nimport { baseMarketingFields } from './marketing.validation';\nimport { MarketingType, ValueType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { baseFields as baseProductMarketingFields } from './product-marketing.validation';\n\n/**\n * Define the base parent schema fields\n */\nconst baseFields = {\n\t...baseMarketingFields,\n\tmarketingType: z.literal(MarketingType.BUY1GET1),\n\tcategories: ZodValidation.array(ZodValidation.objectId('Category'), 'Categories').optional().default([]),\n\tisEntireMenu: ZodValidation.boolean('IsEntireMenu').default(false),\n\tproducts: ZodValidation.array(z.object(baseProductMarketingFields), \"Products\").optional().default([]),\n\tspendLimit: ZodValidation.number('Spend limit').default(0),\n\tisSpendLimitEnabled: ZodValidation.boolean('Is spend limit enabled').default(false),\n\tisOnlyForSubscriber: ZodValidation.boolean('IsOnlyForSubscriber').default(false),\n};\n\n/**\n * Create schema builder for Parent entity\n * - Includes timestamps\n * - Excludes 'createdAt' from update operations\n */\nconst schemaBuilder = createSchemaBuilder(baseFields);\n\n/**\n * Get all schemas for the Parent entity\n */\nconst {\n\tBaseSchema: Buy1Get1MarketingValidationSchema,\n\tEntitySchema: Buy1Get1MarketingSchema,\n\tIdSchema: Buy1Get1MarketingIdSchema,\n\tUpdateSchema: UpdateBuy1Get1MarketingSchema,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\nconst Buy1Get1MarketingValidationSchemaRefined = Buy1Get1MarketingValidationSchema.superRefine(\n\t(data, ctx) => {\n\n\t\tif (data.categories.length > 0 && data.isEntireMenu) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Please provide either categories or entire menu',\n\t\t\t\tpath: ['categories', 'isEntireMenu'],\n\t\t\t});\n\t\t}\n\n\t\tif (data.products.length > 0 && data.isEntireMenu) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Please provide either products or entire menu',\n\t\t\t\tpath: ['products', 'isEntireMenu'],\n\t\t\t});\n\t\t}\n\n\t\tif (data.categories.length < 1 && data.products.length < 1 && !data.isEntireMenu) {\n\t\t\tctx.addIssue({\n\t\t\t\tcode: z.ZodIssueCode.custom,\n\t\t\t\tmessage: 'Please provide either categories or products or entire menu',\n\t\t\t\tpath: ['categories', 'products', 'isEntireMenu'],\n\t\t\t});\n\t\t}\n\t}\n);\n\n/**\n * Export schemas\n */\nexport {\n\tBuy1Get1MarketingValidationSchemaRefined as Buy1Get1MarketingValidationSchema,\n\tBuy1Get1MarketingSchema,\n\tBuy1Get1MarketingIdSchema as Buy1Get1MarketingIdValidationSchema,\n\tUpdateBuy1Get1MarketingSchema,\n};\n\n/**\n * Export DTO types\n */\nexport type CreateBuy1Get1MarketingDTO = DTO<typeof Buy1Get1MarketingValidationSchema>;\nexport type Buy1Get1MarketingDTO = DTO<typeof Buy1Get1MarketingSchema>;\nexport type UpdateBuy1Get1MarketingDTO = DTO<typeof UpdateBuy1Get1MarketingSchema>;\n"]}
|