feat(core-flows,medusa,types,utils): rename psma to prices (#6796)
What: Renames pricesetmoneyamount to prices Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
co-authored by
Adrien de Peretti
parent
fbc369705d
commit
9073d7aba3
@@ -14,7 +14,7 @@ export const getExistingPriceListsPriceIdsStep = createStep(
|
||||
)
|
||||
|
||||
const existingPrices = priceListIds.length
|
||||
? await pricingModule.listPriceSetMoneyAmounts(
|
||||
? await pricingModule.listPrices(
|
||||
{ price_list_id: priceListIds },
|
||||
{ relations: ["price_list"] }
|
||||
)
|
||||
|
||||
@@ -14,18 +14,16 @@ export const removePriceListPricesStep = createStep(
|
||||
ModuleRegistrationName.PRICING
|
||||
)
|
||||
|
||||
const psmas = await pricingModule.listPriceSetMoneyAmounts(
|
||||
const prices = await pricingModule.listPrices(
|
||||
{ id: ids },
|
||||
{ relations: ["price_list"] }
|
||||
)
|
||||
|
||||
await pricingModule.softDeletePriceSetMoneyAmounts(
|
||||
psmas.map((psma) => psma.id)
|
||||
)
|
||||
await pricingModule.softDeletePrices(prices.map((price) => price.id))
|
||||
|
||||
return new StepResponse(
|
||||
null,
|
||||
psmas.map((psma) => psma.id)
|
||||
prices.map((price) => price.id)
|
||||
)
|
||||
},
|
||||
async (ids, { container }) => {
|
||||
@@ -37,6 +35,6 @@ export const removePriceListPricesStep = createStep(
|
||||
ModuleRegistrationName.PRICING
|
||||
)
|
||||
|
||||
await pricingModule.restorePriceSetMoneyAmounts(ids)
|
||||
await pricingModule.restorePrices(ids)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
IPricingModuleService,
|
||||
PriceSetMoneyAmountDTO,
|
||||
PriceDTO,
|
||||
UpdatePriceListPriceDTO,
|
||||
UpdatePriceListPricesDTO,
|
||||
UpdatePriceListPriceWorkflowStepDTO,
|
||||
@@ -42,26 +42,26 @@ export const updatePriceListPricesStep = createStep(
|
||||
}
|
||||
|
||||
const existingPrices = priceIds.length
|
||||
? await pricingModule.listPriceSetMoneyAmounts(
|
||||
? await pricingModule.listPrices(
|
||||
{ id: priceIds },
|
||||
{ relations: ["price_list"] }
|
||||
)
|
||||
: []
|
||||
|
||||
const priceListPsmaMap = new Map<string, PriceSetMoneyAmountDTO[]>()
|
||||
const priceListPricesMap = new Map<string, PriceDTO[]>()
|
||||
const dataBeforePriceUpdate: UpdatePriceListPricesDTO[] = []
|
||||
|
||||
for (const price of existingPrices) {
|
||||
const priceListId = price.price_list!.id
|
||||
const psmas = priceListPsmaMap.get(priceListId) || []
|
||||
const prices = priceListPricesMap.get(priceListId) || []
|
||||
|
||||
priceListPsmaMap.set(priceListId, psmas)
|
||||
priceListPricesMap.set(priceListId, prices)
|
||||
}
|
||||
|
||||
for (const [priceListId, psmas] of Object.entries(priceListPsmaMap)) {
|
||||
for (const [priceListId, prices] of Object.entries(priceListPricesMap)) {
|
||||
dataBeforePriceUpdate.push({
|
||||
price_list_id: priceListId,
|
||||
prices: buildPriceSetPricesForModule(psmas),
|
||||
prices: buildPriceSetPricesForModule(prices),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
CreatePriceListPriceDTO,
|
||||
CreatePriceListPriceWorkflowDTO,
|
||||
IPricingModuleService,
|
||||
PriceSetMoneyAmountDTO,
|
||||
PriceDTO,
|
||||
UpdatePriceListPriceDTO,
|
||||
UpdatePriceListPriceWorkflowDTO,
|
||||
UpdatePriceListPricesDTO,
|
||||
@@ -56,33 +56,30 @@ export const upsertPriceListPricesStep = createStep(
|
||||
}
|
||||
}
|
||||
|
||||
const updatedPriceSetMoneyAmounts =
|
||||
await pricingModule.listPriceSetMoneyAmounts(
|
||||
{
|
||||
id: priceListPricesToUpdate
|
||||
.map((priceListData) =>
|
||||
priceListData.prices.map((price) => price.id)
|
||||
)
|
||||
.filter(Boolean)
|
||||
.flat(1),
|
||||
},
|
||||
{ relations: ["price_list"] }
|
||||
)
|
||||
const updatedPrices = await pricingModule.listPrices(
|
||||
{
|
||||
id: priceListPricesToUpdate
|
||||
.map((priceListData) => priceListData.prices.map((price) => price.id))
|
||||
.filter(Boolean)
|
||||
.flat(1),
|
||||
},
|
||||
{ relations: ["price_list"] }
|
||||
)
|
||||
|
||||
const priceListPsmaMap = new Map<string, PriceSetMoneyAmountDTO[]>()
|
||||
const priceListPricesMap = new Map<string, PriceDTO[]>()
|
||||
const dataBeforePriceUpdate: UpdatePriceListPricesDTO[] = []
|
||||
|
||||
for (const priceSetMoneyAmount of updatedPriceSetMoneyAmounts) {
|
||||
const priceListId = priceSetMoneyAmount.price_list!.id
|
||||
const psmas = priceListPsmaMap.get(priceListId) || []
|
||||
for (const updatedPrice of updatedPrices) {
|
||||
const priceListId = updatedPrice.price_list!.id
|
||||
const prices = priceListPricesMap.get(priceListId) || []
|
||||
|
||||
priceListPsmaMap.set(priceListId, psmas)
|
||||
priceListPricesMap.set(priceListId, prices)
|
||||
}
|
||||
|
||||
for (const [priceListId, psmas] of Object.entries(priceListPsmaMap)) {
|
||||
for (const [priceListId, prices] of Object.entries(priceListPricesMap)) {
|
||||
dataBeforePriceUpdate.push({
|
||||
price_list_id: priceListId,
|
||||
prices: buildPriceSetPricesForModule(psmas),
|
||||
prices: buildPriceSetPricesForModule(prices),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user