feat(core-flows,medusa): add endpoint to add/remove fulfillment providers to location (#8299)

what:

- add endpoint to add/remove fulfillment providers to location
- specs cleanup from previous PR

RESOLVES CC-259
This commit is contained in:
Riqwan Thamir authored and GitHub committed 2024-07-26 14:35:19 +00:00
1 parent 4eb7abbae8
commit 71411463b1
11 files changed
+154 -127

No files matched your search

@@ -0,0 +1,41 @@
import { batchLinksWorkflow } from "@medusajs/core-flows"
import { LinkMethodRequest } from "@medusajs/types"
import { Modules } from "@medusajs/utils"
import {
AuthenticatedMedusaRequest,
MedusaResponse,
} from "../../../../../types/routing"
import { refetchStockLocation } from "../../helpers"
const buildLinks = (id, fulfillmentProviderIds: string[]) => {
return fulfillmentProviderIds.map((fulfillmentProviderId) => ({
[Modules.STOCK_LOCATION]: { stock_location_id: id },
[Modules.FULFILLMENT]: {
fulfillment_provider_id: fulfillmentProviderId,
},
}))
}
export const POST = async (
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
res: MedusaResponse
) => {
const { id } = req.params
const { add = [], remove = [] } = req.validatedBody
await batchLinksWorkflow(req.scope).run({
input: {
create: buildLinks(id, add),
delete: buildLinks(id, remove),
},
})
const stockLocation = await refetchStockLocation(
req.params.id,
req.scope,
req.remoteQueryConfig.fields
)
res.status(200).json({ stock_location: stockLocation })
}
@@ -82,4 +82,15 @@ export const adminStockLocationRoutesMiddlewares: MiddlewareRoute[] = [
),
],
},
{
method: ["POST"],
matcher: "/admin/stock-locations/:id/fulfillment-providers",
middlewares: [
validateAndTransformBody(createLinkBody()),
validateAndTransformQuery(
AdminGetStockLocationParams,
QueryConfig.retrieveTransformQueryConfig
),
],
},
]