Compare commits
2 Commits
master
...
feature/dr
Author | SHA1 | Date | |
---|---|---|---|
|
979bf24767 | ||
|
98daf19853 |
@ -74,7 +74,7 @@ const VALIDATION_MESSAGES = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
router.post('/create', async (req, res, next) => {
|
const createOrder = async (req, res) => {
|
||||||
const bodyErrors = []
|
const bodyErrors = []
|
||||||
|
|
||||||
const { customer } = req.body
|
const { customer } = req.body
|
||||||
@ -120,7 +120,6 @@ router.post('/create', async (req, res, next) => {
|
|||||||
throw new Error(bodyErrors.join(', '))
|
throw new Error(bodyErrors.join(', '))
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const order = await OrderModel.create({
|
const order = await OrderModel.create({
|
||||||
phone: customer.phone,
|
phone: customer.phone,
|
||||||
carNumber: car.number,
|
carNumber: car.number,
|
||||||
@ -135,31 +134,23 @@ router.post('/create', async (req, res, next) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
res.status(200).send({ success: true, body: order })
|
res.status(200).send({ success: true, body: order })
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
next(error)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
router.get('/:id', async (req, res, next) => {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const order = await OrderModel.findById(id)
|
const order = await OrderModel.findById(id)
|
||||||
if (!order) {
|
if (!order) {
|
||||||
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 })
|
||||||
} catch (error) {
|
|
||||||
next(error)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
router.patch('/:id', async (req, res, next) => {
|
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)
|
||||||
@ -179,14 +170,10 @@ router.patch('/:id', async (req, res, next) => {
|
|||||||
if (!mongoose.Types.ObjectId.isValid(masterId)) {
|
if (!mongoose.Types.ObjectId.isValid(masterId)) {
|
||||||
bodyErrors.push(VALIDATION_MESSAGES.masterId.invalid)
|
bodyErrors.push(VALIDATION_MESSAGES.masterId.invalid)
|
||||||
} else {
|
} else {
|
||||||
try {
|
|
||||||
const master = await MasterModel.findById(masterId)
|
const master = await MasterModel.findById(masterId)
|
||||||
if (!master) {
|
if (!master) {
|
||||||
bodyErrors.push(VALIDATION_MESSAGES.master.notFound)
|
bodyErrors.push(VALIDATION_MESSAGES.master.notFound)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
next(error)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +188,6 @@ router.patch('/:id', async (req, res, next) => {
|
|||||||
throw new Error(bodyErrors.join(', '))
|
throw new Error(bodyErrors.join(', '))
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const updateData = {}
|
const updateData = {}
|
||||||
if (status) {
|
if (status) {
|
||||||
updateData.status = status
|
updateData.status = status
|
||||||
@ -224,18 +210,14 @@ router.patch('/:id', async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).send({ success: true, body: order })
|
res.status(200).send({ success: true, body: order })
|
||||||
} catch (error) {
|
|
||||||
next(error)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
router.delete('/:id', async (req, res, next) => {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
const order = await OrderModel.findByIdAndDelete(id, {
|
const order = await OrderModel.findByIdAndDelete(id, {
|
||||||
new: true,
|
new: true,
|
||||||
})
|
})
|
||||||
@ -243,9 +225,11 @@ router.delete('/:id', async (req, res, next) => {
|
|||||||
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 })
|
||||||
} catch (error) {
|
|
||||||
next(error)
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
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