feat(pricing) Add Price Set Rule Type (#4977)
* initial * initial service * update pricing module service * add integration test for rule-type * update pricing-module integration tests * update pricing service interface * feat(pricing): PriceSets as entry point to pricing module * chore: add price set money amount * chore: add price set money amount * chore: change name of test * chore: added changeset * chore: use filterable props from money amount in price sets * chore: update migrations * test update integration test * fix weird behavior * Update packages/pricing/integration-tests/__fixtures__/rule-type/index.ts Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * Apply suggestions from code review Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> * move rule-type to common * chore: reset migration * chore: remove incorrect conflicts * chore: address review * chore: remove ghost price list * Apply suggestions from code review Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com> * update id prefix * use persist not persistAndflush * rename key_value to rule_attribute * more renaming --------- Co-authored-by: Riqwan Thamir <rmthamir@gmail.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Riqwan Thamir
Oli Juhl
parent
5b09f816cb
commit
edf90eecb4
@@ -1,36 +0,0 @@
|
||||
|
||||
export const defaultPriceListData = [
|
||||
{
|
||||
name: 'pl-1',
|
||||
description: 'pl-1',
|
||||
prices: [ {
|
||||
id: "money-amount-USD",
|
||||
currency_code: "USD",
|
||||
amount: 500,
|
||||
min_quantity: 1,
|
||||
max_quantity: 10,
|
||||
price_list_id: 'pl-1'
|
||||
},
|
||||
{
|
||||
id: "money-amount-EUR",
|
||||
currency_code: "EUR",
|
||||
amount: 400,
|
||||
min_quantity: 1,
|
||||
max_quantity: 5,
|
||||
price_list_id: 'pl-1'
|
||||
}]
|
||||
},
|
||||
{
|
||||
id: 'pl-2',
|
||||
name: 'pl-2',
|
||||
description: 'pl-2',
|
||||
prices: [{
|
||||
id: "money-amount-CAD",
|
||||
currency_code: "CAD",
|
||||
amount: 600,
|
||||
min_quantity: 1,
|
||||
max_quantity: 8,
|
||||
price_list_id: 'pl-2'
|
||||
}]
|
||||
}
|
||||
]
|
||||
@@ -1,25 +0,0 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { MoneyAmount, PriceList } from "@models"
|
||||
import { defaultPriceListData } from "./data"
|
||||
|
||||
export async function createPriceLists(
|
||||
manager: SqlEntityManager,
|
||||
priceListsData: any[] = defaultPriceListData,
|
||||
): Promise<MoneyAmount[]> {
|
||||
const priceLists: PriceList[] = []
|
||||
const moneyAmounts: MoneyAmount[] = []
|
||||
|
||||
for (let priceListdata of priceListsData) {
|
||||
const { prices, ...rest } = priceListdata
|
||||
const priceList = manager.create(MoneyAmount, rest)
|
||||
priceLists.push(priceList)
|
||||
|
||||
const createdPrices = manager.create(MoneyAmount, prices)
|
||||
moneyAmounts.push(createdPrices)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(priceLists)
|
||||
await manager.persistAndFlush(moneyAmounts)
|
||||
|
||||
return priceLists
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
export const defaultRuleTypesData = [
|
||||
{
|
||||
id: "rule-type-1",
|
||||
name: "rule 1",
|
||||
rule_attribute: "region_id",
|
||||
},
|
||||
{
|
||||
id: "rule-type-2",
|
||||
name: "rule 2",
|
||||
rule_attribute: "currency_code",
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { RuleType } from "@models"
|
||||
import { defaultRuleTypesData } 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
|
||||
}
|
||||
Reference in New Issue
Block a user