chore: merge money amounts and price set money amounts (#6768)
what: - merges price set money amounts and money amount
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
export const defaultMoneyAmountsData = [
|
||||
{
|
||||
id: "money-amount-USD",
|
||||
currency_code: "USD",
|
||||
amount: 500,
|
||||
min_quantity: 1,
|
||||
max_quantity: 10,
|
||||
},
|
||||
{
|
||||
id: "money-amount-EUR",
|
||||
currency_code: "EUR",
|
||||
amount: 400,
|
||||
min_quantity: 1,
|
||||
max_quantity: 5,
|
||||
},
|
||||
{
|
||||
id: "money-amount-CAD",
|
||||
currency_code: "CAD",
|
||||
amount: 600,
|
||||
min_quantity: 1,
|
||||
max_quantity: 8,
|
||||
},
|
||||
]
|
||||
@@ -1,22 +0,0 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { MoneyAmount } from "@models"
|
||||
import { defaultMoneyAmountsData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createMoneyAmounts(
|
||||
manager: SqlEntityManager,
|
||||
moneyAmountsData: any[] = defaultMoneyAmountsData
|
||||
): Promise<MoneyAmount[]> {
|
||||
const moneyAmounts: MoneyAmount[] = []
|
||||
|
||||
for (let moneyAmountData of moneyAmountsData) {
|
||||
const moneyAmount = manager.create(MoneyAmount, moneyAmountData)
|
||||
|
||||
moneyAmounts.push(moneyAmount)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(moneyAmounts)
|
||||
|
||||
return moneyAmounts
|
||||
}
|
||||
@@ -1,23 +1,26 @@
|
||||
export const defaultPriceSetMoneyAmountsData = [
|
||||
{
|
||||
id: "price-set-money-amount-USD",
|
||||
currency_code: "USD",
|
||||
amount: 500,
|
||||
title: "price set money amount USD",
|
||||
price_set_id: "price-set-1",
|
||||
money_amount_id: "money-amount-USD",
|
||||
rules_count: 1,
|
||||
},
|
||||
{
|
||||
id: "price-set-money-amount-EUR",
|
||||
currency_code: "EUR",
|
||||
amount: 400,
|
||||
title: "price set money amount EUR",
|
||||
price_set_id: "price-set-2",
|
||||
money_amount_id: "money-amount-EUR",
|
||||
rules_count: 1,
|
||||
},
|
||||
{
|
||||
id: "price-set-money-amount-CAD",
|
||||
currency_code: "CAD",
|
||||
amount: 600,
|
||||
title: "price set money amount CAD",
|
||||
price_set_id: "price-set-3",
|
||||
money_amount_id: "money-amount-CAD",
|
||||
rules_count: 1,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -13,17 +13,17 @@ export async function createPriceSets(
|
||||
|
||||
for (let priceSetData of priceSetsData) {
|
||||
const priceSetDataClone = { ...priceSetData }
|
||||
const moneyAmountsData = priceSetDataClone.prices || []
|
||||
const psmas = priceSetDataClone.prices || []
|
||||
delete priceSetDataClone.prices
|
||||
|
||||
let priceSet = manager.create(PriceSet, priceSetDataClone) as PriceSet
|
||||
|
||||
manager.persist(priceSet)
|
||||
|
||||
for (let moneyAmount of moneyAmountsData) {
|
||||
for (let psmaData of psmas) {
|
||||
const psma = manager.create(PriceSetMoneyAmount, {
|
||||
price_set: priceSet,
|
||||
money_amount_id: moneyAmount.id,
|
||||
...psmaData,
|
||||
price_set_id: priceSet.id,
|
||||
title: "test",
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
import { createMoneyAmounts, defaultMoneyAmountsData } from "./money-amount"
|
||||
import { createPriceRules, defaultPriceRuleData } from "./price-rule"
|
||||
import { createPriceSets, defaultPriceSetsData } from "./price-set"
|
||||
import {
|
||||
@@ -14,14 +12,12 @@ jest.setTimeout(30000)
|
||||
export async function seedPriceData(
|
||||
testManager: SqlEntityManager,
|
||||
{
|
||||
moneyAmountsData = defaultMoneyAmountsData,
|
||||
priceSetsData = defaultPriceSetsData,
|
||||
priceRuleData = defaultPriceRuleData,
|
||||
priceSetMoneyAmountsData = defaultPriceSetMoneyAmountsData,
|
||||
ruleTypesData = defaultRuleTypesData,
|
||||
} = {}
|
||||
) {
|
||||
await createMoneyAmounts(testManager, moneyAmountsData)
|
||||
await createPriceSets(testManager, priceSetsData)
|
||||
await createPriceSetMoneyAmounts(testManager, priceSetMoneyAmountsData)
|
||||
await createRuleTypes(testManager, ruleTypesData)
|
||||
|
||||
Reference in New Issue
Block a user