Skip to content

Commit

Permalink
Update customer routes and order controller
Browse files Browse the repository at this point in the history
- Add some routes
- Add Cancel Order
  • Loading branch information
polekstulod committed Aug 9, 2022
1 parent 1581c8b commit 2015207
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/controllers/customer/order.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ exports.getAllOrders = async (req, res) => {
try {
const data = await db.Order.findAll({
include: [{ model: db.Dish, as: 'order_dishes', include: ['dish_category'] }, 'restaurant'],
order: [['date_created', 'DESC']],
});
dataResponse(res, data, 'All Orders has been retrieved', 'No Orders has been retrieved');
} catch (err) {
Expand All @@ -68,7 +69,7 @@ exports.getOrder = async (req, res) => {
include: [
{ model: db.Dish, as: 'order_dishes', include: ['dish_category'] },
'address',
'restaurant',
{ model: db.Restaurant, as: 'restaurant', include: 'restaurant_category' },
{ model: db.DeliveryDetails, as: 'delivery_details', include: ['courier'] },
],
});
Expand All @@ -77,3 +78,23 @@ exports.getOrder = async (req, res) => {
errResponse(res, err);
}
};

// * Cancel Order
exports.cancelOrder = async (req, res) => {
if (!checkAuthorization(req, res, 'Customer')) {
return;
}

const id = req.params.orderID;

try {
await db.Order.update(
{ order_status: 'Cancelled', updated_by: req.user.user_id, date_cancelled: new Date() },
{ where: { order_id: id } }
);
const data = await db.Order.findByPk(id);
dataResponse(res, data, 'Order Status has been updated', 'No Order Status has been updated');
} catch (err) {
errResponse(res, err);
}
};
1 change: 1 addition & 0 deletions src/routes/customer.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var orderCtl = require('../controllers/customer/order.controller');
router.post('/order', orderCtl.createOrder);
router.get('/orders', orderCtl.getAllOrders);
router.get('/order/:orderID', orderCtl.getOrder);
router.put('/order/cancelled/:orderID', orderCtl.cancelOrder);

var exploreCtl = require('../controllers/customer/explore.controller');
router.get('/some-resto-cat', exploreCtl.getSomeRestoCat);
Expand Down

0 comments on commit 2015207

Please sign in to comment.