From 5e332d1231b9935c6ee6e416d4b9a15d7ca6f788 Mon Sep 17 00:00:00 2001 From: patrickjieraldjuan Date: Sun, 28 Jan 2024 19:48:02 +0800 Subject: [PATCH] Added controller and route for get specific product --- controllers/productControllers.js | 10 +++++++++- routes/productRoutes.js | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/controllers/productControllers.js b/controllers/productControllers.js index a4a6567..e311e6b 100644 --- a/controllers/productControllers.js +++ b/controllers/productControllers.js @@ -374,4 +374,12 @@ exports.getCartDetails = async (req, res) => { console.error(error); res.status(500).json({ message: 'Error fetching cart details' }); } -}; \ No newline at end of file +}; + +module.exports.getProduct = (request, response) => { + let reqParams = request.params.productId; + + Course.findById(reqParams).then(result => response.send(result)) + .catch(error => response.send(error)); + +} diff --git a/routes/productRoutes.js b/routes/productRoutes.js index cb7d662..e1cb66d 100644 --- a/routes/productRoutes.js +++ b/routes/productRoutes.js @@ -33,6 +33,8 @@ router.put(`/:productId/activate`, verify, verifyAdmin, productControllers.activ // Route to create an order || check-out router.post(`/create-order`, verify, verifyNonAdmin, productControllers.createOrder); +// Route for getting the information of specific product +router.get("/:productId", courseController.getProduct); // My Cart