@medusajs/promotion 0.0.6 → 1.0.0-rc-20241001083650
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -20
- package/dist/index.js.map +1 -0
- package/dist/joiner-config.d.ts +1 -8
- package/dist/joiner-config.d.ts.map +1 -1
- package/dist/joiner-config.js +11 -36
- package/dist/joiner-config.js.map +1 -0
- package/dist/migrations/Migration20240227120221.d.ts.map +1 -1
- package/dist/migrations/Migration20240227120221.js +11 -2
- package/dist/migrations/Migration20240227120221.js.map +1 -0
- package/dist/migrations/Migration20240617102917.d.ts +6 -0
- package/dist/migrations/Migration20240617102917.d.ts.map +1 -0
- package/dist/migrations/Migration20240617102917.js +16 -0
- package/dist/migrations/Migration20240617102917.js.map +1 -0
- package/dist/migrations/Migration20240624153824.d.ts +6 -0
- package/dist/migrations/Migration20240624153824.d.ts.map +1 -0
- package/dist/migrations/Migration20240624153824.js +16 -0
- package/dist/migrations/Migration20240624153824.js.map +1 -0
- package/dist/models/application-method.d.ts +5 -7
- package/dist/models/application-method.d.ts.map +1 -1
- package/dist/models/application-method.js +18 -7
- package/dist/models/application-method.js.map +1 -0
- package/dist/models/campaign-budget.d.ts +8 -7
- package/dist/models/campaign-budget.d.ts.map +1 -1
- package/dist/models/campaign-budget.js +10 -5
- package/dist/models/campaign-budget.js.map +1 -0
- package/dist/models/campaign.d.ts +4 -5
- package/dist/models/campaign.d.ts.map +1 -1
- package/dist/models/campaign.js +12 -14
- package/dist/models/campaign.js.map +1 -0
- package/dist/models/index.js +1 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/promotion-rule-value.d.ts +2 -1
- package/dist/models/promotion-rule-value.d.ts.map +1 -1
- package/dist/models/promotion-rule-value.js +3 -2
- package/dist/models/promotion-rule-value.js.map +1 -0
- package/dist/models/promotion-rule.d.ts +2 -2
- package/dist/models/promotion-rule.d.ts.map +1 -1
- package/dist/models/promotion-rule.js +2 -1
- package/dist/models/promotion-rule.js.map +1 -0
- package/dist/models/promotion.d.ts +6 -5
- package/dist/models/promotion.d.ts.map +1 -1
- package/dist/models/promotion.js +10 -5
- package/dist/models/promotion.js.map +1 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +99 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/promotion-module.d.ts +41 -26
- package/dist/services/promotion-module.d.ts.map +1 -1
- package/dist/services/promotion-module.js +293 -100
- package/dist/services/promotion-module.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/application-method.d.ts +12 -10
- package/dist/types/application-method.d.ts.map +1 -1
- package/dist/types/application-method.js +1 -0
- package/dist/types/application-method.js.map +1 -0
- package/dist/types/campaign-budget.d.ts +8 -6
- package/dist/types/campaign-budget.d.ts.map +1 -1
- package/dist/types/campaign-budget.js +1 -0
- package/dist/types/campaign-budget.js.map +1 -0
- package/dist/types/campaign.d.ts +7 -9
- package/dist/types/campaign.d.ts.map +1 -1
- package/dist/types/campaign.js +1 -0
- package/dist/types/campaign.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/promotion-rule-value.d.ts +1 -1
- package/dist/types/promotion-rule-value.d.ts.map +1 -1
- package/dist/types/promotion-rule-value.js +1 -0
- package/dist/types/promotion-rule-value.js.map +1 -0
- package/dist/types/promotion-rule.d.ts +1 -1
- package/dist/types/promotion-rule.d.ts.map +1 -1
- package/dist/types/promotion-rule.js +1 -0
- package/dist/types/promotion-rule.js.map +1 -0
- package/dist/types/promotion.d.ts +3 -3
- package/dist/types/promotion.d.ts.map +1 -1
- package/dist/types/promotion.js +1 -0
- package/dist/types/promotion.js.map +1 -0
- package/dist/utils/compute-actions/buy-get.d.ts +6 -3
- package/dist/utils/compute-actions/buy-get.d.ts.map +1 -1
- package/dist/utils/compute-actions/buy-get.js +98 -34
- package/dist/utils/compute-actions/buy-get.js.map +1 -0
- package/dist/utils/compute-actions/index.js +1 -0
- package/dist/utils/compute-actions/index.js.map +1 -0
- package/dist/utils/compute-actions/line-items.d.ts +2 -2
- package/dist/utils/compute-actions/line-items.d.ts.map +1 -1
- package/dist/utils/compute-actions/line-items.js +10 -10
- package/dist/utils/compute-actions/line-items.js.map +1 -0
- package/dist/utils/compute-actions/shipping-methods.d.ts +3 -3
- package/dist/utils/compute-actions/shipping-methods.d.ts.map +1 -1
- package/dist/utils/compute-actions/shipping-methods.js +20 -22
- package/dist/utils/compute-actions/shipping-methods.js.map +1 -0
- package/dist/utils/compute-actions/usage.d.ts +2 -3
- package/dist/utils/compute-actions/usage.d.ts.map +1 -1
- package/dist/utils/compute-actions/usage.js +6 -13
- package/dist/utils/compute-actions/usage.js.map +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/validations/application-method.d.ts.map +1 -1
- package/dist/utils/validations/application-method.js +6 -5
- package/dist/utils/validations/application-method.js.map +1 -0
- package/dist/utils/validations/index.js +1 -0
- package/dist/utils/validations/index.js.map +1 -0
- package/dist/utils/validations/promotion-rule.d.ts +2 -2
- package/dist/utils/validations/promotion-rule.d.ts.map +1 -1
- package/dist/utils/validations/promotion-rule.js +27 -7
- package/dist/utils/validations/promotion-rule.js.map +1 -0
- package/package.json +20 -21
- package/dist/initialize/index.d.ts +0 -5
- package/dist/initialize/index.d.ts.map +0 -1
- package/dist/initialize/index.js +0 -16
- package/dist/loaders/connection.d.ts +0 -5
- package/dist/loaders/connection.d.ts.map +0 -1
- package/dist/loaders/connection.js +0 -41
- package/dist/loaders/container.d.ts +0 -3
- package/dist/loaders/container.d.ts.map +0 -1
- package/dist/loaders/container.js +0 -34
- package/dist/loaders/index.d.ts +0 -3
- package/dist/loaders/index.d.ts.map +0 -1
- package/dist/loaders/index.js +0 -18
- package/dist/module-definition.d.ts +0 -5
- package/dist/module-definition.d.ts.map +0 -1
- package/dist/module-definition.js +0 -50
- package/dist/repositories/campaign.d.ts +0 -16
- package/dist/repositories/campaign.d.ts.map +0 -1
- package/dist/repositories/campaign.js +0 -90
- package/dist/repositories/index.d.ts +0 -3
- package/dist/repositories/index.d.ts.map +0 -1
- package/dist/repositories/index.js +0 -7
@@ -12,20 +12,20 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
const types_1 = require("@medusajs/types");
|
16
|
-
const utils_1 = require("@medusajs/utils");
|
15
|
+
const types_1 = require("@medusajs/framework/types");
|
16
|
+
const utils_1 = require("@medusajs/framework/utils");
|
17
17
|
const _models_1 = require("../models");
|
18
18
|
const _types_1 = require("../types");
|
19
19
|
const _utils_1 = require("../utils");
|
20
20
|
const joiner_config_1 = require("../joiner-config");
|
21
|
-
|
22
|
-
_models_1.
|
23
|
-
_models_1.
|
24
|
-
_models_1.
|
25
|
-
_models_1.
|
26
|
-
_models_1.
|
27
|
-
|
28
|
-
|
21
|
+
class PromotionModuleService extends (0, utils_1.MedusaService)({
|
22
|
+
Promotion: _models_1.Promotion,
|
23
|
+
ApplicationMethod: _models_1.ApplicationMethod,
|
24
|
+
Campaign: _models_1.Campaign,
|
25
|
+
CampaignBudget: _models_1.CampaignBudget,
|
26
|
+
PromotionRule: _models_1.PromotionRule,
|
27
|
+
PromotionRuleValue: _models_1.PromotionRuleValue,
|
28
|
+
}) {
|
29
29
|
constructor({ baseRepository, promotionService, applicationMethodService, promotionRuleService, promotionRuleValueService, campaignService, campaignBudgetService, }, moduleDeclaration) {
|
30
30
|
// @ts-ignore
|
31
31
|
super(...arguments);
|
@@ -45,14 +45,18 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
45
45
|
const promotionCodes = computedActions
|
46
46
|
.map((computedAction) => computedAction.code)
|
47
47
|
.filter(Boolean);
|
48
|
-
const
|
48
|
+
const campaignBudgetMap = new Map();
|
49
49
|
const promotionCodeUsageMap = new Map();
|
50
|
-
const existingPromotions = await this.
|
50
|
+
const existingPromotions = await this.listPromotions({ code: promotionCodes }, {
|
51
|
+
relations: ["campaign", "campaign.budget"],
|
52
|
+
}, sharedContext);
|
53
|
+
for (const promotion of existingPromotions) {
|
54
|
+
if (promotion.campaign?.budget) {
|
55
|
+
campaignBudgetMap.set(promotion.campaign?.budget.id, promotion.campaign?.budget);
|
56
|
+
}
|
57
|
+
}
|
51
58
|
const existingPromotionsMap = new Map(existingPromotions.map((promotion) => [promotion.code, promotion]));
|
52
59
|
for (let computedAction of computedActions) {
|
53
|
-
if (!_utils_1.ComputeActionUtils.canRegisterUsage(computedAction)) {
|
54
|
-
continue;
|
55
|
-
}
|
56
60
|
const promotion = existingPromotionsMap.get(computedAction.code);
|
57
61
|
if (!promotion) {
|
58
62
|
continue;
|
@@ -62,14 +66,16 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
62
66
|
continue;
|
63
67
|
}
|
64
68
|
if (campaignBudget.type === utils_1.CampaignBudgetType.SPEND) {
|
65
|
-
const campaignBudgetData =
|
66
|
-
campaignBudgetData
|
67
|
-
|
69
|
+
const campaignBudgetData = campaignBudgetMap.get(campaignBudget.id);
|
70
|
+
if (!campaignBudgetData) {
|
71
|
+
continue;
|
72
|
+
}
|
73
|
+
campaignBudgetData.used = utils_1.MathBN.add(campaignBudgetData.used ?? 0, computedAction.amount);
|
68
74
|
if (campaignBudget.limit &&
|
69
|
-
campaignBudgetData.used
|
75
|
+
utils_1.MathBN.gt(campaignBudgetData.used, campaignBudget.limit)) {
|
70
76
|
continue;
|
71
77
|
}
|
72
|
-
|
78
|
+
campaignBudgetMap.set(campaignBudget.id, campaignBudgetData);
|
73
79
|
}
|
74
80
|
if (campaignBudget.type === utils_1.CampaignBudgetType.USAGE) {
|
75
81
|
const promotionAlreadyUsed = promotionCodeUsageMap.get(promotion.code) || false;
|
@@ -78,17 +84,68 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
78
84
|
}
|
79
85
|
const campaignBudgetData = {
|
80
86
|
id: campaignBudget.id,
|
81
|
-
used: (campaignBudget.used ?? 0
|
87
|
+
used: utils_1.MathBN.add(campaignBudget.used ?? 0, 1),
|
82
88
|
};
|
83
89
|
if (campaignBudget.limit &&
|
84
|
-
campaignBudgetData.used
|
90
|
+
utils_1.MathBN.gt(campaignBudgetData.used, campaignBudget.limit)) {
|
91
|
+
continue;
|
92
|
+
}
|
93
|
+
campaignBudgetMap.set(campaignBudget.id, campaignBudgetData);
|
94
|
+
promotionCodeUsageMap.set(promotion.code, true);
|
95
|
+
}
|
96
|
+
const campaignBudgetsData = [];
|
97
|
+
for (const [_, campaignBudgetData] of campaignBudgetMap) {
|
98
|
+
campaignBudgetsData.push(campaignBudgetData);
|
99
|
+
}
|
100
|
+
await this.campaignBudgetService_.update(campaignBudgetsData, sharedContext);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
async revertUsage(computedActions, sharedContext = {}) {
|
104
|
+
const promotionCodeUsageMap = new Map();
|
105
|
+
const campaignBudgetMap = new Map();
|
106
|
+
const existingPromotions = await this.listPromotions({
|
107
|
+
code: computedActions
|
108
|
+
.map((computedAction) => computedAction.code)
|
109
|
+
.filter(Boolean),
|
110
|
+
}, {
|
111
|
+
relations: ["campaign", "campaign.budget"],
|
112
|
+
}, sharedContext);
|
113
|
+
for (const promotion of existingPromotions) {
|
114
|
+
if (promotion.campaign?.budget) {
|
115
|
+
campaignBudgetMap.set(promotion.campaign?.budget.id, promotion.campaign?.budget);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
const existingPromotionsMap = new Map(existingPromotions.map((promotion) => [promotion.code, promotion]));
|
119
|
+
for (let computedAction of computedActions) {
|
120
|
+
const promotion = existingPromotionsMap.get(computedAction.code);
|
121
|
+
if (!promotion) {
|
122
|
+
continue;
|
123
|
+
}
|
124
|
+
const campaignBudget = promotion.campaign?.budget;
|
125
|
+
if (!campaignBudget) {
|
126
|
+
continue;
|
127
|
+
}
|
128
|
+
if (campaignBudget.type === utils_1.CampaignBudgetType.SPEND) {
|
129
|
+
const campaignBudgetData = campaignBudgetMap.get(campaignBudget.id);
|
130
|
+
if (!campaignBudgetData) {
|
131
|
+
continue;
|
132
|
+
}
|
133
|
+
campaignBudgetData.used = utils_1.MathBN.sub(campaignBudgetData.used ?? 0, computedAction.amount);
|
134
|
+
campaignBudgetMap.set(campaignBudget.id, campaignBudgetData);
|
135
|
+
}
|
136
|
+
if (campaignBudget.type === utils_1.CampaignBudgetType.USAGE) {
|
137
|
+
const promotionAlreadyUsed = promotionCodeUsageMap.get(promotion.code) || false;
|
138
|
+
if (promotionAlreadyUsed) {
|
85
139
|
continue;
|
86
140
|
}
|
87
|
-
|
141
|
+
campaignBudgetMap.set(campaignBudget.id, {
|
142
|
+
id: campaignBudget.id,
|
143
|
+
used: utils_1.MathBN.sub(campaignBudget.used ?? 0, 1),
|
144
|
+
});
|
88
145
|
promotionCodeUsageMap.set(promotion.code, true);
|
89
146
|
}
|
90
147
|
const campaignBudgetsData = [];
|
91
|
-
for (const [_, campaignBudgetData] of
|
148
|
+
for (const [_, campaignBudgetData] of campaignBudgetMap) {
|
92
149
|
campaignBudgetsData.push(campaignBudgetData);
|
93
150
|
}
|
94
151
|
await this.campaignBudgetService_.update(campaignBudgetsData, sharedContext);
|
@@ -102,9 +159,13 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
102
159
|
const appliedShippingCodes = [];
|
103
160
|
const codeAdjustmentMap = new Map();
|
104
161
|
const methodIdPromoValueMap = new Map();
|
162
|
+
// Keeps a map of all elgible items in the buy section and its eligible quantity
|
163
|
+
const eligibleBuyItemMap = new Map();
|
164
|
+
// Keeps a map of all elgible items in the target section and its eligible quantity
|
165
|
+
const eligibleTargetItemMap = new Map();
|
105
166
|
const automaticPromotions = preventAutoPromotions
|
106
167
|
? []
|
107
|
-
: await this.
|
168
|
+
: await this.listPromotions({ is_automatic: true }, { select: ["code"] }, sharedContext);
|
108
169
|
// Promotions we need to apply includes all the codes that are passed as an argument
|
109
170
|
// to this method, along with any automatic promotions that can be applied to the context
|
110
171
|
const automaticPromotionCodes = automaticPromotions.map((p) => p.code);
|
@@ -132,7 +193,7 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
132
193
|
}
|
133
194
|
});
|
134
195
|
});
|
135
|
-
const promotions = await this.
|
196
|
+
const promotions = await this.listPromotions({
|
136
197
|
code: [
|
137
198
|
...promotionCodesToApply,
|
138
199
|
...appliedItemCodes,
|
@@ -150,7 +211,6 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
150
211
|
"campaign",
|
151
212
|
"campaign.budget",
|
152
213
|
],
|
153
|
-
take: null,
|
154
214
|
});
|
155
215
|
const existingPromotionsMap = new Map(promotions.map((promotion) => [promotion.code, promotion]));
|
156
216
|
// We look at any existing promo codes applied in the context and recommend
|
@@ -183,12 +243,12 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
183
243
|
if (!applicationMethod) {
|
184
244
|
continue;
|
185
245
|
}
|
186
|
-
const isPromotionApplicable = (0, _utils_1.areRulesValidForContext)(promotionRules, applicationContext);
|
246
|
+
const isPromotionApplicable = (0, _utils_1.areRulesValidForContext)(promotionRules, applicationContext, utils_1.ApplicationMethodTargetType.ORDER);
|
187
247
|
if (!isPromotionApplicable) {
|
188
248
|
continue;
|
189
249
|
}
|
190
250
|
if (promotion.type === utils_1.PromotionType.BUYGET) {
|
191
|
-
const computedActionsForItems = _utils_1.ComputeActionUtils.getComputedActionsForBuyGet(promotion, applicationContext[utils_1.ApplicationMethodTargetType.ITEMS], methodIdPromoValueMap);
|
251
|
+
const computedActionsForItems = _utils_1.ComputeActionUtils.getComputedActionsForBuyGet(promotion, applicationContext[utils_1.ApplicationMethodTargetType.ITEMS], methodIdPromoValueMap, eligibleBuyItemMap, eligibleTargetItemMap);
|
192
252
|
computedActions.push(...computedActionsForItems);
|
193
253
|
}
|
194
254
|
if (promotion.type === utils_1.PromotionType.STANDARD) {
|
@@ -209,12 +269,13 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
209
269
|
}
|
210
270
|
}
|
211
271
|
}
|
272
|
+
(0, utils_1.transformPropertiesToBigNumber)(computedActions, { include: ["amount"] });
|
212
273
|
return computedActions;
|
213
274
|
}
|
214
|
-
async
|
275
|
+
async createPromotions(data, sharedContext = {}) {
|
215
276
|
const input = Array.isArray(data) ? data : [data];
|
216
|
-
const createdPromotions = await this.
|
217
|
-
const promotions = await this.
|
277
|
+
const createdPromotions = await this.createPromotions_(input, sharedContext);
|
278
|
+
const promotions = await this.listPromotions({ id: createdPromotions.map((p) => p.id) }, {
|
218
279
|
relations: [
|
219
280
|
"application_method",
|
220
281
|
"application_method.target_rules",
|
@@ -226,35 +287,48 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
226
287
|
"campaign",
|
227
288
|
"campaign.budget",
|
228
289
|
],
|
229
|
-
take: null,
|
230
290
|
}, sharedContext);
|
231
291
|
return Array.isArray(data) ? promotions : promotions[0];
|
232
292
|
}
|
233
|
-
async
|
293
|
+
async createPromotions_(data, sharedContext = {}) {
|
234
294
|
const promotionsData = [];
|
235
295
|
const applicationMethodsData = [];
|
236
296
|
const campaignsData = [];
|
297
|
+
const existingCampaigns = await this.campaignService_.list({ id: data.map((d) => d.campaign_id).filter((id) => (0, utils_1.isString)(id)) }, { relations: ["budget"] }, sharedContext);
|
237
298
|
const promotionCodeApplicationMethodDataMap = new Map();
|
238
299
|
const promotionCodeRulesDataMap = new Map();
|
239
300
|
const methodTargetRulesMap = new Map();
|
240
301
|
const methodBuyRulesMap = new Map();
|
241
302
|
const promotionCodeCampaignMap = new Map();
|
242
303
|
for (const { application_method: applicationMethodData, rules: rulesData, campaign: campaignData, campaign_id: campaignId, ...promotionData } of data) {
|
243
|
-
|
244
|
-
promotionCodeApplicationMethodDataMap.set(promotionData.code, applicationMethodData);
|
245
|
-
}
|
304
|
+
promotionCodeApplicationMethodDataMap.set(promotionData.code, applicationMethodData);
|
246
305
|
if (rulesData) {
|
247
306
|
promotionCodeRulesDataMap.set(promotionData.code, rulesData);
|
248
307
|
}
|
249
308
|
if (campaignData && campaignId) {
|
250
309
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Provide either the 'campaign' or 'campaign_id' parameter; both cannot be used simultaneously.`);
|
251
310
|
}
|
311
|
+
if (!campaignData && !campaignId) {
|
312
|
+
promotionsData.push({ ...promotionData });
|
313
|
+
continue;
|
314
|
+
}
|
315
|
+
const existingCampaign = existingCampaigns.find((c) => c.id === campaignId);
|
316
|
+
if (campaignId && !existingCampaign) {
|
317
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Could not find campaign with id - ${campaignId}`);
|
318
|
+
}
|
319
|
+
const campaignCurrency = campaignData?.budget?.currency_code ||
|
320
|
+
existingCampaigns.find((c) => c.id === campaignId)?.budget
|
321
|
+
?.currency_code;
|
322
|
+
if (campaignData?.budget?.type === utils_1.CampaignBudgetType.SPEND &&
|
323
|
+
campaignCurrency !== applicationMethodData?.currency_code) {
|
324
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Currency between promotion and campaigns should match`);
|
325
|
+
}
|
252
326
|
if (campaignData) {
|
253
327
|
promotionCodeCampaignMap.set(promotionData.code, campaignData);
|
254
328
|
}
|
255
329
|
promotionsData.push({
|
256
330
|
...promotionData,
|
257
|
-
|
331
|
+
campaign_id: campaignId,
|
258
332
|
});
|
259
333
|
}
|
260
334
|
const createdPromotions = await this.promotionService_.create(promotionsData, sharedContext);
|
@@ -297,8 +371,14 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
297
371
|
await this.createPromotionRulesAndValues_(promotionCodeRulesDataMap.get(promotion.code) || [], "promotions", promotion, sharedContext);
|
298
372
|
}
|
299
373
|
const createdApplicationMethods = await this.applicationMethodService_.create(applicationMethodsData, sharedContext);
|
300
|
-
|
301
|
-
|
374
|
+
const createdCampaigns = await this.createCampaigns(campaignsData, sharedContext);
|
375
|
+
for (const campaignData of campaignsData) {
|
376
|
+
const promotions = campaignData.promotions;
|
377
|
+
const campaign = createdCampaigns.find((c) => c.campaign_identifier === campaignData.campaign_identifier);
|
378
|
+
if (!campaign || !promotions || !promotions.length) {
|
379
|
+
continue;
|
380
|
+
}
|
381
|
+
await this.addPromotionsToCampaign({ id: campaign.id, promotion_ids: promotions.map((p) => p.id) }, sharedContext);
|
302
382
|
}
|
303
383
|
for (const applicationMethod of createdApplicationMethods) {
|
304
384
|
await this.createPromotionRulesAndValues_(methodTargetRulesMap.get(applicationMethod.promotion.id) || [], "method_target_rules", applicationMethod, sharedContext);
|
@@ -306,10 +386,10 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
306
386
|
}
|
307
387
|
return createdPromotions;
|
308
388
|
}
|
309
|
-
async
|
389
|
+
async updatePromotions(data, sharedContext = {}) {
|
310
390
|
const input = Array.isArray(data) ? data : [data];
|
311
|
-
const updatedPromotions = await this.
|
312
|
-
const promotions = await this.
|
391
|
+
const updatedPromotions = await this.updatePromotions_(input, sharedContext);
|
392
|
+
const promotions = await this.listPromotions({ id: updatedPromotions.map((p) => p.id) }, {
|
313
393
|
relations: [
|
314
394
|
"application_method",
|
315
395
|
"application_method.target_rules",
|
@@ -319,29 +399,37 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
319
399
|
"campaign",
|
320
400
|
"campaign.budget",
|
321
401
|
],
|
322
|
-
take: null,
|
323
402
|
}, sharedContext);
|
324
403
|
return Array.isArray(data) ? promotions : promotions[0];
|
325
404
|
}
|
326
|
-
async
|
405
|
+
async updatePromotions_(data, sharedContext = {}) {
|
327
406
|
const promotionIds = data.map((d) => d.id);
|
328
407
|
const existingPromotions = await this.promotionService_.list({ id: promotionIds }, { relations: ["application_method"] });
|
408
|
+
const existingCampaigns = await this.campaignService_.list({ id: data.map((d) => d.campaign_id).filter((d) => (0, utils_1.isPresent)(d)) }, { relations: ["budget"] });
|
329
409
|
const existingPromotionsMap = new Map(existingPromotions.map((promotion) => [promotion.id, promotion]));
|
330
410
|
const promotionsData = [];
|
331
411
|
const applicationMethodsData = [];
|
332
412
|
for (const { application_method: applicationMethodData, campaign_id: campaignId, ...promotionData } of data) {
|
333
|
-
|
334
|
-
|
413
|
+
const existingCampaign = existingCampaigns.find((c) => c.id === campaignId);
|
414
|
+
const existingPromotion = existingPromotionsMap.get(promotionData.id);
|
415
|
+
const existingApplicationMethod = existingPromotion?.application_method;
|
416
|
+
const promotionCurrencyCode = existingApplicationMethod?.currency_code ||
|
417
|
+
applicationMethodData?.currency_code;
|
418
|
+
if (campaignId && !existingCampaign) {
|
419
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Could not find campaign with id ${campaignId}`);
|
420
|
+
}
|
421
|
+
if (campaignId &&
|
422
|
+
existingCampaign?.budget?.type === utils_1.CampaignBudgetType.SPEND &&
|
423
|
+
existingCampaign.budget.currency_code !== promotionCurrencyCode) {
|
424
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Currency code doesn't match for campaign (${campaignId}) and promotion (${existingPromotion.id})`);
|
425
|
+
}
|
426
|
+
if ((0, utils_1.isDefined)(campaignId)) {
|
427
|
+
promotionsData.push({ ...promotionData, campaign_id: campaignId });
|
335
428
|
}
|
336
429
|
else {
|
337
430
|
promotionsData.push(promotionData);
|
338
431
|
}
|
339
|
-
if (!applicationMethodData) {
|
340
|
-
continue;
|
341
|
-
}
|
342
|
-
const existingPromotion = existingPromotionsMap.get(promotionData.id);
|
343
|
-
const existingApplicationMethod = existingPromotion?.application_method;
|
344
|
-
if (!existingApplicationMethod) {
|
432
|
+
if (!applicationMethodData || !existingApplicationMethod) {
|
345
433
|
continue;
|
346
434
|
}
|
347
435
|
if (applicationMethodData.allocation &&
|
@@ -361,9 +449,10 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
361
449
|
}
|
362
450
|
return updatedPromotions;
|
363
451
|
}
|
452
|
+
// @ts-ignore
|
364
453
|
async updatePromotionRules(data, sharedContext = {}) {
|
365
454
|
const updatedPromotionRules = await this.updatePromotionRules_(data, sharedContext);
|
366
|
-
return this.listPromotionRules({ id: updatedPromotionRules.map((r) => r.id) }, { relations: ["values"] }, sharedContext);
|
455
|
+
return await this.listPromotionRules({ id: updatedPromotionRules.map((r) => r.id) }, { relations: ["values"] }, sharedContext);
|
367
456
|
}
|
368
457
|
async updatePromotionRules_(data, sharedContext = {}) {
|
369
458
|
const promotionRuleIds = data.map((d) => d.id);
|
@@ -413,9 +502,7 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
413
502
|
return await this.listPromotionRules({ id: createdPromotionRules.map((pr) => pr.id) }, { relations: ["values"] }, sharedContext);
|
414
503
|
}
|
415
504
|
async addPromotionBuyRules(promotionId, rulesData, sharedContext = {}) {
|
416
|
-
const promotion = await this.promotionService_.retrieve(promotionId, {
|
417
|
-
relations: ["application_method"],
|
418
|
-
});
|
505
|
+
const promotion = await this.promotionService_.retrieve(promotionId, { relations: ["application_method"] }, sharedContext);
|
419
506
|
const applicationMethod = promotion.application_method;
|
420
507
|
if (!applicationMethod) {
|
421
508
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `application_method for promotion not found`);
|
@@ -482,7 +569,6 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
482
569
|
const createdCampaigns = await this.createCampaigns_(input, sharedContext);
|
483
570
|
const campaigns = await this.listCampaigns({ id: createdCampaigns.map((p) => p.id) }, {
|
484
571
|
relations: ["budget", "promotions"],
|
485
|
-
take: null,
|
486
572
|
}, sharedContext);
|
487
573
|
return Array.isArray(data) ? campaigns : campaigns[0];
|
488
574
|
}
|
@@ -491,22 +577,19 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
491
577
|
const campaignBudgetsData = [];
|
492
578
|
const campaignIdentifierBudgetMap = new Map();
|
493
579
|
for (const createCampaignData of data) {
|
494
|
-
const { budget: campaignBudgetData,
|
495
|
-
const promotionsToAdd = promotions
|
496
|
-
? await this.list({ id: promotions.map((p) => p.id) }, { take: null }, sharedContext)
|
497
|
-
: [];
|
580
|
+
const { budget: campaignBudgetData, ...campaignData } = createCampaignData;
|
498
581
|
if (campaignBudgetData) {
|
499
582
|
campaignIdentifierBudgetMap.set(campaignData.campaign_identifier, campaignBudgetData);
|
500
583
|
}
|
501
584
|
campaignsData.push({
|
502
585
|
...campaignData,
|
503
|
-
promotions: promotionsToAdd,
|
504
586
|
});
|
505
587
|
}
|
506
588
|
const createdCampaigns = await this.campaignService_.create(campaignsData, sharedContext);
|
507
589
|
for (const createdCampaign of createdCampaigns) {
|
508
590
|
const campaignBudgetData = campaignIdentifierBudgetMap.get(createdCampaign.campaign_identifier);
|
509
591
|
if (campaignBudgetData) {
|
592
|
+
this.validateCampaignBudgetData(campaignBudgetData);
|
510
593
|
campaignBudgetsData.push({
|
511
594
|
...campaignBudgetData,
|
512
595
|
campaign: createdCampaign.id,
|
@@ -518,185 +601,295 @@ class PromotionModuleService extends utils_1.ModulesSdkUtils.abstractModuleServi
|
|
518
601
|
}
|
519
602
|
return createdCampaigns;
|
520
603
|
}
|
604
|
+
validateCampaignBudgetData(data) {
|
605
|
+
if (!data.type) {
|
606
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Campaign Budget type is a required field`);
|
607
|
+
}
|
608
|
+
if (data.type === utils_1.CampaignBudgetType.SPEND &&
|
609
|
+
!(0, utils_1.isPresent)(data.currency_code)) {
|
610
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Campaign Budget type is a required field`);
|
611
|
+
}
|
612
|
+
}
|
521
613
|
async updateCampaigns(data, sharedContext = {}) {
|
522
614
|
const input = Array.isArray(data) ? data : [data];
|
523
615
|
const updatedCampaigns = await this.updateCampaigns_(input, sharedContext);
|
524
616
|
const campaigns = await this.listCampaigns({ id: updatedCampaigns.map((p) => p.id) }, {
|
525
617
|
relations: ["budget", "promotions"],
|
526
|
-
take: null,
|
527
618
|
}, sharedContext);
|
528
619
|
return Array.isArray(data) ? campaigns : campaigns[0];
|
529
620
|
}
|
530
621
|
async updateCampaigns_(data, sharedContext = {}) {
|
531
622
|
const campaignIds = data.map((d) => d.id);
|
532
623
|
const campaignsData = [];
|
533
|
-
const
|
534
|
-
const
|
624
|
+
const updateBudgetData = [];
|
625
|
+
const createBudgetData = [];
|
626
|
+
const existingCampaigns = await this.listCampaigns({ id: campaignIds }, { relations: ["budget"] }, sharedContext);
|
535
627
|
const existingCampaignsMap = new Map(existingCampaigns.map((campaign) => [campaign.id, campaign]));
|
536
628
|
for (const updateCampaignData of data) {
|
537
|
-
const { budget:
|
629
|
+
const { budget: budgetData, ...campaignData } = updateCampaignData;
|
538
630
|
const existingCampaign = existingCampaignsMap.get(campaignData.id);
|
539
|
-
const existingCampaignBudget = existingCampaign?.budget;
|
540
631
|
campaignsData.push(campaignData);
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
632
|
+
// Type & currency code of the budget is immutable, we don't allow for it to be updated.
|
633
|
+
// If an existing budget is present, we remove the type and currency from being updated
|
634
|
+
if ((existingCampaign?.budget && budgetData?.type) ||
|
635
|
+
budgetData?.currency_code) {
|
636
|
+
delete budgetData?.type;
|
637
|
+
delete budgetData?.currency_code;
|
638
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Campaign budget attributes (type, currency_code) are immutable`);
|
639
|
+
}
|
640
|
+
if (budgetData) {
|
641
|
+
if (existingCampaign?.budget) {
|
642
|
+
updateBudgetData.push({
|
643
|
+
id: existingCampaign.budget.id,
|
644
|
+
...budgetData,
|
645
|
+
});
|
646
|
+
}
|
647
|
+
else {
|
648
|
+
createBudgetData.push({
|
649
|
+
...budgetData,
|
650
|
+
campaign: existingCampaign.id,
|
651
|
+
});
|
652
|
+
}
|
546
653
|
}
|
547
654
|
}
|
548
655
|
const updatedCampaigns = await this.campaignService_.update(campaignsData, sharedContext);
|
549
|
-
if (
|
550
|
-
await this.campaignBudgetService_.update(
|
656
|
+
if (updateBudgetData.length) {
|
657
|
+
await this.campaignBudgetService_.update(updateBudgetData, sharedContext);
|
658
|
+
}
|
659
|
+
if (createBudgetData.length) {
|
660
|
+
await this.campaignBudgetService_.create(createBudgetData, sharedContext);
|
551
661
|
}
|
552
662
|
return updatedCampaigns;
|
553
663
|
}
|
664
|
+
async addPromotionsToCampaign(data, sharedContext) {
|
665
|
+
const ids = await this.addPromotionsToCampaign_(data, sharedContext);
|
666
|
+
return { ids };
|
667
|
+
}
|
668
|
+
// TODO:
|
669
|
+
// - introduce currency_code to promotion
|
670
|
+
// - allow promotions to be queried by currency code
|
671
|
+
// - when the above is present, validate adding promotion to campaign based on currency code
|
672
|
+
async addPromotionsToCampaign_(data, sharedContext = {}) {
|
673
|
+
const { id, promotion_ids: promotionIds = [] } = data;
|
674
|
+
const campaign = await this.campaignService_.retrieve(id, {}, sharedContext);
|
675
|
+
const promotionsToAdd = await this.promotionService_.list({ id: promotionIds, campaign_id: null }, { relations: ["application_method"] }, sharedContext);
|
676
|
+
const diff = (0, utils_1.arrayDifference)(promotionsToAdd.map((p) => p.id), promotionIds);
|
677
|
+
if (diff.length > 0) {
|
678
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Cannot add promotions (${diff.join(",")}) to campaign. These promotions are either already part of a campaign or not found.`);
|
679
|
+
}
|
680
|
+
const promotionsWithInvalidCurrency = promotionsToAdd.filter((promotion) => campaign.budget?.type === utils_1.CampaignBudgetType.SPEND &&
|
681
|
+
promotion.application_method?.currency_code !==
|
682
|
+
campaign?.budget?.currency_code);
|
683
|
+
if (promotionsWithInvalidCurrency.length > 0) {
|
684
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Cannot add promotions to campaign where currency_code don't match.`);
|
685
|
+
}
|
686
|
+
await this.promotionService_.update(promotionsToAdd.map((promotion) => ({
|
687
|
+
id: promotion.id,
|
688
|
+
campaign_id: campaign.id,
|
689
|
+
})), sharedContext);
|
690
|
+
return promotionsToAdd.map((promo) => promo.id);
|
691
|
+
}
|
692
|
+
async removePromotionsFromCampaign(data, sharedContext) {
|
693
|
+
const ids = await this.removePromotionsFromCampaign_(data, sharedContext);
|
694
|
+
return { ids };
|
695
|
+
}
|
696
|
+
async removePromotionsFromCampaign_(data, sharedContext = {}) {
|
697
|
+
const { id, promotion_ids: promotionIds = [] } = data;
|
698
|
+
await this.campaignService_.retrieve(id, {}, sharedContext);
|
699
|
+
const promotionsToRemove = await this.promotionService_.list({ id: promotionIds }, {}, sharedContext);
|
700
|
+
const diff = (0, utils_1.arrayDifference)(promotionsToRemove.map((p) => p.id), promotionIds);
|
701
|
+
if (diff.length > 0) {
|
702
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Promotions with ids (${diff.join(",")}) not found.`);
|
703
|
+
}
|
704
|
+
await this.promotionService_.update(promotionsToRemove.map((promotion) => ({
|
705
|
+
id: promotion.id,
|
706
|
+
campaign_id: null,
|
707
|
+
})), sharedContext);
|
708
|
+
return promotionsToRemove.map((promo) => promo.id);
|
709
|
+
}
|
554
710
|
}
|
555
711
|
exports.default = PromotionModuleService;
|
556
712
|
__decorate([
|
557
|
-
(0, utils_1.InjectManager)(
|
713
|
+
(0, utils_1.InjectManager)(),
|
714
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
558
715
|
__param(1, (0, utils_1.MedusaContext)()),
|
559
716
|
__metadata("design:type", Function),
|
560
717
|
__metadata("design:paramtypes", [Array, Object]),
|
561
718
|
__metadata("design:returntype", Promise)
|
562
719
|
], PromotionModuleService.prototype, "registerUsage", null);
|
563
720
|
__decorate([
|
564
|
-
(0, utils_1.InjectManager)(
|
721
|
+
(0, utils_1.InjectManager)(),
|
722
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
723
|
+
__metadata("design:type", Function),
|
724
|
+
__metadata("design:paramtypes", [Array, Object]),
|
725
|
+
__metadata("design:returntype", Promise)
|
726
|
+
], PromotionModuleService.prototype, "revertUsage", null);
|
727
|
+
__decorate([
|
728
|
+
(0, utils_1.InjectManager)(),
|
565
729
|
__param(3, (0, utils_1.MedusaContext)()),
|
566
730
|
__metadata("design:type", Function),
|
567
731
|
__metadata("design:paramtypes", [Array, Object, Object, Object]),
|
568
732
|
__metadata("design:returntype", Promise)
|
569
733
|
], PromotionModuleService.prototype, "computeActions", null);
|
570
734
|
__decorate([
|
571
|
-
(0, utils_1.InjectManager)(
|
735
|
+
(0, utils_1.InjectManager)(),
|
572
736
|
__param(1, (0, utils_1.MedusaContext)()),
|
573
737
|
__metadata("design:type", Function),
|
574
738
|
__metadata("design:paramtypes", [Object, Object]),
|
575
739
|
__metadata("design:returntype", Promise)
|
576
|
-
], PromotionModuleService.prototype, "
|
740
|
+
], PromotionModuleService.prototype, "createPromotions", null);
|
577
741
|
__decorate([
|
578
|
-
(0, utils_1.InjectTransactionManager)(
|
742
|
+
(0, utils_1.InjectTransactionManager)(),
|
579
743
|
__param(1, (0, utils_1.MedusaContext)()),
|
580
744
|
__metadata("design:type", Function),
|
581
745
|
__metadata("design:paramtypes", [Array, Object]),
|
582
746
|
__metadata("design:returntype", Promise)
|
583
|
-
], PromotionModuleService.prototype, "
|
747
|
+
], PromotionModuleService.prototype, "createPromotions_", null);
|
584
748
|
__decorate([
|
585
|
-
(0, utils_1.InjectManager)(
|
749
|
+
(0, utils_1.InjectManager)(),
|
586
750
|
__param(1, (0, utils_1.MedusaContext)()),
|
587
751
|
__metadata("design:type", Function),
|
588
752
|
__metadata("design:paramtypes", [Object, Object]),
|
589
753
|
__metadata("design:returntype", Promise)
|
590
|
-
], PromotionModuleService.prototype, "
|
754
|
+
], PromotionModuleService.prototype, "updatePromotions", null);
|
591
755
|
__decorate([
|
592
|
-
(0, utils_1.InjectTransactionManager)(
|
756
|
+
(0, utils_1.InjectTransactionManager)(),
|
593
757
|
__param(1, (0, utils_1.MedusaContext)()),
|
594
758
|
__metadata("design:type", Function),
|
595
759
|
__metadata("design:paramtypes", [Array, Object]),
|
596
760
|
__metadata("design:returntype", Promise)
|
597
|
-
], PromotionModuleService.prototype, "
|
761
|
+
], PromotionModuleService.prototype, "updatePromotions_", null);
|
598
762
|
__decorate([
|
599
|
-
(0, utils_1.InjectManager)(
|
763
|
+
(0, utils_1.InjectManager)()
|
764
|
+
// @ts-ignore
|
765
|
+
,
|
600
766
|
__param(1, (0, utils_1.MedusaContext)()),
|
601
767
|
__metadata("design:type", Function),
|
602
768
|
__metadata("design:paramtypes", [Array, Object]),
|
603
769
|
__metadata("design:returntype", Promise)
|
604
770
|
], PromotionModuleService.prototype, "updatePromotionRules", null);
|
605
771
|
__decorate([
|
606
|
-
(0, utils_1.InjectTransactionManager)(
|
772
|
+
(0, utils_1.InjectTransactionManager)(),
|
607
773
|
__param(1, (0, utils_1.MedusaContext)()),
|
608
774
|
__metadata("design:type", Function),
|
609
775
|
__metadata("design:paramtypes", [Array, Object]),
|
610
776
|
__metadata("design:returntype", Promise)
|
611
777
|
], PromotionModuleService.prototype, "updatePromotionRules_", null);
|
612
778
|
__decorate([
|
613
|
-
(0, utils_1.InjectManager)(
|
779
|
+
(0, utils_1.InjectManager)(),
|
614
780
|
__param(2, (0, utils_1.MedusaContext)()),
|
615
781
|
__metadata("design:type", Function),
|
616
782
|
__metadata("design:paramtypes", [String, Array, Object]),
|
617
783
|
__metadata("design:returntype", Promise)
|
618
784
|
], PromotionModuleService.prototype, "addPromotionRules", null);
|
619
785
|
__decorate([
|
620
|
-
(0, utils_1.InjectManager)(
|
786
|
+
(0, utils_1.InjectManager)(),
|
621
787
|
__param(2, (0, utils_1.MedusaContext)()),
|
622
788
|
__metadata("design:type", Function),
|
623
789
|
__metadata("design:paramtypes", [String, Array, Object]),
|
624
790
|
__metadata("design:returntype", Promise)
|
625
791
|
], PromotionModuleService.prototype, "addPromotionTargetRules", null);
|
626
792
|
__decorate([
|
627
|
-
(0, utils_1.InjectManager)(
|
793
|
+
(0, utils_1.InjectManager)(),
|
628
794
|
__param(2, (0, utils_1.MedusaContext)()),
|
629
795
|
__metadata("design:type", Function),
|
630
796
|
__metadata("design:paramtypes", [String, Array, Object]),
|
631
797
|
__metadata("design:returntype", Promise)
|
632
798
|
], PromotionModuleService.prototype, "addPromotionBuyRules", null);
|
633
799
|
__decorate([
|
634
|
-
(0, utils_1.InjectTransactionManager)(
|
800
|
+
(0, utils_1.InjectTransactionManager)(),
|
635
801
|
__param(3, (0, utils_1.MedusaContext)()),
|
636
802
|
__metadata("design:type", Function),
|
637
803
|
__metadata("design:paramtypes", [Array, String, Object, Object]),
|
638
804
|
__metadata("design:returntype", Promise)
|
639
805
|
], PromotionModuleService.prototype, "createPromotionRulesAndValues_", null);
|
640
806
|
__decorate([
|
641
|
-
(0, utils_1.InjectManager)(
|
807
|
+
(0, utils_1.InjectManager)(),
|
642
808
|
__param(2, (0, utils_1.MedusaContext)()),
|
643
809
|
__metadata("design:type", Function),
|
644
810
|
__metadata("design:paramtypes", [String, Array, Object]),
|
645
811
|
__metadata("design:returntype", Promise)
|
646
812
|
], PromotionModuleService.prototype, "removePromotionRules", null);
|
647
813
|
__decorate([
|
648
|
-
(0, utils_1.InjectTransactionManager)(
|
814
|
+
(0, utils_1.InjectTransactionManager)(),
|
649
815
|
__param(2, (0, utils_1.MedusaContext)()),
|
650
816
|
__metadata("design:type", Function),
|
651
817
|
__metadata("design:paramtypes", [String, Array, Object]),
|
652
818
|
__metadata("design:returntype", Promise)
|
653
819
|
], PromotionModuleService.prototype, "removePromotionRules_", null);
|
654
820
|
__decorate([
|
655
|
-
(0, utils_1.InjectManager)(
|
821
|
+
(0, utils_1.InjectManager)(),
|
656
822
|
__param(2, (0, utils_1.MedusaContext)()),
|
657
823
|
__metadata("design:type", Function),
|
658
824
|
__metadata("design:paramtypes", [String, Array, Object]),
|
659
825
|
__metadata("design:returntype", Promise)
|
660
826
|
], PromotionModuleService.prototype, "removePromotionTargetRules", null);
|
661
827
|
__decorate([
|
662
|
-
(0, utils_1.InjectManager)(
|
828
|
+
(0, utils_1.InjectManager)(),
|
663
829
|
__param(2, (0, utils_1.MedusaContext)()),
|
664
830
|
__metadata("design:type", Function),
|
665
831
|
__metadata("design:paramtypes", [String, Array, Object]),
|
666
832
|
__metadata("design:returntype", Promise)
|
667
833
|
], PromotionModuleService.prototype, "removePromotionBuyRules", null);
|
668
834
|
__decorate([
|
669
|
-
(0, utils_1.InjectTransactionManager)(
|
835
|
+
(0, utils_1.InjectTransactionManager)(),
|
670
836
|
__param(3, (0, utils_1.MedusaContext)()),
|
671
837
|
__metadata("design:type", Function),
|
672
838
|
__metadata("design:paramtypes", [String, Array, String, Object]),
|
673
839
|
__metadata("design:returntype", Promise)
|
674
840
|
], PromotionModuleService.prototype, "removeApplicationMethodRules_", null);
|
675
841
|
__decorate([
|
676
|
-
(0, utils_1.InjectManager)(
|
842
|
+
(0, utils_1.InjectManager)(),
|
677
843
|
__param(1, (0, utils_1.MedusaContext)()),
|
678
844
|
__metadata("design:type", Function),
|
679
845
|
__metadata("design:paramtypes", [Object, Object]),
|
680
846
|
__metadata("design:returntype", Promise)
|
681
847
|
], PromotionModuleService.prototype, "createCampaigns", null);
|
682
848
|
__decorate([
|
683
|
-
(0, utils_1.InjectTransactionManager)(
|
849
|
+
(0, utils_1.InjectTransactionManager)(),
|
684
850
|
__param(1, (0, utils_1.MedusaContext)()),
|
685
851
|
__metadata("design:type", Function),
|
686
852
|
__metadata("design:paramtypes", [Array, Object]),
|
687
853
|
__metadata("design:returntype", Promise)
|
688
854
|
], PromotionModuleService.prototype, "createCampaigns_", null);
|
689
855
|
__decorate([
|
690
|
-
(0, utils_1.InjectManager)(
|
856
|
+
(0, utils_1.InjectManager)(),
|
691
857
|
__param(1, (0, utils_1.MedusaContext)()),
|
692
858
|
__metadata("design:type", Function),
|
693
859
|
__metadata("design:paramtypes", [Object, Object]),
|
694
860
|
__metadata("design:returntype", Promise)
|
695
861
|
], PromotionModuleService.prototype, "updateCampaigns", null);
|
696
862
|
__decorate([
|
697
|
-
(0, utils_1.InjectTransactionManager)(
|
863
|
+
(0, utils_1.InjectTransactionManager)(),
|
698
864
|
__param(1, (0, utils_1.MedusaContext)()),
|
699
865
|
__metadata("design:type", Function),
|
700
866
|
__metadata("design:paramtypes", [Array, Object]),
|
701
867
|
__metadata("design:returntype", Promise)
|
702
868
|
], PromotionModuleService.prototype, "updateCampaigns_", null);
|
869
|
+
__decorate([
|
870
|
+
(0, utils_1.InjectManager)(),
|
871
|
+
__metadata("design:type", Function),
|
872
|
+
__metadata("design:paramtypes", [Object, Object]),
|
873
|
+
__metadata("design:returntype", Promise)
|
874
|
+
], PromotionModuleService.prototype, "addPromotionsToCampaign", null);
|
875
|
+
__decorate([
|
876
|
+
(0, utils_1.InjectTransactionManager)(),
|
877
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
878
|
+
__metadata("design:type", Function),
|
879
|
+
__metadata("design:paramtypes", [Object, Object]),
|
880
|
+
__metadata("design:returntype", Promise)
|
881
|
+
], PromotionModuleService.prototype, "addPromotionsToCampaign_", null);
|
882
|
+
__decorate([
|
883
|
+
(0, utils_1.InjectManager)(),
|
884
|
+
__metadata("design:type", Function),
|
885
|
+
__metadata("design:paramtypes", [Object, Object]),
|
886
|
+
__metadata("design:returntype", Promise)
|
887
|
+
], PromotionModuleService.prototype, "removePromotionsFromCampaign", null);
|
888
|
+
__decorate([
|
889
|
+
(0, utils_1.InjectTransactionManager)(),
|
890
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
891
|
+
__metadata("design:type", Function),
|
892
|
+
__metadata("design:paramtypes", [Object, Object]),
|
893
|
+
__metadata("design:returntype", Promise)
|
894
|
+
], PromotionModuleService.prototype, "removePromotionsFromCampaign_", null);
|
895
|
+
//# sourceMappingURL=promotion-module.js.map
|