Adds delete line item, prepares checkout

This commit is contained in:
Sebastian Rindom
2020-07-09 18:19:16 +02:00
parent 154564b80a
commit aabec1e45e
13 changed files with 50 additions and 20 deletions
@@ -22,7 +22,7 @@ export default async (req, res) => {
await cartService.addShippingMethod(id, value.option_id, value.data)
let cart = await cartService.retrieve(id)
cart = await cartService.decorate(cart)
cart = await cartService.decorate(cart, [], ["region"])
res.status(200).json({ cart })
} catch (err) {
@@ -26,7 +26,7 @@ export default async (req, res) => {
await cartService.addLineItem(cart._id, lineItem)
cart = await cartService.retrieve(cart._id)
cart = await cartService.decorate(cart)
cart = await cartService.decorate(cart, [], ["region"])
res.status(200).json({ cart })
} catch (err) {
@@ -9,7 +9,7 @@ export default async (req, res) => {
// return the updated cart
let cart = await cartService.retrieve(id)
cart = await cartService.decorate(cart)
cart = await cartService.decorate(cart, [], ["region"])
res.status(200).json({ cart })
} catch (err) {
@@ -0,0 +1,16 @@
import { Validator, MedusaError } from "medusa-core-utils"
export default async (req, res) => {
const { id, line_id } = req.params
try {
const cartService = req.scope.resolve("cartService")
let cart = await cartService.removeLineItem(id, line_id)
cart = await cartService.decorate(cart, [], ["region"])
res.status(200).json({ cart })
} catch (err) {
throw err
}
}
@@ -20,6 +20,10 @@ export default app => {
"/:id/line-items/:line_id",
middlewares.wrap(require("./update-line-item").default)
)
route.delete(
"/:id/line-items/:line_id",
middlewares.wrap(require("./delete-line-item").default)
)
// Payment sessions
route.post(
@@ -57,7 +57,7 @@ export default async (req, res) => {
}
let newCart = await cartService.retrieve(id)
const data = await cartService.decorate(newCart)
const data = await cartService.decorate(newCart, [], ["region"])
res.json({ cart: data })
} catch (err) {
throw err
@@ -24,10 +24,8 @@ export default async (req, res) => {
cart.region_id
)
await cartService.updateLineItem(cart._id, line_id, lineItem)
cart = await cartService.retrieve(cart._id)
cart = await cartService.decorate(cart)
cart = await cartService.updateLineItem(cart._id, line_id, lineItem)
cart = await cartService.decorate(cart, [], ["region"])
res.status(200).json({ cart })
} catch (err) {
@@ -22,7 +22,7 @@ export default async (req, res) => {
await cartService.setPaymentMethod(id, session)
let cart = await cartService.retrieve(id)
cart = await cartService.decorate(cart)
cart = await cartService.decorate(cart, [], ["region"])
res.status(200).json({ cart })
} catch (err) {
@@ -6,7 +6,10 @@ const route = Router()
export default app => {
app.use("/shipping-options", route)
route.get("/", middlewares.wrap(require("./list-shipping-options").default))
route.get(
"/:cart_id",
middlewares.wrap(require("./list-shipping-options").default)
)
return app
}
@@ -2,10 +2,10 @@ import { Validator, MedusaError } from "medusa-core-utils"
export default async (req, res) => {
const schema = Validator.object().keys({
cart_id: Validator.string(),
cart_id: Validator.string().required(),
})
const { value, error } = schema.validate(req.body)
const { value, error } = schema.validate(req.params)
if (error) {
throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details)
}