From da5ffed015cb4c7dc9958455f7c3b71a6a264293 Mon Sep 17 00:00:00 2001 From: yamiltauil Date: Fri, 3 Jan 2025 20:17:38 -0300 Subject: [PATCH] add order by id --- src/application/orders/orderControllers.ts | 12 ++++++++++++ src/application/orders/orderRoutes.ts | 1 + 2 files changed, 13 insertions(+) diff --git a/src/application/orders/orderControllers.ts b/src/application/orders/orderControllers.ts index c8b29fa..3c8770c 100755 --- a/src/application/orders/orderControllers.ts +++ b/src/application/orders/orderControllers.ts @@ -49,6 +49,18 @@ const mercadoPagoProcess = async ({ }; class OrderController { + async findById(req: Request, res: Response, next: NextFunction) { + const { id } = req.params; + try { + // add product name to res + const orderWithProducts = await Order.findById(id).populate('orderItems._id').exec(); + res.status(200).json(orderWithProducts); + } catch (error) { + console.log(error); + next(error); + } + } + async findAll(req: Request, res: Response, next: NextFunction) { const page: number | undefined = parseInt(req.query.page as string) || 1; try { diff --git a/src/application/orders/orderRoutes.ts b/src/application/orders/orderRoutes.ts index f8a56f6..20a0aa2 100755 --- a/src/application/orders/orderRoutes.ts +++ b/src/application/orders/orderRoutes.ts @@ -9,6 +9,7 @@ const routes = Router(); routes.get('/', idChecker.isUserAdmin, orderController.findAll); routes.get('/monthly-sales', idChecker.isUserAdmin, orderController.getMonthlySalesReport); +routes.get('/order/:id', idChecker.containsIdInParams, idChecker.isUserAdmin, orderController.findById); routes.put('/update', idChecker.isUserAdmin, orderController.updateOrderStatus); routes.put('/update-payment', idChecker.isUserAdmin, orderController.updatePaymentStatus); routes.post(