feat: extract order handlers
This commit is contained in:
parent
98daf19853
commit
979bf24767
@ -74,7 +74,7 @@ const VALIDATION_MESSAGES = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
router.post('/create', async (req, res) => {
|
const createOrder = async (req, res) => {
|
||||||
const bodyErrors = []
|
const bodyErrors = []
|
||||||
|
|
||||||
const { customer } = req.body
|
const { customer } = req.body
|
||||||
@ -134,9 +134,9 @@ router.post('/create', async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).send({ success: true, body: order })
|
res.status(200).send({ success: true, body: order })
|
||||||
})
|
}
|
||||||
|
|
||||||
router.get('/:id', async (req, res) => {
|
const getOrder = async (req, res) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||||
throw new Error(VALIDATION_MESSAGES.orderId.invalid)
|
throw new Error(VALIDATION_MESSAGES.orderId.invalid)
|
||||||
@ -148,9 +148,9 @@ router.get('/:id', async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).send({ success: true, body: order })
|
res.status(200).send({ success: true, body: order })
|
||||||
})
|
}
|
||||||
|
|
||||||
router.patch('/:id', async (req, res) => {
|
const updateOrder = async (req, res) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||||
throw new Error(VALIDATION_MESSAGES.orderId.invalid)
|
throw new Error(VALIDATION_MESSAGES.orderId.invalid)
|
||||||
@ -210,9 +210,9 @@ router.patch('/:id', async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).send({ success: true, body: order })
|
res.status(200).send({ success: true, body: order })
|
||||||
})
|
}
|
||||||
|
|
||||||
router.delete('/:id', async (req, res) => {
|
const deleteOrder = async (req, res) => {
|
||||||
const { id } = req.params
|
const { id } = req.params
|
||||||
if (!mongoose.Types.ObjectId.isValid(id)) {
|
if (!mongoose.Types.ObjectId.isValid(id)) {
|
||||||
throw new Error(VALIDATION_MESSAGES.orderId.invalid)
|
throw new Error(VALIDATION_MESSAGES.orderId.invalid)
|
||||||
@ -225,6 +225,11 @@ router.delete('/:id', async (req, res) => {
|
|||||||
throw new Error(VALIDATION_MESSAGES.order.notFound)
|
throw new Error(VALIDATION_MESSAGES.order.notFound)
|
||||||
}
|
}
|
||||||
res.status(200).send({ success: true, body: order })
|
res.status(200).send({ success: true, body: order })
|
||||||
})
|
}
|
||||||
|
|
||||||
|
router.post('/create', createOrder)
|
||||||
|
router.get('/:id', getOrder)
|
||||||
|
router.patch('/:id', updateOrder)
|
||||||
|
router.delete('/:id', deleteOrder)
|
||||||
|
|
||||||
module.exports = router
|
module.exports = router
|
Loading…
Reference in New Issue
Block a user