feat: Completely revamp the pricing module (#7852)
* feat: Completely revamp the pricing module * chore: Update all places to the new pricing interfaces * fix: Remove unnecessary join to itself * chore: Add data migration for existing users * fix: Apply the correct index to price rule
This commit is contained in:
@@ -2,11 +2,13 @@ export const defaultPriceListRuleData = [
|
||||
{
|
||||
id: "price-list-rule-1",
|
||||
price_list_id: "price-list-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
attribute: "currency_code",
|
||||
value: [],
|
||||
},
|
||||
{
|
||||
id: "price-list-rule-2",
|
||||
price_list_id: "price-list-1",
|
||||
rule_type_id: "rule-type-2",
|
||||
attribute: "region_id",
|
||||
value: [],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -6,7 +6,7 @@ export const defaultPriceRuleData = [
|
||||
{
|
||||
id: "price-rule-1",
|
||||
price_set_id: "price-set-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
attribute: "currency_code",
|
||||
value: "USD",
|
||||
price_list_id: "test",
|
||||
price_id: "price-set-money-amount-USD",
|
||||
@@ -14,7 +14,7 @@ export const defaultPriceRuleData = [
|
||||
{
|
||||
id: "price-rule-2",
|
||||
price_set_id: "price-set-2",
|
||||
rule_type_id: "rule-type-2",
|
||||
attribute: "region_id",
|
||||
value: "region_1",
|
||||
price_list_id: "test",
|
||||
price_id: "price-set-money-amount-EUR",
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function createPriceRules(
|
||||
const priceRuleDataClone: CreatePriceRuleDTO = { ...priceRuleData }
|
||||
|
||||
priceRuleDataClone.price_set_id = priceRuleDataClone.price_set_id
|
||||
priceRuleDataClone.rule_type_id = priceRuleDataClone.rule_type_id
|
||||
priceRuleDataClone.attribute = priceRuleDataClone.attribute
|
||||
priceRuleDataClone.price_id = priceRuleDataClone.price_id
|
||||
|
||||
const priceRule = manager.create(PriceRule, priceRuleDataClone)
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
export const defaultRuleTypesData = [
|
||||
{
|
||||
id: "rule-type-1",
|
||||
name: "rule 1",
|
||||
rule_attribute: "currency_code",
|
||||
},
|
||||
{
|
||||
id: "rule-type-2",
|
||||
name: "rule 2",
|
||||
rule_attribute: "region_id",
|
||||
},
|
||||
]
|
||||
@@ -1,22 +0,0 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { RuleType } from "@models"
|
||||
import { defaultRuleTypesData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createRuleTypes(
|
||||
manager: SqlEntityManager,
|
||||
ruletypesData: any[] = defaultRuleTypesData
|
||||
): Promise<RuleType[]> {
|
||||
const ruleTypes: RuleType[] = []
|
||||
|
||||
for (let ruleTypeData of ruletypesData) {
|
||||
const ruleType = manager.create(RuleType, ruleTypeData)
|
||||
|
||||
ruleTypes.push(ruleType)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(ruleTypes)
|
||||
|
||||
return ruleTypes
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { createPrices, defaultPricesData } from "./price"
|
||||
import { createPriceRules, defaultPriceRuleData } from "./price-rule"
|
||||
import { createPriceSets, defaultPriceSetsData } from "./price-set"
|
||||
import { createRuleTypes, defaultRuleTypesData } from "./rule-type"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -12,11 +11,9 @@ export async function seedPriceData(
|
||||
priceSetsData = defaultPriceSetsData,
|
||||
priceRuleData = defaultPriceRuleData,
|
||||
pricesData = defaultPricesData,
|
||||
ruleTypesData = defaultRuleTypesData,
|
||||
} = {}
|
||||
) {
|
||||
await createPriceSets(testManager, priceSetsData)
|
||||
await createPrices(testManager, pricesData)
|
||||
await createRuleTypes(testManager, ruleTypesData)
|
||||
await createPriceRules(testManager, priceRuleData)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user