refactor: migrate pricing entities to DML models (#10335)
Fixes: FRMW-2810 ## Breaking changes There is only one breaking change - The `min_quantity` and `max_quantity` properties are now consistently typed as numbers. Earlier, it was [typed as numbers](https://github.com/medusajs/medusa/blob/develop/integration-tests/http/__tests__/price-list/admin/price-list.spec.ts#L68-L69) in some API responses and as [string in others](https://github.com/medusajs/medusa/blob/develop/integration-tests/http/__tests__/price-list/admin/price-list.spec.ts#L186-L187). I did not go to the bottom of this inconsistency, but the tests reveals them. Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
co-authored by
Adrien de Peretti
parent
b4d6a4b3f0
commit
913cf15e2b
@@ -1,5 +1,6 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PriceListRule } from "@models"
|
||||
import { toMikroORMEntity } from "@medusajs/framework/utils"
|
||||
import { defaultPriceListRuleData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
@@ -11,7 +12,7 @@ export async function createPriceListRules(
|
||||
const priceListRules: PriceListRule[] = []
|
||||
|
||||
for (let data of priceListRuleData) {
|
||||
const plr = manager.create(PriceListRule, data)
|
||||
const plr = manager.create(toMikroORMEntity(PriceListRule), data)
|
||||
|
||||
priceListRules.push(plr)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { PriceList } from "@models"
|
||||
import { toMikroORMEntity } from "@medusajs/framework/utils"
|
||||
import { defaultPriceListData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
@@ -11,7 +12,7 @@ export async function createPriceLists(
|
||||
const priceLists: PriceList[] = []
|
||||
|
||||
for (let data of priceListData) {
|
||||
const pl = manager.create(PriceList, data)
|
||||
const pl = manager.create(toMikroORMEntity(PriceList), data)
|
||||
|
||||
priceLists.push(pl)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { PriceRule } from "@models"
|
||||
|
||||
import { CreatePriceRuleDTO } from "@medusajs/framework/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { toMikroORMEntity } from "@medusajs/framework/utils"
|
||||
import { defaultPriceRuleData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
@@ -20,7 +21,10 @@ export async function createPriceRules(
|
||||
priceRuleDataClone.attribute = priceRuleDataClone.attribute
|
||||
priceRuleDataClone.price_id = priceRuleDataClone.price_id
|
||||
|
||||
const priceRule = manager.create(PriceRule, priceRuleDataClone)
|
||||
const priceRule = manager.create(
|
||||
toMikroORMEntity(PriceRule),
|
||||
priceRuleDataClone
|
||||
)
|
||||
|
||||
priceRules.push(priceRule)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { CreatePriceSetDTO } from "@medusajs/framework/types"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Price, PriceSet } from "@models"
|
||||
import { toMikroORMEntity } from "@medusajs/framework/utils"
|
||||
import { defaultPriceSetsData } from "./data"
|
||||
|
||||
export * from "./data"
|
||||
@@ -16,12 +17,15 @@ export async function createPriceSets(
|
||||
const prices = priceSetDataClone.prices || []
|
||||
delete priceSetDataClone.prices
|
||||
|
||||
let priceSet = manager.create(PriceSet, priceSetDataClone) as PriceSet
|
||||
let priceSet = manager.create(
|
||||
toMikroORMEntity(PriceSet),
|
||||
priceSetDataClone
|
||||
) as PriceSet
|
||||
|
||||
manager.persist(priceSet)
|
||||
|
||||
for (let priceData of prices) {
|
||||
const price = manager.create(Price, {
|
||||
const price = manager.create(toMikroORMEntity(Price), {
|
||||
...priceData,
|
||||
price_set_id: priceSet.id,
|
||||
title: "test",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { Price } from "@models"
|
||||
import { defaultPricesData } from "./data"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { toMikroORMEntity } from "@medusajs/framework/utils"
|
||||
|
||||
export * from "./data"
|
||||
|
||||
@@ -11,7 +12,7 @@ export async function createPrices(
|
||||
const prices: Price[] = []
|
||||
|
||||
for (let data of pricesData) {
|
||||
const price = manager.create(Price, data)
|
||||
const price = manager.create(toMikroORMEntity(Price), data)
|
||||
prices.push(price)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user