fix: Disallow creating duplicate prices (#7866)
* fix: Disallow creating duplicate prices * fix: Don't pass id to manager create in upsertWithReplace
This commit is contained in:
@@ -2,6 +2,7 @@ import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
AddPriceListPricesDTO,
|
||||
CreatePriceListPriceDTO,
|
||||
CreatePriceListPriceWorkflowDTO,
|
||||
CreatePriceListPricesWorkflowStepDTO,
|
||||
IPricingModuleService,
|
||||
} from "@medusajs/types"
|
||||
@@ -22,10 +23,12 @@ export const createPriceListPricesStep = createStep(
|
||||
const pricesToAdd: CreatePriceListPriceDTO[] = []
|
||||
|
||||
for (const price of prices) {
|
||||
pricesToAdd.push({
|
||||
const toPush = {
|
||||
...price,
|
||||
price_set_id: variantPriceSetMap[price.variant_id!],
|
||||
})
|
||||
} as CreatePriceListPriceDTO
|
||||
delete (toPush as Partial<CreatePriceListPriceWorkflowDTO>).variant_id
|
||||
pricesToAdd.push(toPush)
|
||||
}
|
||||
|
||||
if (pricesToAdd.length) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
PriceDTO,
|
||||
UpdatePriceListPriceDTO,
|
||||
UpdatePriceListPricesDTO,
|
||||
UpdatePriceListPriceWorkflowDTO,
|
||||
UpdatePriceListPriceWorkflowStepDTO,
|
||||
} from "@medusajs/types"
|
||||
import { buildPriceSetPricesForModule } from "@medusajs/utils"
|
||||
@@ -25,10 +26,13 @@ export const updatePriceListPricesStep = createStep(
|
||||
const { prices = [], id } = priceListData
|
||||
|
||||
for (const price of prices) {
|
||||
pricesToUpdate.push({
|
||||
const toPush = {
|
||||
...price,
|
||||
price_set_id: variantPriceSetMap[price.variant_id!],
|
||||
})
|
||||
} as UpdatePriceListPriceDTO
|
||||
delete (toPush as Partial<UpdatePriceListPriceWorkflowDTO>).variant_id
|
||||
|
||||
pricesToUpdate.push(toPush)
|
||||
|
||||
if (price.id) {
|
||||
priceIds.push(price.id)
|
||||
|
||||
Reference in New Issue
Block a user