Skip to content

Commit

Permalink
add order by id
Browse files Browse the repository at this point in the history
  • Loading branch information
yamiltauil committed Jan 3, 2025
1 parent 1bf9e5f commit da5ffed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/application/orders/orderControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/application/orders/orderRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit da5ffed

Please sign in to comment.