chore(): Reorganize modules (#7210)
**What** Move all modules to the modules directory
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { CreatePriceRuleDTO } from "@medusajs/types"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export const defaultPriceRuleData = [
|
||||
{
|
||||
id: "price-rule-1",
|
||||
price_set_id: "price-set-1",
|
||||
rule_type_id: "rule-type-1",
|
||||
value: "USD",
|
||||
price_list_id: "test",
|
||||
price_id: "price-set-money-amount-USD",
|
||||
},
|
||||
{
|
||||
id: "price-rule-2",
|
||||
price_set_id: "price-set-2",
|
||||
rule_type_id: "rule-type-2",
|
||||
value: "region_1",
|
||||
price_list_id: "test",
|
||||
price_id: "price-set-money-amount-EUR",
|
||||
},
|
||||
] as unknown as CreatePriceRuleDTO[]
|
||||
@@ -0,0 +1,30 @@
|
||||
import { PriceRule } from "@models"
|
||||
|
||||
import { CreatePriceRuleDTO } from "@medusajs/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { defaultPriceRuleData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
export async function createPriceRules(
|
||||
manager: SqlEntityManager,
|
||||
pricesRulesData: CreatePriceRuleDTO[] = defaultPriceRuleData
|
||||
): Promise<PriceRule[]> {
|
||||
const priceRules: PriceRule[] = []
|
||||
|
||||
for (let priceRuleData of pricesRulesData) {
|
||||
const priceRuleDataClone: CreatePriceRuleDTO = { ...priceRuleData }
|
||||
|
||||
priceRuleDataClone.price_set_id = priceRuleDataClone.price_set_id
|
||||
priceRuleDataClone.rule_type_id = priceRuleDataClone.rule_type_id
|
||||
priceRuleDataClone.price_id = priceRuleDataClone.price_id
|
||||
|
||||
const priceRule = manager.create(PriceRule, priceRuleDataClone)
|
||||
|
||||
priceRules.push(priceRule)
|
||||
}
|
||||
|
||||
await manager.persistAndFlush(priceRules)
|
||||
|
||||
return priceRules
|
||||
}
|
||||
Reference in New Issue
Block a user