fix: fulfillment api (#104)
* fix: updates admin fulfillment endpoint * fix: adds shipment creation in admin * fix: adds shipment creation in admin * fix: missing await
This commit is contained in:
@@ -1,9 +1,31 @@
|
||||
import { MedusaError, Validator } from "medusa-core-utils"
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
items: Validator.array()
|
||||
.items({
|
||||
item_id: Validator.string().required(),
|
||||
quantity: Validator.number().required(),
|
||||
})
|
||||
.required(),
|
||||
metadata: Validator.object().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
let order = await orderService.createFulfillment(id)
|
||||
|
||||
let order = await orderService.createFulfillment(
|
||||
id,
|
||||
value.items,
|
||||
value.metadata
|
||||
)
|
||||
order = await orderService.decorate(order, [], ["region"])
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { MedusaError, Validator } from "medusa-core-utils"
|
||||
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const schema = Validator.object().keys({
|
||||
fulfillment_id: Validator.string().required(),
|
||||
tracking_numbers: Validator.array()
|
||||
.items(Validator.string())
|
||||
.optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
if (error) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
|
||||
}
|
||||
|
||||
try {
|
||||
const orderService = req.scope.resolve("orderService")
|
||||
let order = await orderService.createShipment(
|
||||
id,
|
||||
value.fulfillment_id,
|
||||
value.tracking_numbers
|
||||
)
|
||||
order = await orderService.decorate(order, [], ["region"])
|
||||
res.json({ order })
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,11 @@ export default app => {
|
||||
"/:id/capture",
|
||||
middlewares.wrap(require("./capture-payment").default)
|
||||
)
|
||||
route.post(
|
||||
"/:id/shipment",
|
||||
middlewares.wrap(require("./create-shipment").default)
|
||||
)
|
||||
|
||||
route.post(
|
||||
"/:id/fulfillment",
|
||||
middlewares.wrap(require("./create-fulfillment").default)
|
||||
|
||||
Reference in New Issue
Block a user