@medusajs/promotion 0.0.5-snapshot-20240916110643 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -5
- package/dist/initialize/index.d.ts +5 -0
- package/dist/initialize/index.d.ts.map +1 -0
- package/dist/initialize/index.js +16 -0
- package/dist/joiner-config.d.ts +8 -1
- package/dist/joiner-config.d.ts.map +1 -1
- package/dist/joiner-config.js +35 -9
- package/dist/loaders/connection.d.ts +5 -0
- package/dist/loaders/connection.d.ts.map +1 -0
- package/dist/loaders/connection.js +41 -0
- package/dist/loaders/container.d.ts +3 -0
- package/dist/loaders/container.d.ts.map +1 -0
- package/dist/loaders/container.js +34 -0
- package/dist/loaders/index.d.ts +3 -0
- package/dist/loaders/index.d.ts.map +1 -0
- package/dist/loaders/index.js +18 -0
- package/dist/migrations/Migration20240227120221.d.ts.map +1 -1
- package/dist/migrations/Migration20240227120221.js +2 -10
- package/dist/models/application-method.d.ts +6 -4
- package/dist/models/application-method.d.ts.map +1 -1
- package/dist/models/application-method.js +6 -16
- package/dist/models/campaign-budget.d.ts +5 -6
- package/dist/models/campaign-budget.d.ts.map +1 -1
- package/dist/models/campaign-budget.js +4 -8
- package/dist/models/campaign.d.ts +4 -3
- package/dist/models/campaign.d.ts.map +1 -1
- package/dist/models/campaign.js +13 -10
- package/dist/models/promotion-rule-value.d.ts +1 -2
- package/dist/models/promotion-rule-value.d.ts.map +1 -1
- package/dist/models/promotion-rule-value.js +1 -1
- package/dist/models/promotion-rule.d.ts +1 -1
- package/dist/models/promotion-rule.d.ts.map +1 -1
- package/dist/models/promotion.d.ts +4 -5
- package/dist/models/promotion.d.ts.map +1 -1
- package/dist/models/promotion.js +4 -8
- package/dist/module-definition.d.ts +5 -0
- package/dist/module-definition.d.ts.map +1 -0
- package/dist/module-definition.js +50 -0
- package/dist/repositories/campaign.d.ts +16 -0
- package/dist/repositories/campaign.d.ts.map +1 -0
- package/dist/repositories/campaign.js +90 -0
- package/dist/repositories/index.d.ts +3 -0
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +7 -0
- package/dist/services/promotion-module.d.ts +26 -41
- package/dist/services/promotion-module.d.ts.map +1 -1
- package/dist/services/promotion-module.js +72 -271
- package/dist/types/application-method.d.ts +10 -12
- package/dist/types/application-method.d.ts.map +1 -1
- package/dist/types/campaign-budget.d.ts +6 -8
- package/dist/types/campaign-budget.d.ts.map +1 -1
- package/dist/types/campaign.d.ts +8 -6
- package/dist/types/campaign.d.ts.map +1 -1
- package/dist/types/promotion.d.ts +2 -2
- package/dist/types/promotion.d.ts.map +1 -1
- package/dist/utils/compute-actions/buy-get.d.ts +3 -6
- package/dist/utils/compute-actions/buy-get.d.ts.map +1 -1
- package/dist/utils/compute-actions/buy-get.js +30 -94
- package/dist/utils/compute-actions/line-items.d.ts.map +1 -1
- package/dist/utils/compute-actions/line-items.js +5 -5
- package/dist/utils/compute-actions/shipping-methods.d.ts +2 -2
- package/dist/utils/compute-actions/shipping-methods.d.ts.map +1 -1
- package/dist/utils/compute-actions/shipping-methods.js +18 -16
- package/dist/utils/compute-actions/usage.d.ts +3 -2
- package/dist/utils/compute-actions/usage.d.ts.map +1 -1
- package/dist/utils/compute-actions/usage.js +11 -4
- package/dist/utils/validations/application-method.d.ts.map +1 -1
- package/dist/utils/validations/application-method.js +2 -2
- 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 +2 -22
- package/package.json +14 -9
- package/dist/migrations/Migration20240617102917.d.ts +0 -6
- package/dist/migrations/Migration20240617102917.d.ts.map +0 -1
- package/dist/migrations/Migration20240617102917.js +0 -15
- package/dist/migrations/Migration20240624153824.d.ts +0 -6
- package/dist/migrations/Migration20240624153824.d.ts.map +0 -1
- package/dist/migrations/Migration20240624153824.js +0 -15
- package/dist/schema/index.d.ts +0 -3
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js +0 -98
package/dist/types/campaign.d.ts
CHANGED
@@ -2,19 +2,21 @@ import { PromotionDTO } from "@medusajs/types";
|
|
2
2
|
import { Promotion } from "../models";
|
3
3
|
export interface CreateCampaignDTO {
|
4
4
|
name: string;
|
5
|
-
description?: string
|
5
|
+
description?: string;
|
6
|
+
currency?: string;
|
6
7
|
campaign_identifier: string;
|
7
|
-
starts_at
|
8
|
-
ends_at
|
8
|
+
starts_at: Date;
|
9
|
+
ends_at: Date;
|
9
10
|
promotions?: (PromotionDTO | Promotion)[];
|
10
11
|
}
|
11
12
|
export interface UpdateCampaignDTO {
|
12
13
|
id: string;
|
13
14
|
name?: string;
|
14
|
-
description?: string
|
15
|
+
description?: string;
|
16
|
+
currency?: string;
|
15
17
|
campaign_identifier?: string;
|
16
|
-
starts_at?: Date
|
17
|
-
ends_at?: Date
|
18
|
+
starts_at?: Date;
|
19
|
+
ends_at?: Date;
|
18
20
|
promotions?: (PromotionDTO | Promotion)[];
|
19
21
|
}
|
20
22
|
//# sourceMappingURL=campaign.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"campaign.d.ts","sourceRoot":"","sources":["../../src/types/campaign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"campaign.d.ts","sourceRoot":"","sources":["../../src/types/campaign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,SAAS,EAAE,IAAI,CAAA;IACf,OAAO,EAAE,IAAI,CAAA;IACb,UAAU,CAAC,EAAE,CAAC,YAAY,GAAG,SAAS,CAAC,EAAE,CAAA;CAC1C;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,SAAS,CAAC,EAAE,IAAI,CAAA;IAChB,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,UAAU,CAAC,EAAE,CAAC,YAAY,GAAG,SAAS,CAAC,EAAE,CAAA;CAC1C"}
|
@@ -3,13 +3,13 @@ export interface CreatePromotionDTO {
|
|
3
3
|
code: string;
|
4
4
|
type: PromotionTypeValues;
|
5
5
|
is_automatic?: boolean;
|
6
|
-
|
6
|
+
campaign?: string;
|
7
7
|
}
|
8
8
|
export interface UpdatePromotionDTO {
|
9
9
|
id: string;
|
10
10
|
code?: string;
|
11
11
|
type?: PromotionTypeValues;
|
12
12
|
is_automatic?: boolean;
|
13
|
-
|
13
|
+
campaign?: string;
|
14
14
|
}
|
15
15
|
//# sourceMappingURL=promotion.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promotion.d.ts","sourceRoot":"","sources":["../../src/types/promotion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAErD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,mBAAmB,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,
|
1
|
+
{"version":3,"file":"promotion.d.ts","sourceRoot":"","sources":["../../src/types/promotion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAErD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,mBAAmB,CAAA;IACzB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,mBAAmB,CAAA;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB"}
|
@@ -1,8 +1,5 @@
|
|
1
|
-
import {
|
2
|
-
|
3
|
-
|
4
|
-
quantity: BigNumberInput;
|
5
|
-
};
|
6
|
-
export declare function getComputedActionsForBuyGet(promotion: PromotionTypes.PromotionDTO, itemsContext: ComputeActionItemLine[], methodIdPromoValueMap: Map<string, BigNumberInput>, eligibleBuyItemMap: Map<string, EligibleItem[]>, eligibleTargetItemMap: Map<string, EligibleItem[]>): PromotionTypes.ComputeActions[];
|
1
|
+
import { PromotionTypes } from "@medusajs/types";
|
2
|
+
import { ApplicationMethodTargetType } from "@medusajs/utils";
|
3
|
+
export declare function getComputedActionsForBuyGet(promotion: PromotionTypes.PromotionDTO, itemsContext: PromotionTypes.ComputeActionContext[ApplicationMethodTargetType.ITEMS], methodIdPromoValueMap: Map<string, number>): PromotionTypes.ComputeActions[];
|
7
4
|
export declare function sortByBuyGetType(a: any, b: any): 0 | 1 | -1;
|
8
5
|
//# sourceMappingURL=buy-get.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"buy-get.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/buy-get.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"buy-get.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/buy-get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EACL,2BAA2B,EAK5B,MAAM,iBAAiB,CAAA;AAKxB,wBAAgB,2BAA2B,CACzC,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,YAAY,EAAE,cAAc,CAAC,oBAAoB,CAAC,2BAA2B,CAAC,KAAK,CAAC,EACpF,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,cAAc,EAAE,CA6EjC;AAED,wBAAgB,gBAAgB,CAAC,CAAC,KAAA,EAAE,CAAC,KAAA,cAWpC"}
|
@@ -4,106 +4,42 @@ exports.sortByBuyGetType = exports.getComputedActionsForBuyGet = void 0;
|
|
4
4
|
const utils_1 = require("@medusajs/utils");
|
5
5
|
const validations_1 = require("../validations");
|
6
6
|
const usage_1 = require("./usage");
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
*/
|
14
|
-
function filterItemsByPromotionRules(itemsContext, rules) {
|
15
|
-
return itemsContext
|
16
|
-
.filter((item) => (0, validations_1.areRulesValidForContext)(rules || [], item, utils_1.ApplicationMethodTargetType.ITEMS))
|
17
|
-
.sort(sortByPrice);
|
18
|
-
}
|
19
|
-
function getComputedActionsForBuyGet(promotion, itemsContext, methodIdPromoValueMap, eligibleBuyItemMap, eligibleTargetItemMap) {
|
7
|
+
// TODO: calculations should eventually move to a totals util outside of the module
|
8
|
+
function getComputedActionsForBuyGet(promotion, itemsContext, methodIdPromoValueMap) {
|
9
|
+
const buyRulesMinQuantity = promotion.application_method?.buy_rules_min_quantity;
|
10
|
+
const applyToQuantity = promotion.application_method?.apply_to_quantity;
|
11
|
+
const buyRules = promotion.application_method?.buy_rules;
|
12
|
+
const targetRules = promotion.application_method?.target_rules;
|
20
13
|
const computedActions = [];
|
21
|
-
const minimumBuyQuantity = utils_1.MathBN.convert(promotion.application_method?.buy_rules_min_quantity ?? 0);
|
22
|
-
const itemsMap = new Map(itemsContext.map((i) => [i.id, i]));
|
23
14
|
if (!itemsContext) {
|
24
15
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `"items" should be present as an array in the context to compute actions`);
|
25
16
|
}
|
26
|
-
|
27
|
-
const eligibleBuyItemQuantity = utils_1.MathBN.sum(...eligibleBuyItems.map((item) => item.quantity));
|
28
|
-
/*
|
29
|
-
Get the total quantity of items where buy rules apply. If the total sum of eligible items
|
30
|
-
does not match up to the minimum buy quantity set on the promotion, return early.
|
31
|
-
*/
|
32
|
-
if (utils_1.MathBN.gt(minimumBuyQuantity, eligibleBuyItemQuantity)) {
|
17
|
+
if (!Array.isArray(buyRules) || !Array.isArray(targetRules)) {
|
33
18
|
return [];
|
34
19
|
}
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
*/
|
42
|
-
for (const eligibleBuyItem of eligibleBuyItems) {
|
43
|
-
const eligibleItemsByPromotion = eligibleBuyItemMap.get(promotion.code) || [];
|
44
|
-
const accumulatedQuantity = eligibleItemsByPromotion.reduce((acc, item) => utils_1.MathBN.sum(acc, item.quantity), utils_1.MathBN.convert(0));
|
45
|
-
// If we have reached the minimum buy quantity from the eligible items for this promotion,
|
46
|
-
// we can break early and continue to applying the target items
|
47
|
-
if (utils_1.MathBN.gte(accumulatedQuantity, minimumBuyQuantity)) {
|
48
|
-
break;
|
49
|
-
}
|
50
|
-
const eligibleQuantity = utils_1.MathBN.sum(...eligibleItemsByPromotion
|
51
|
-
.filter((buy) => buy.item_id === eligibleBuyItem.id)
|
52
|
-
.map((b) => b.quantity));
|
53
|
-
const reservableQuantity = utils_1.MathBN.min(eligibleBuyItem.quantity, utils_1.MathBN.sub(minimumBuyQuantity, eligibleQuantity));
|
54
|
-
// If we have reached the required minimum quantity, we break the loop early
|
55
|
-
if (utils_1.MathBN.lte(reservableQuantity, 0)) {
|
56
|
-
break;
|
57
|
-
}
|
58
|
-
eligibleItemsByPromotion.push({
|
59
|
-
item_id: eligibleBuyItem.id,
|
60
|
-
quantity: utils_1.MathBN.min(eligibleBuyItem.quantity, reservableQuantity).toNumber(),
|
61
|
-
});
|
62
|
-
eligibleBuyItemMap.set(promotion.code, eligibleItemsByPromotion);
|
63
|
-
}
|
64
|
-
const eligibleTargetItems = filterItemsByPromotionRules(itemsContext, promotion.application_method?.target_rules);
|
65
|
-
const targetQuantity = utils_1.MathBN.convert(promotion.application_method?.apply_to_quantity ?? 0);
|
66
|
-
/*
|
67
|
-
In this loop, we build a map of eligible target items and quantity applicable to these items.
|
68
|
-
|
69
|
-
Here we remove the quantity we used previously to identify eligible buy items
|
70
|
-
from the eligible target items.
|
71
|
-
|
72
|
-
This is done to prevent applying promotion to the same item we use to qualify the buy rules.
|
73
|
-
*/
|
74
|
-
for (const eligibleTargetItem of eligibleTargetItems) {
|
75
|
-
const inapplicableQuantity = utils_1.MathBN.sum(...Array.from(eligibleBuyItemMap.values())
|
76
|
-
.flat(1)
|
77
|
-
.filter((buy) => buy.item_id === eligibleTargetItem.id)
|
78
|
-
.map((b) => b.quantity));
|
79
|
-
const applicableQuantity = utils_1.MathBN.sub(eligibleTargetItem.quantity, inapplicableQuantity);
|
80
|
-
const fulfillableQuantity = utils_1.MathBN.min(targetQuantity, applicableQuantity);
|
81
|
-
// If we have reached the required quantity to target from this item, we
|
82
|
-
// move on to the next item
|
83
|
-
if (utils_1.MathBN.lte(fulfillableQuantity, 0)) {
|
84
|
-
continue;
|
85
|
-
}
|
86
|
-
const targetItemsByPromotion = eligibleTargetItemMap.get(promotion.code) || [];
|
87
|
-
targetItemsByPromotion.push({
|
88
|
-
item_id: eligibleTargetItem.id,
|
89
|
-
quantity: utils_1.MathBN.min(fulfillableQuantity, targetQuantity).toNumber(),
|
90
|
-
});
|
91
|
-
eligibleTargetItemMap.set(promotion.code, targetItemsByPromotion);
|
92
|
-
}
|
93
|
-
const targetItemsByPromotion = eligibleTargetItemMap.get(promotion.code) || [];
|
94
|
-
const targettableQuantity = targetItemsByPromotion.reduce((sum, item) => utils_1.MathBN.sum(sum, item.quantity), utils_1.MathBN.convert(0));
|
95
|
-
// If we were able to match the target requirements across all line items, we return early.
|
96
|
-
if (utils_1.MathBN.lt(targettableQuantity, targetQuantity)) {
|
20
|
+
const validQuantity = itemsContext
|
21
|
+
.filter((item) => (0, validations_1.areRulesValidForContext)(buyRules, item))
|
22
|
+
.reduce((acc, next) => acc + next.quantity, 0);
|
23
|
+
if (!buyRulesMinQuantity ||
|
24
|
+
!applyToQuantity ||
|
25
|
+
buyRulesMinQuantity > validQuantity) {
|
97
26
|
return [];
|
98
27
|
}
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
const
|
104
|
-
const
|
105
|
-
|
106
|
-
|
28
|
+
const validItemsForTargetRules = itemsContext
|
29
|
+
.filter((item) => (0, validations_1.areRulesValidForContext)(targetRules, item))
|
30
|
+
.filter((item) => (0, utils_1.isPresent)(item.subtotal) && (0, utils_1.isPresent)(item.quantity))
|
31
|
+
.sort((a, b) => {
|
32
|
+
const aPrice = a.subtotal / a.quantity;
|
33
|
+
const bPrice = b.subtotal / b.quantity;
|
34
|
+
return bPrice - aPrice;
|
35
|
+
});
|
36
|
+
let remainingQtyToApply = applyToQuantity;
|
37
|
+
for (const method of validItemsForTargetRules) {
|
38
|
+
const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0;
|
39
|
+
const multiplier = Math.min(method.quantity, remainingQtyToApply);
|
40
|
+
const amount = (method.subtotal / method.quantity) * multiplier;
|
41
|
+
const newRemainingQtyToApply = remainingQtyToApply - multiplier;
|
42
|
+
if (newRemainingQtyToApply < 0 || amount <= 0) {
|
107
43
|
break;
|
108
44
|
}
|
109
45
|
else {
|
@@ -114,10 +50,10 @@ function getComputedActionsForBuyGet(promotion, itemsContext, methodIdPromoValue
|
|
114
50
|
computedActions.push(budgetExceededAction);
|
115
51
|
continue;
|
116
52
|
}
|
117
|
-
methodIdPromoValueMap.set(
|
53
|
+
methodIdPromoValueMap.set(method.id, appliedPromoValue + amount);
|
118
54
|
computedActions.push({
|
119
55
|
action: utils_1.ComputedActions.ADD_ITEM_ADJUSTMENT,
|
120
|
-
item_id:
|
56
|
+
item_id: method.id,
|
121
57
|
amount,
|
122
58
|
code: promotion.code,
|
123
59
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"line-items.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/line-items.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,
|
1
|
+
{"version":3,"file":"line-items.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/line-items.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,cAAc,EACf,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAIL,2BAA2B,IAAI,UAAU,EAE1C,MAAM,iBAAiB,CAAA;AAgBxB,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,KAAK,EAAE,cAAc,CAAC,oBAAoB,CAAC,UAAU,CAAC,KAAK,CAAC,EAC5D,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,kBAAkB,CAAC,EAAE,iCAAiC,GACrD,cAAc,CAAC,cAAc,EAAE,CASjC;AAED,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,eAAe,EAAE,cAAc,CAAC,oBAAoB,CAAC,UAAU,CAAC,gBAAgB,CAAC,EACjF,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,cAAc,CAAC,cAAc,EAAE,CAIjC;AAED,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,sBAAsB,EAAE,cAAc,CAAC,oBAAoB,EAC3D,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,cAAc,EAAE,CAOjC"}
|
@@ -32,9 +32,9 @@ function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocatio
|
|
32
32
|
const isTargetShippingMethod = target === utils_1.ApplicationMethodTargetType.SHIPPING_METHODS;
|
33
33
|
const isTargetLineItems = target === utils_1.ApplicationMethodTargetType.ITEMS;
|
34
34
|
const isTargetOrder = target === utils_1.ApplicationMethodTargetType.ORDER;
|
35
|
-
let lineItemsTotal =
|
35
|
+
let lineItemsTotal = 0;
|
36
36
|
if (allocation === utils_1.ApplicationMethodAllocation.ACROSS) {
|
37
|
-
lineItemsTotal = applicableItems.reduce((acc, item) =>
|
37
|
+
lineItemsTotal = applicableItems.reduce((acc, item) => acc + item.subtotal - (appliedPromotionsMap.get(item.id) ?? 0), 0);
|
38
38
|
}
|
39
39
|
for (const item of applicableItems) {
|
40
40
|
const appliedPromoValue = appliedPromotionsMap.get(item.id) ?? 0;
|
@@ -51,7 +51,7 @@ function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocatio
|
|
51
51
|
type: applicationMethod?.type,
|
52
52
|
allocation,
|
53
53
|
}, lineItemsTotal);
|
54
|
-
if (
|
54
|
+
if (amount <= 0) {
|
55
55
|
continue;
|
56
56
|
}
|
57
57
|
const budgetExceededAction = (0, usage_1.computeActionForBudgetExceeded)(promotion, amount);
|
@@ -59,7 +59,7 @@ function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocatio
|
|
59
59
|
computedActions.push(budgetExceededAction);
|
60
60
|
continue;
|
61
61
|
}
|
62
|
-
appliedPromotionsMap.set(item.id,
|
62
|
+
appliedPromotionsMap.set(item.id, appliedPromoValue + amount);
|
63
63
|
if (isTargetLineItems || isTargetOrder) {
|
64
64
|
computedActions.push({
|
65
65
|
action: utils_1.ComputedActions.ADD_ITEM_ADJUSTMENT,
|
@@ -84,7 +84,7 @@ function getValidItemsForPromotion(items, promotion) {
|
|
84
84
|
return (items?.filter((item) => {
|
85
85
|
const isSubtotalPresent = "subtotal" in item;
|
86
86
|
const isQuantityPresent = "quantity" in item;
|
87
|
-
const isPromotionApplicableToItem = (0, validations_1.areRulesValidForContext)(promotion?.application_method?.target_rules, item
|
87
|
+
const isPromotionApplicableToItem = (0, validations_1.areRulesValidForContext)(promotion?.application_method?.target_rules, item);
|
88
88
|
return (isPromotionApplicableToItem &&
|
89
89
|
(isQuantityPresent || isTargetShippingMethod) &&
|
90
90
|
isSubtotalPresent);
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { PromotionTypes } from "@medusajs/types";
|
2
2
|
import { ApplicationMethodTargetType } from "@medusajs/utils";
|
3
3
|
export declare function getComputedActionsForShippingMethods(promotion: PromotionTypes.PromotionDTO, shippingMethodApplicationContext: PromotionTypes.ComputeActionContext[ApplicationMethodTargetType.SHIPPING_METHODS], methodIdPromoValueMap: Map<string, number>): PromotionTypes.ComputeActions[];
|
4
|
-
export declare function applyPromotionToShippingMethods(promotion: PromotionTypes.PromotionDTO, shippingMethods: PromotionTypes.ComputeActionContext[ApplicationMethodTargetType.SHIPPING_METHODS], methodIdPromoValueMap: Map<string,
|
4
|
+
export declare function applyPromotionToShippingMethods(promotion: PromotionTypes.PromotionDTO, shippingMethods: PromotionTypes.ComputeActionContext[ApplicationMethodTargetType.SHIPPING_METHODS], methodIdPromoValueMap: Map<string, number>): PromotionTypes.ComputeActions[];
|
5
5
|
//# sourceMappingURL=shipping-methods.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"shipping-methods.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/shipping-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,
|
1
|
+
{"version":3,"file":"shipping-methods.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/shipping-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAEL,2BAA2B,EAI5B,MAAM,iBAAiB,CAAA;AAIxB,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,gCAAgC,EAAE,cAAc,CAAC,oBAAoB,CAAC,2BAA2B,CAAC,gBAAgB,CAAC,EACnH,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,cAAc,EAAE,CA6BjC;AAED,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,eAAe,EAAE,cAAc,CAAC,oBAAoB,CAAC,2BAA2B,CAAC,gBAAgB,CAAC,EAClG,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,cAAc,EAAE,CA0GjC"}
|
@@ -10,7 +10,7 @@ function getComputedActionsForShippingMethods(promotion, shippingMethodApplicati
|
|
10
10
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `"shipping_methods" should be present as an array in the context for computeActions`);
|
11
11
|
}
|
12
12
|
for (const shippingMethodContext of shippingMethodApplicationContext) {
|
13
|
-
const isPromotionApplicableToItem = (0, validations_1.areRulesValidForContext)(promotion.application_method?.target_rules, shippingMethodContext
|
13
|
+
const isPromotionApplicableToItem = (0, validations_1.areRulesValidForContext)(promotion.application_method?.target_rules, shippingMethodContext);
|
14
14
|
if (!isPromotionApplicableToItem) {
|
15
15
|
continue;
|
16
16
|
}
|
@@ -29,13 +29,13 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
|
|
29
29
|
continue;
|
30
30
|
}
|
31
31
|
const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0;
|
32
|
-
let promotionValue =
|
33
|
-
const applicableTotal =
|
32
|
+
let promotionValue = applicationMethod?.value ?? 0;
|
33
|
+
const applicableTotal = method.subtotal - appliedPromoValue;
|
34
34
|
if (applicationMethod?.type === utils_1.ApplicationMethodType.PERCENTAGE) {
|
35
|
-
promotionValue =
|
35
|
+
promotionValue = (promotionValue / 100) * applicableTotal;
|
36
36
|
}
|
37
|
-
const amount =
|
38
|
-
if (
|
37
|
+
const amount = Math.min(promotionValue, applicableTotal);
|
38
|
+
if (amount <= 0) {
|
39
39
|
continue;
|
40
40
|
}
|
41
41
|
const budgetExceededAction = (0, usage_1.computeActionForBudgetExceeded)(promotion, amount);
|
@@ -43,7 +43,7 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
|
|
43
43
|
computedActions.push(budgetExceededAction);
|
44
44
|
continue;
|
45
45
|
}
|
46
|
-
methodIdPromoValueMap.set(method.id,
|
46
|
+
methodIdPromoValueMap.set(method.id, appliedPromoValue + amount);
|
47
47
|
computedActions.push({
|
48
48
|
action: utils_1.ComputedActions.ADD_SHIPPING_METHOD_ADJUSTMENT,
|
49
49
|
shipping_method_id: method.id,
|
@@ -55,9 +55,9 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
|
|
55
55
|
if (allocation === utils_1.ApplicationMethodAllocation.ACROSS) {
|
56
56
|
const totalApplicableValue = shippingMethods.reduce((acc, method) => {
|
57
57
|
const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0;
|
58
|
-
return
|
59
|
-
},
|
60
|
-
if (
|
58
|
+
return acc + (method.subtotal ?? 0) - appliedPromoValue;
|
59
|
+
}, 0);
|
60
|
+
if (totalApplicableValue <= 0) {
|
61
61
|
return computedActions;
|
62
62
|
}
|
63
63
|
for (const method of shippingMethods) {
|
@@ -67,13 +67,15 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
|
|
67
67
|
const promotionValue = applicationMethod?.value ?? 0;
|
68
68
|
const applicableTotal = method.subtotal;
|
69
69
|
const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0;
|
70
|
-
|
71
|
-
let applicablePromotionValue =
|
70
|
+
// TODO: should we worry about precision here?
|
71
|
+
let applicablePromotionValue = (applicableTotal / totalApplicableValue) * promotionValue -
|
72
|
+
appliedPromoValue;
|
72
73
|
if (applicationMethod?.type === utils_1.ApplicationMethodType.PERCENTAGE) {
|
73
|
-
applicablePromotionValue =
|
74
|
+
applicablePromotionValue =
|
75
|
+
(promotionValue / 100) * (applicableTotal - appliedPromoValue);
|
74
76
|
}
|
75
|
-
const amount =
|
76
|
-
if (
|
77
|
+
const amount = Math.min(applicablePromotionValue, applicableTotal);
|
78
|
+
if (amount <= 0) {
|
77
79
|
continue;
|
78
80
|
}
|
79
81
|
const budgetExceededAction = (0, usage_1.computeActionForBudgetExceeded)(promotion, amount);
|
@@ -81,7 +83,7 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
|
|
81
83
|
computedActions.push(budgetExceededAction);
|
82
84
|
continue;
|
83
85
|
}
|
84
|
-
methodIdPromoValueMap.set(method.id,
|
86
|
+
methodIdPromoValueMap.set(method.id, appliedPromoValue + amount);
|
85
87
|
computedActions.push({
|
86
88
|
action: utils_1.ComputedActions.ADD_SHIPPING_METHOD_ADJUSTMENT,
|
87
89
|
shipping_method_id: method.id,
|
@@ -1,3 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
export declare function
|
1
|
+
import { CampaignBudgetExceededAction, ComputeActions, PromotionDTO } from "@medusajs/types";
|
2
|
+
export declare function canRegisterUsage(computedAction: ComputeActions): boolean;
|
3
|
+
export declare function computeActionForBudgetExceeded(promotion: PromotionDTO, amount: number): CampaignBudgetExceededAction | void;
|
3
4
|
//# sourceMappingURL=usage.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,cAAc,EACd,YAAY,EACb,MAAM,iBAAiB,CAAA;AAGxB,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAOxE;AAED,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,YAAY,EACvB,MAAM,EAAE,MAAM,GACb,4BAA4B,GAAG,IAAI,CAmBrC"}
|
@@ -1,7 +1,14 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.computeActionForBudgetExceeded = void 0;
|
3
|
+
exports.computeActionForBudgetExceeded = exports.canRegisterUsage = void 0;
|
4
4
|
const utils_1 = require("@medusajs/utils");
|
5
|
+
function canRegisterUsage(computedAction) {
|
6
|
+
return [
|
7
|
+
utils_1.ComputedActions.ADD_ITEM_ADJUSTMENT,
|
8
|
+
utils_1.ComputedActions.ADD_SHIPPING_METHOD_ADJUSTMENT,
|
9
|
+
].includes(computedAction.action);
|
10
|
+
}
|
11
|
+
exports.canRegisterUsage = canRegisterUsage;
|
5
12
|
function computeActionForBudgetExceeded(promotion, amount) {
|
6
13
|
const campaignBudget = promotion.campaign?.budget;
|
7
14
|
if (!campaignBudget) {
|
@@ -9,9 +16,9 @@ function computeActionForBudgetExceeded(promotion, amount) {
|
|
9
16
|
}
|
10
17
|
const campaignBudgetUsed = campaignBudget.used ?? 0;
|
11
18
|
const totalUsed = campaignBudget.type === utils_1.CampaignBudgetType.SPEND
|
12
|
-
?
|
13
|
-
:
|
14
|
-
if (campaignBudget.limit &&
|
19
|
+
? campaignBudgetUsed + amount
|
20
|
+
: campaignBudgetUsed + 1;
|
21
|
+
if (campaignBudget.limit && totalUsed > campaignBudget.limit) {
|
15
22
|
return {
|
16
23
|
action: utils_1.ComputedActions.CAMPAIGN_BUDGET_EXCEEDED,
|
17
24
|
code: promotion.code,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"application-method.d.ts","sourceRoot":"","sources":["../../../src/utils/validations/application-method.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"application-method.d.ts","sourceRoot":"","sources":["../../../src/utils/validations/application-method.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAA;AAE/E,eAAO,MAAM,4BAA4B,EAAE,MAAM,EAGhD,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAM,EAG1C,CAAA;AAED,eAAO,MAAM,4BAA4B,EAAE,MAAM,EAEhD,CAAA;AAED,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,0BAA0B,GAAG,0BAA0B,EAC7D,SAAS,EAAE,SAAS,QA4GrB"}
|
@@ -20,12 +20,12 @@ function validateApplicationMethodAttributes(data, promotion) {
|
|
20
20
|
const targetType = data.target_type || applicationMethod?.target_type;
|
21
21
|
const type = data.type || applicationMethod?.type;
|
22
22
|
const applicationMethodType = data.type || applicationMethod?.type;
|
23
|
-
const value =
|
23
|
+
const value = data.value || applicationMethod.value;
|
24
24
|
const maxQuantity = data.max_quantity || applicationMethod.max_quantity;
|
25
25
|
const allocation = data.allocation || applicationMethod.allocation;
|
26
26
|
const allTargetTypes = Object.values(utils_1.ApplicationMethodTargetType);
|
27
27
|
if (type === utils_1.ApplicationMethodType.PERCENTAGE &&
|
28
|
-
(
|
28
|
+
(typeof value !== "number" || value <= 0 || value > 100)) {
|
29
29
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Application Method value should be a percentage number between 0 and 100`);
|
30
30
|
}
|
31
31
|
if (promotion?.type === utils_1.PromotionType.BUYGET) {
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import {
|
1
|
+
import { PromotionRuleDTO } from "@medusajs/types";
|
2
2
|
import { CreatePromotionRuleDTO } from "../../types";
|
3
3
|
export declare function validatePromotionRuleAttributes(promotionRulesData: CreatePromotionRuleDTO[]): void;
|
4
|
-
export declare function areRulesValidForContext(rules: PromotionRuleDTO[], context: Record<string, any
|
4
|
+
export declare function areRulesValidForContext(rules: PromotionRuleDTO[], context: Record<string, any>): boolean;
|
5
5
|
export declare function evaluateRuleValueCondition(ruleValues: string[], operator: string, ruleValuesToCheck: string[] | string): boolean;
|
6
6
|
//# sourceMappingURL=promotion-rule.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promotion-rule.d.ts","sourceRoot":"","sources":["../../../src/utils/validations/promotion-rule.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"promotion-rule.d.ts","sourceRoot":"","sources":["../../../src/utils/validations/promotion-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA+B,MAAM,iBAAiB,CAAA;AAQ/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAE/C,wBAAgB,+BAA+B,CAC7C,kBAAkB,EAAE,sBAAsB,EAAE,QAiC7C;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,gBAAgB,EAAE,EACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC3B,OAAO,CAgBT;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,MAAM,EAAE,EACpB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,EAAE,GAAG,MAAM,WAiCrC"}
|
@@ -26,37 +26,17 @@ function validatePromotionRuleAttributes(promotionRulesData) {
|
|
26
26
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, errors.join(", "));
|
27
27
|
}
|
28
28
|
exports.validatePromotionRuleAttributes = validatePromotionRuleAttributes;
|
29
|
-
function areRulesValidForContext(rules, context
|
29
|
+
function areRulesValidForContext(rules, context) {
|
30
30
|
return rules.every((rule) => {
|
31
31
|
const validRuleValues = rule.values?.map((ruleValue) => ruleValue.value);
|
32
32
|
if (!rule.attribute) {
|
33
33
|
return false;
|
34
34
|
}
|
35
|
-
const valuesToCheck = (0, utils_1.pickValueFromObject)(
|
35
|
+
const valuesToCheck = (0, utils_1.pickValueFromObject)(rule.attribute, context);
|
36
36
|
return evaluateRuleValueCondition(validRuleValues.filter(utils_1.isString), rule.operator, valuesToCheck);
|
37
37
|
});
|
38
38
|
}
|
39
39
|
exports.areRulesValidForContext = areRulesValidForContext;
|
40
|
-
/*
|
41
|
-
The context here can either be either:
|
42
|
-
- a cart context
|
43
|
-
- an item context under a cart
|
44
|
-
- a shipping method context under a cart
|
45
|
-
|
46
|
-
The rule's attributes are set from the perspective of the cart context. For example: items.product.id
|
47
|
-
|
48
|
-
When the context here is item or shipping_method, we need to drop the "items."" or "shipping_method."
|
49
|
-
from the rule attribute string to accurate pick the values from the context.
|
50
|
-
*/
|
51
|
-
function fetchRuleAttributeForContext(ruleAttribute, contextScope) {
|
52
|
-
if (contextScope === utils_1.ApplicationMethodTargetType.ITEMS) {
|
53
|
-
ruleAttribute = ruleAttribute.replace(`${utils_1.ApplicationMethodTargetType.ITEMS}.`, "");
|
54
|
-
}
|
55
|
-
if (contextScope === utils_1.ApplicationMethodTargetType.SHIPPING_METHODS) {
|
56
|
-
ruleAttribute = ruleAttribute.replace(`${utils_1.ApplicationMethodTargetType.SHIPPING_METHODS}.`, "");
|
57
|
-
}
|
58
|
-
return ruleAttribute;
|
59
|
-
}
|
60
40
|
function evaluateRuleValueCondition(ruleValues, operator, ruleValuesToCheck) {
|
61
41
|
if (!Array.isArray(ruleValuesToCheck)) {
|
62
42
|
ruleValuesToCheck = [ruleValuesToCheck];
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@medusajs/promotion",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.6",
|
4
4
|
"description": "Medusa Promotion module",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -8,7 +8,10 @@
|
|
8
8
|
"dist"
|
9
9
|
],
|
10
10
|
"engines": {
|
11
|
-
"node": ">=
|
11
|
+
"node": ">=16"
|
12
|
+
},
|
13
|
+
"bin": {
|
14
|
+
"medusa-promotion-seed": "dist/scripts/bin/run-seed.js"
|
12
15
|
},
|
13
16
|
"repository": {
|
14
17
|
"type": "git",
|
@@ -23,6 +26,7 @@
|
|
23
26
|
"scripts": {
|
24
27
|
"watch": "tsc --build --watch",
|
25
28
|
"watch:test": "tsc --build tsconfig.spec.json --watch",
|
29
|
+
"prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
|
26
30
|
"build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
|
27
31
|
"test": "jest --runInBand --passWithNoTests --bail --forceExit -- src",
|
28
32
|
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
@@ -33,11 +37,10 @@
|
|
33
37
|
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
34
38
|
},
|
35
39
|
"devDependencies": {
|
36
|
-
"@medusajs/types": "1.12.0-snapshot-20240916110643",
|
37
40
|
"@mikro-orm/cli": "5.9.7",
|
38
41
|
"cross-env": "^5.2.1",
|
39
|
-
"jest": "^29.
|
40
|
-
"medusa-test-utils": "1.1.45
|
42
|
+
"jest": "^29.6.3",
|
43
|
+
"medusa-test-utils": "^1.1.45",
|
41
44
|
"rimraf": "^3.0.2",
|
42
45
|
"ts-jest": "^29.1.1",
|
43
46
|
"ts-node": "^10.9.1",
|
@@ -45,12 +48,14 @@
|
|
45
48
|
"typescript": "^5.1.6"
|
46
49
|
},
|
47
50
|
"dependencies": {
|
48
|
-
"@medusajs/
|
49
|
-
|
50
|
-
|
51
|
+
"@medusajs/modules-sdk": "^1.12.12",
|
52
|
+
"@medusajs/types": "^1.11.17",
|
53
|
+
"@medusajs/utils": "1.11.11",
|
51
54
|
"@mikro-orm/core": "5.9.7",
|
52
55
|
"@mikro-orm/migrations": "5.9.7",
|
53
56
|
"@mikro-orm/postgresql": "5.9.7",
|
54
|
-
"awilix": "^8.0.
|
57
|
+
"awilix": "^8.0.0",
|
58
|
+
"dotenv": "^16.4.5",
|
59
|
+
"knex": "2.4.2"
|
55
60
|
}
|
56
61
|
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Migration20240617102917.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240617102917.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAUnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ5B"}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Migration20240617102917 = void 0;
|
4
|
-
const migrations_1 = require("@mikro-orm/migrations");
|
5
|
-
class Migration20240617102917 extends migrations_1.Migration {
|
6
|
-
async up() {
|
7
|
-
this.addSql('alter table "promotion_application_method" alter column "currency_code" type text using ("currency_code"::text);');
|
8
|
-
this.addSql('alter table "promotion_application_method" alter column "currency_code" drop not null;');
|
9
|
-
}
|
10
|
-
async down() {
|
11
|
-
this.addSql('alter table "promotion_application_method" alter column "currency_code" type text using ("currency_code"::text);');
|
12
|
-
this.addSql('alter table "promotion_application_method" alter column "currency_code" set not null;');
|
13
|
-
}
|
14
|
-
}
|
15
|
-
exports.Migration20240617102917 = Migration20240617102917;
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"Migration20240624153824.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240624153824.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IASnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ5B"}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Migration20240624153824 = void 0;
|
4
|
-
const migrations_1 = require("@mikro-orm/migrations");
|
5
|
-
class Migration20240624153824 extends migrations_1.Migration {
|
6
|
-
async up() {
|
7
|
-
this.addSql('alter table if exists "promotion_campaign" drop constraint if exists "IDX_campaign_identifier_unique";');
|
8
|
-
this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_promotion_campaign_campaign_identifier_unique" ON "promotion_campaign" (campaign_identifier) WHERE deleted_at IS NULL;');
|
9
|
-
}
|
10
|
-
async down() {
|
11
|
-
this.addSql('drop index if exists "IDX_promotion_campaign_campaign_identifier_unique";');
|
12
|
-
this.addSql('alter table if exists "promotion_campaign" add constraint "IDX_campaign_identifier_unique" unique ("campaign_identifier");');
|
13
|
-
}
|
14
|
-
}
|
15
|
-
exports.Migration20240624153824 = Migration20240624153824;
|