fix(medusa,pricing,types): rules only gets updated/deleted upon passing an explicit object (#5711)

This commit is contained in:
Riqwan Thamir
2023-11-24 13:54:23 +00:00
committed by GitHub
parent 07934cdaac
commit fc1ef29ed9
5 changed files with 124 additions and 53 deletions
@@ -99,22 +99,22 @@ export default async (req, res) => {
if (featureFlagRouter.isFeatureEnabled(MedusaV2Flag.key)) {
const updateVariantsWorkflow = updatePriceLists(req.scope)
const rules: PricingTypes.CreatePriceListRules = {}
const customerGroups = validated.customer_groups || []
const customerGroups = validated.customer_groups
delete validated.customer_groups
if (customerGroups.length) {
rules["customer_group_id"] = customerGroups.map((group) => group.id)
const updatePriceListInput = {
id,
...validated,
} as PricingTypes.UpdatePriceListDTO
if (Array.isArray(customerGroups)) {
updatePriceListInput.rules = {
customer_group_id: customerGroups.map((group) => group.id),
}
}
const input = {
price_lists: [
{
id,
...validated,
rules,
},
],
price_lists: [updatePriceListInput],
} as WorkflowTypes.PriceListWorkflow.UpdatePriceListWorkflowInputDTO
await updateVariantsWorkflow.run({