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 parent
f063a69632
commit
ee3580efdb
12 files changed
+48
-40
No files matched your search
@@ -33,7 +33,7 @@ export const deleteShippingOptionRulesStep = createStep(
|
|||||||
|
|
||||||
await fulfillmentModule.deleteShippingOptionRules(ids)
|
await fulfillmentModule.deleteShippingOptionRules(ids)
|
||||||
|
|
||||||
return new StepResponse(null, shippingOptionRules)
|
return new StepResponse(ids, shippingOptionRules)
|
||||||
},
|
},
|
||||||
async (shippingOptionRules, { container }) => {
|
async (shippingOptionRules, { container }) => {
|
||||||
if (!shippingOptionRules?.length) {
|
if (!shippingOptionRules?.length) {
|
||||||
|
|||||||
@@ -54,11 +54,7 @@ export const batchProductVariantsWorkflow = createWorkflow(
|
|||||||
return {
|
return {
|
||||||
created: data.res[0],
|
created: data.res[0],
|
||||||
updated: data.res[1],
|
updated: data.res[1],
|
||||||
deleted: {
|
deleted: data.input.delete ?? [],
|
||||||
ids: data.input.delete ?? [],
|
|
||||||
object: "product_variant",
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -47,11 +47,7 @@ export const batchProductsWorkflow = createWorkflow(
|
|||||||
return {
|
return {
|
||||||
created: data.res[0],
|
created: data.res[0],
|
||||||
updated: data.res[1],
|
updated: data.res[1],
|
||||||
deleted: {
|
deleted: data.input.delete ?? [],
|
||||||
ids: data.input.delete ?? [],
|
|
||||||
object: "product",
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,11 +22,7 @@ export const deletePromotionRulesWorkflowStep = createStep(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new StepResponse(
|
return new StepResponse(
|
||||||
{
|
data.data.rule_ids ?? [],
|
||||||
ids: data.data.rule_ids ?? [],
|
|
||||||
object: "promotion-rule",
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
transaction
|
transaction
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -18,11 +18,7 @@ export type BatchMethodRequest<TCreate, TUpdate, TDelete = string> = {
|
|||||||
export type BatchMethodResponse<T> = {
|
export type BatchMethodResponse<T> = {
|
||||||
created: T[]
|
created: T[]
|
||||||
updated: T[]
|
updated: T[]
|
||||||
deleted: {
|
deleted: string[]
|
||||||
ids: string[]
|
|
||||||
object: string
|
|
||||||
deleted: boolean
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BatchWorkflowInput<
|
export type BatchWorkflowInput<
|
||||||
|
|||||||
@@ -29,3 +29,13 @@ export type PaginatedResponse<T> = {
|
|||||||
offset: number
|
offset: number
|
||||||
count: number
|
count: number
|
||||||
} & T
|
} & T
|
||||||
|
|
||||||
|
export type BatchResponse<T> = {
|
||||||
|
created: T[]
|
||||||
|
updated: T[]
|
||||||
|
deleted: {
|
||||||
|
ids: string[]
|
||||||
|
object: string
|
||||||
|
deleted: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { BatchMethodResponse } from "../../../common"
|
import { BatchResponse, DeleteResponse, DeleteResponseWithParent, PaginatedResponse } from "../../common"
|
||||||
import { DeleteResponse, DeleteResponseWithParent, PaginatedResponse } from "../../common"
|
|
||||||
import {
|
import {
|
||||||
AdminProduct,
|
AdminProduct,
|
||||||
AdminProductOption,
|
AdminProductOption,
|
||||||
@@ -19,7 +18,7 @@ export type AdminProductListResponse = PaginatedResponse<{
|
|||||||
export interface AdminProductDeleteResponse extends DeleteResponse<"product"> {}
|
export interface AdminProductDeleteResponse extends DeleteResponse<"product"> {}
|
||||||
|
|
||||||
export interface AdminBatchProductResponse
|
export interface AdminBatchProductResponse
|
||||||
extends BatchMethodResponse<AdminProduct> {}
|
extends BatchResponse<AdminProduct> {}
|
||||||
|
|
||||||
export interface AdminProductVariantResponse {
|
export interface AdminProductVariantResponse {
|
||||||
variant: AdminProductVariant
|
variant: AdminProductVariant
|
||||||
@@ -45,10 +44,10 @@ export interface AdminImportProductResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AdminBatchProductVariantResponse
|
export interface AdminBatchProductVariantResponse
|
||||||
extends BatchMethodResponse<AdminProductVariant> {}
|
extends BatchResponse<AdminProductVariant> {}
|
||||||
|
|
||||||
export interface AdminBatchProductVariantInventoryItemResponse
|
export interface AdminBatchProductVariantInventoryItemResponse
|
||||||
extends BatchMethodResponse<AdminInventoryItem> {}
|
extends BatchResponse<AdminInventoryItem> {}
|
||||||
|
|
||||||
export interface AdminProductOptionResponse {
|
export interface AdminProductOptionResponse {
|
||||||
product_option: AdminProductOption
|
product_option: AdminProductOption
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { BatchMethodResponse } from "../../../common";
|
import { BatchResponse, DeleteResponse, PaginatedResponse } from "../../common";
|
||||||
import { DeleteResponse, PaginatedResponse } from "../../common";
|
|
||||||
import {
|
import {
|
||||||
AdminPromotion,
|
AdminPromotion,
|
||||||
AdminPromotionRule,
|
AdminPromotionRule,
|
||||||
@@ -54,6 +53,6 @@ export type AdminRuleValueOptionsListResponse = {
|
|||||||
values: AdminRuleValueOption[]
|
values: AdminRuleValueOption[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AdminPromotionRuleBatchResponse = BatchMethodResponse<AdminPromotionRule>
|
export type AdminPromotionRuleBatchResponse = BatchResponse<AdminPromotionRule>
|
||||||
|
|
||||||
export type AdminPromotionDeleteResponse = DeleteResponse<"promotion">
|
export type AdminPromotionDeleteResponse = DeleteResponse<"promotion">
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { BatchMethodResponse } from "../../../common"
|
import { BatchResponse, DeleteResponse, PaginatedResponse } from "../../common"
|
||||||
import { DeleteResponse, PaginatedResponse } from "../../common"
|
|
||||||
import { AdminShippingOption, AdminShippingOptionRule } from "./entities"
|
import { AdminShippingOption, AdminShippingOptionRule } from "./entities"
|
||||||
|
|
||||||
export interface AdminShippingOptionResponse {
|
export interface AdminShippingOptionResponse {
|
||||||
@@ -13,4 +12,4 @@ export type AdminShippingOptionListResponse = PaginatedResponse<{
|
|||||||
export interface AdminShippingOptionDeleteResponse
|
export interface AdminShippingOptionDeleteResponse
|
||||||
extends DeleteResponse<"shipping_option"> {}
|
extends DeleteResponse<"shipping_option"> {}
|
||||||
|
|
||||||
export type AdminUpdateShippingOptionRulesResponse = BatchMethodResponse<AdminShippingOptionRule>
|
export type AdminUpdateShippingOptionRulesResponse = BatchResponse<AdminShippingOptionRule>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
BatchMethodResponse,
|
BatchMethodResponse,
|
||||||
|
BatchResponse,
|
||||||
HttpTypes,
|
HttpTypes,
|
||||||
LinkDefinition,
|
LinkDefinition,
|
||||||
MedusaContainer,
|
MedusaContainer,
|
||||||
@@ -125,7 +126,7 @@ export const refetchBatchProducts = async (
|
|||||||
batchResult: BatchMethodResponse<ProductDTO>,
|
batchResult: BatchMethodResponse<ProductDTO>,
|
||||||
scope: MedusaContainer,
|
scope: MedusaContainer,
|
||||||
fields: string[]
|
fields: string[]
|
||||||
) => {
|
): Promise<BatchResponse<ProductDTO>> => {
|
||||||
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
let created = Promise.resolve<ProductDTO[]>([])
|
let created = Promise.resolve<ProductDTO[]>([])
|
||||||
let updated = Promise.resolve<ProductDTO[]>([])
|
let updated = Promise.resolve<ProductDTO[]>([])
|
||||||
@@ -160,7 +161,11 @@ export const refetchBatchProducts = async (
|
|||||||
return {
|
return {
|
||||||
created: createdRes,
|
created: createdRes,
|
||||||
updated: updatedRes,
|
updated: updatedRes,
|
||||||
deleted: batchResult.deleted,
|
deleted: {
|
||||||
|
ids: batchResult.deleted,
|
||||||
|
object: "product",
|
||||||
|
deleted: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +173,7 @@ export const refetchBatchVariants = async (
|
|||||||
batchResult: BatchMethodResponse<ProductVariantDTO>,
|
batchResult: BatchMethodResponse<ProductVariantDTO>,
|
||||||
scope: MedusaContainer,
|
scope: MedusaContainer,
|
||||||
fields: string[]
|
fields: string[]
|
||||||
) => {
|
): Promise<BatchResponse<ProductVariantDTO>> => {
|
||||||
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
let created = Promise.resolve<ProductVariantDTO[]>([])
|
let created = Promise.resolve<ProductVariantDTO[]>([])
|
||||||
let updated = Promise.resolve<ProductVariantDTO[]>([])
|
let updated = Promise.resolve<ProductVariantDTO[]>([])
|
||||||
@@ -203,7 +208,11 @@ export const refetchBatchVariants = async (
|
|||||||
return {
|
return {
|
||||||
created: createdRes,
|
created: createdRes,
|
||||||
updated: updatedRes,
|
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 { PromotionRuleDTO, MedusaContainer } from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
promiseAll,
|
promiseAll,
|
||||||
@@ -28,7 +28,7 @@ export const refetchBatchRules = async (
|
|||||||
batchResult: BatchMethodResponse<PromotionRuleDTO>,
|
batchResult: BatchMethodResponse<PromotionRuleDTO>,
|
||||||
scope: MedusaContainer,
|
scope: MedusaContainer,
|
||||||
fields: string[]
|
fields: string[]
|
||||||
) => {
|
): Promise<BatchResponse<PromotionRuleDTO>> => {
|
||||||
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||||
let created = Promise.resolve<PromotionRuleDTO[]>([])
|
let created = Promise.resolve<PromotionRuleDTO[]>([])
|
||||||
let updated = Promise.resolve<PromotionRuleDTO[]>([])
|
let updated = Promise.resolve<PromotionRuleDTO[]>([])
|
||||||
@@ -63,6 +63,10 @@ export const refetchBatchRules = async (
|
|||||||
return {
|
return {
|
||||||
created: createdRes,
|
created: createdRes,
|
||||||
updated: updatedRes,
|
updated: updatedRes,
|
||||||
deleted: batchResult.deleted,
|
deleted: {
|
||||||
|
ids: batchResult.deleted,
|
||||||
|
object: "promotion-rule",
|
||||||
|
deleted: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,6 +66,10 @@ export const refetchBatchRules = async (
|
|||||||
return {
|
return {
|
||||||
created: createdRes,
|
created: createdRes,
|
||||||
updated: updatedRes,
|
updated: updatedRes,
|
||||||
deleted: batchResult.deleted,
|
deleted: {
|
||||||
|
ids: batchResult.deleted,
|
||||||
|
object: "shipping_option_rule",
|
||||||
|
deleted: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user