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 () => {
|
it("should throw if invalid type is passed", async () => {
|
||||||
@@ -344,9 +356,9 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
const stockLocationId = stockLocationResponse.data.stock_location.id
|
const stockLocationId = stockLocationResponse.data.stock_location.id
|
||||||
|
|
||||||
const locationWithFSetResponse = await api.post(
|
const locationWithFSetResponse = await api.post(
|
||||||
`/admin/stock-locations/${stockLocationId}/fulfillment-sets?fields=id,*fulfillment_sets`,
|
`/admin/stock-locations/${stockLocationId}/fulfillment-sets?fields=id,*fulfillment_sets`,
|
||||||
{
|
{
|
||||||
@@ -355,7 +367,7 @@ medusaIntegrationTestRunner({
|
|||||||
},
|
},
|
||||||
adminHeaders
|
adminHeaders
|
||||||
)
|
)
|
||||||
|
|
||||||
const fulfillmentSetId =
|
const fulfillmentSetId =
|
||||||
locationWithFSetResponse.data.stock_location.fulfillment_sets[0].id
|
locationWithFSetResponse.data.stock_location.fulfillment_sets[0].id
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const deleteServiceZonesStep = createStep(
|
|||||||
ModuleRegistrationName.FULFILLMENT
|
ModuleRegistrationName.FULFILLMENT
|
||||||
)
|
)
|
||||||
|
|
||||||
await service.softDelete(ids)
|
await service.softDeleteServiceZones(ids)
|
||||||
|
|
||||||
return new StepResponse(void 0, ids)
|
return new StepResponse(void 0, ids)
|
||||||
},
|
},
|
||||||
@@ -23,6 +23,6 @@ export const deleteServiceZonesStep = createStep(
|
|||||||
ModuleRegistrationName.FULFILLMENT
|
ModuleRegistrationName.FULFILLMENT
|
||||||
)
|
)
|
||||||
|
|
||||||
await service.restore(prevIds)
|
await service.restoreServiceZones(prevIds)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+27
@@ -6,6 +6,7 @@ import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
|||||||
import {
|
import {
|
||||||
AdminFulfillmentSetResponse,
|
AdminFulfillmentSetResponse,
|
||||||
AdminServiceZoneDeleteResponse,
|
AdminServiceZoneDeleteResponse,
|
||||||
|
AdminServiceZoneResponse,
|
||||||
IFulfillmentModuleService,
|
IFulfillmentModuleService,
|
||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
@@ -20,6 +21,32 @@ import {
|
|||||||
} from "../../../../../../types/routing"
|
} from "../../../../../../types/routing"
|
||||||
import { AdminUpdateFulfillmentSetServiceZonesType } from "../../../validators"
|
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 (
|
export const POST = async (
|
||||||
req: MedusaRequest<AdminUpdateFulfillmentSetServiceZonesType>,
|
req: MedusaRequest<AdminUpdateFulfillmentSetServiceZonesType>,
|
||||||
res: MedusaResponse<AdminFulfillmentSetResponse>
|
res: MedusaResponse<AdminFulfillmentSetResponse>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import * as QueryConfig from "./query-config"
|
|||||||
import {
|
import {
|
||||||
AdminCreateFulfillmentSetServiceZonesSchema,
|
AdminCreateFulfillmentSetServiceZonesSchema,
|
||||||
AdminFulfillmentSetParams,
|
AdminFulfillmentSetParams,
|
||||||
|
AdminServiceZonesParams,
|
||||||
AdminUpdateFulfillmentSetServiceZonesSchema,
|
AdminUpdateFulfillmentSetServiceZonesSchema,
|
||||||
} from "./validators"
|
} 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,
|
...retrieveTransformQueryConfig,
|
||||||
isList: true,
|
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,
|
geoZoneZipSchema,
|
||||||
} from "./validators/geo-zone"
|
} from "./validators/geo-zone"
|
||||||
|
|
||||||
|
export const AdminServiceZonesParams = createFindParams()
|
||||||
|
export type AdminServiceZonesParamsType = z.infer<
|
||||||
|
typeof AdminServiceZonesParams
|
||||||
|
>
|
||||||
|
|
||||||
export const AdminCreateFulfillmentSetServiceZonesSchema = z
|
export const AdminCreateFulfillmentSetServiceZonesSchema = z
|
||||||
.object({
|
.object({
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AdminServiceZoneResponse } from "./service-zone"
|
import { ServiceZoneResponse } from "./service-zone"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @experimental
|
* @experimental
|
||||||
@@ -8,7 +8,7 @@ export interface FulfillmentSetResponse {
|
|||||||
name: string
|
name: string
|
||||||
type: string
|
type: string
|
||||||
metadata: Record<string, unknown> | null
|
metadata: Record<string, unknown> | null
|
||||||
service_zones: AdminServiceZoneResponse[]
|
service_zones: ServiceZoneResponse[]
|
||||||
created_at: Date
|
created_at: Date
|
||||||
updated_at: Date
|
updated_at: Date
|
||||||
deleted_at: Date | null
|
deleted_at: Date | null
|
||||||
|
|||||||
@@ -5,13 +5,7 @@ import { AdminGeoZoneResponse } from "./geo-zone"
|
|||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export interface AdminServiceZoneResponse {
|
export interface AdminServiceZoneResponse {
|
||||||
id: string
|
service_zone: ServiceZoneResponse
|
||||||
name: string
|
|
||||||
metadata: Record<string, unknown> | null
|
|
||||||
geo_zones: AdminGeoZoneResponse[]
|
|
||||||
created_at: Date
|
|
||||||
updated_at: Date
|
|
||||||
deleted_at: Date | null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,3 +17,16 @@ export interface AdminServiceZoneDeleteResponse {
|
|||||||
deleted: boolean
|
deleted: boolean
|
||||||
parent: FulfillmentSetResponse
|
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