fix: Delete service zone (#7017)
This commit is contained in:
@@ -191,6 +191,18 @@ medusaIntegrationTestRunner({
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
const serviceZoneResponse = await api
|
||||
.get(
|
||||
`/admin/fulfillment-sets/${fulfillmentSetId}/service-zones/${serviceZoneId}`,
|
||||
adminHeaders
|
||||
)
|
||||
.catch((err) => err.response)
|
||||
|
||||
expect(serviceZoneResponse.status).toEqual(404)
|
||||
expect(serviceZoneResponse.data.message).toEqual(
|
||||
`Service zone with id: ${serviceZoneId} not found`
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw if invalid type is passed", async () => {
|
||||
@@ -344,9 +356,9 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
|
||||
const stockLocationId = stockLocationResponse.data.stock_location.id
|
||||
|
||||
|
||||
const locationWithFSetResponse = await api.post(
|
||||
`/admin/stock-locations/${stockLocationId}/fulfillment-sets?fields=id,*fulfillment_sets`,
|
||||
{
|
||||
@@ -355,7 +367,7 @@ medusaIntegrationTestRunner({
|
||||
},
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
|
||||
const fulfillmentSetId =
|
||||
locationWithFSetResponse.data.stock_location.fulfillment_sets[0].id
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ export const deleteServiceZonesStep = createStep(
|
||||
ModuleRegistrationName.FULFILLMENT
|
||||
)
|
||||
|
||||
await service.softDelete(ids)
|
||||
await service.softDeleteServiceZones(ids)
|
||||
|
||||
return new StepResponse(void 0, ids)
|
||||
},
|
||||
@@ -23,6 +23,6 @@ export const deleteServiceZonesStep = createStep(
|
||||
ModuleRegistrationName.FULFILLMENT
|
||||
)
|
||||
|
||||
await service.restore(prevIds)
|
||||
await service.restoreServiceZones(prevIds)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
AdminFulfillmentSetResponse,
|
||||
AdminServiceZoneDeleteResponse,
|
||||
AdminServiceZoneResponse,
|
||||
IFulfillmentModuleService,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
@@ -20,6 +21,32 @@ import {
|
||||
} from "../../../../../../types/routing"
|
||||
import { AdminUpdateFulfillmentSetServiceZonesType } from "../../../validators"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse<AdminServiceZoneResponse>
|
||||
) => {
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const [service_zone] = await remoteQuery(
|
||||
remoteQueryObjectFromString({
|
||||
entryPoint: "service_zones",
|
||||
variables: {
|
||||
id: req.params.zone_id,
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
)
|
||||
|
||||
if (!service_zone) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.NOT_FOUND,
|
||||
`Service zone with id ${req.params.zone_id} not found`
|
||||
)
|
||||
}
|
||||
|
||||
res.status(200).json({ service_zone })
|
||||
}
|
||||
|
||||
export const POST = async (
|
||||
req: MedusaRequest<AdminUpdateFulfillmentSetServiceZonesType>,
|
||||
res: MedusaResponse<AdminFulfillmentSetResponse>
|
||||
|
||||
@@ -6,6 +6,7 @@ import * as QueryConfig from "./query-config"
|
||||
import {
|
||||
AdminCreateFulfillmentSetServiceZonesSchema,
|
||||
AdminFulfillmentSetParams,
|
||||
AdminServiceZonesParams,
|
||||
AdminUpdateFulfillmentSetServiceZonesSchema,
|
||||
} from "./validators"
|
||||
|
||||
@@ -42,4 +43,14 @@ export const adminFulfillmentSetsRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/fulfillment-sets/:id/service-zones/:zone_id",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminServiceZonesParams,
|
||||
QueryConfig.retrieveServiceZoneTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -18,3 +18,16 @@ export const listTransformQueryConfig = {
|
||||
...retrieveTransformQueryConfig,
|
||||
isList: true,
|
||||
}
|
||||
|
||||
export const retrieveServiceZoneTransformQueryConfig = {
|
||||
defaults: [
|
||||
"id",
|
||||
"name",
|
||||
"type",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
"deleted_at",
|
||||
"*geo_zones",
|
||||
],
|
||||
isList: false,
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@ import {
|
||||
geoZoneZipSchema,
|
||||
} from "./validators/geo-zone"
|
||||
|
||||
export const AdminServiceZonesParams = createFindParams()
|
||||
export type AdminServiceZonesParamsType = z.infer<
|
||||
typeof AdminServiceZonesParams
|
||||
>
|
||||
|
||||
export const AdminCreateFulfillmentSetServiceZonesSchema = z
|
||||
.object({
|
||||
name: z.string(),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AdminServiceZoneResponse } from "./service-zone"
|
||||
import { ServiceZoneResponse } from "./service-zone"
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
@@ -8,7 +8,7 @@ export interface FulfillmentSetResponse {
|
||||
name: string
|
||||
type: string
|
||||
metadata: Record<string, unknown> | null
|
||||
service_zones: AdminServiceZoneResponse[]
|
||||
service_zones: ServiceZoneResponse[]
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
deleted_at: Date | null
|
||||
|
||||
@@ -5,13 +5,7 @@ import { AdminGeoZoneResponse } from "./geo-zone"
|
||||
* @experimental
|
||||
*/
|
||||
export interface AdminServiceZoneResponse {
|
||||
id: string
|
||||
name: string
|
||||
metadata: Record<string, unknown> | null
|
||||
geo_zones: AdminGeoZoneResponse[]
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
deleted_at: Date | null
|
||||
service_zone: ServiceZoneResponse
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,3 +17,16 @@ export interface AdminServiceZoneDeleteResponse {
|
||||
deleted: boolean
|
||||
parent: FulfillmentSetResponse
|
||||
}
|
||||
|
||||
/**
|
||||
* @experimental
|
||||
*/
|
||||
export interface ServiceZoneResponse {
|
||||
id: string
|
||||
name: string
|
||||
metadata: Record<string, unknown> | null
|
||||
geo_zones: AdminGeoZoneResponse[]
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
deleted_at: Date | null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user