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:
Sebastian Rindom
2020-09-08 12:02:26 +02:00
committed by GitHub
parent 0627276619
commit 1e04be90c8
3 changed files with 58 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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
}
}

View File

@@ -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)