fix(core-flows, types, medusa): fix batch delete types in workflows and routes (#8974)
- Fix the returned data of batch delete steps / workflows for deleted records to just be the array of IDs. - Add a new type `BatchResponse` for API routes to have a different shape for deleted records - Update batch delete helpers to return the expected shape for API routes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
BatchMethodResponse,
|
||||
BatchResponse,
|
||||
HttpTypes,
|
||||
LinkDefinition,
|
||||
MedusaContainer,
|
||||
@@ -125,7 +126,7 @@ export const refetchBatchProducts = async (
|
||||
batchResult: BatchMethodResponse<ProductDTO>,
|
||||
scope: MedusaContainer,
|
||||
fields: string[]
|
||||
) => {
|
||||
): Promise<BatchResponse<ProductDTO>> => {
|
||||
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
let created = Promise.resolve<ProductDTO[]>([])
|
||||
let updated = Promise.resolve<ProductDTO[]>([])
|
||||
@@ -160,7 +161,11 @@ export const refetchBatchProducts = async (
|
||||
return {
|
||||
created: createdRes,
|
||||
updated: updatedRes,
|
||||
deleted: batchResult.deleted,
|
||||
deleted: {
|
||||
ids: batchResult.deleted,
|
||||
object: "product",
|
||||
deleted: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +173,7 @@ export const refetchBatchVariants = async (
|
||||
batchResult: BatchMethodResponse<ProductVariantDTO>,
|
||||
scope: MedusaContainer,
|
||||
fields: string[]
|
||||
) => {
|
||||
): Promise<BatchResponse<ProductVariantDTO>> => {
|
||||
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
let created = Promise.resolve<ProductVariantDTO[]>([])
|
||||
let updated = Promise.resolve<ProductVariantDTO[]>([])
|
||||
@@ -203,7 +208,11 @@ export const refetchBatchVariants = async (
|
||||
return {
|
||||
created: createdRes,
|
||||
updated: updatedRes,
|
||||
deleted: batchResult.deleted,
|
||||
deleted: {
|
||||
ids: batchResult.deleted,
|
||||
object: "variant",
|
||||
deleted: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BatchMethodResponse } from "@medusajs/types"
|
||||
import { BatchMethodResponse, BatchResponse } from "@medusajs/types"
|
||||
import { PromotionRuleDTO, MedusaContainer } from "@medusajs/types"
|
||||
import {
|
||||
promiseAll,
|
||||
@@ -28,7 +28,7 @@ export const refetchBatchRules = async (
|
||||
batchResult: BatchMethodResponse<PromotionRuleDTO>,
|
||||
scope: MedusaContainer,
|
||||
fields: string[]
|
||||
) => {
|
||||
): Promise<BatchResponse<PromotionRuleDTO>> => {
|
||||
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
let created = Promise.resolve<PromotionRuleDTO[]>([])
|
||||
let updated = Promise.resolve<PromotionRuleDTO[]>([])
|
||||
@@ -63,6 +63,10 @@ export const refetchBatchRules = async (
|
||||
return {
|
||||
created: createdRes,
|
||||
updated: updatedRes,
|
||||
deleted: batchResult.deleted,
|
||||
deleted: {
|
||||
ids: batchResult.deleted,
|
||||
object: "promotion-rule",
|
||||
deleted: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,10 @@ export const refetchBatchRules = async (
|
||||
return {
|
||||
created: createdRes,
|
||||
updated: updatedRes,
|
||||
deleted: batchResult.deleted,
|
||||
deleted: {
|
||||
ids: batchResult.deleted,
|
||||
object: "shipping_option_rule",
|
||||
deleted: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user