Added router and controller for getProductName

master
parent 8d2d2d29e3
commit 418c1da9ac

@ -87,6 +87,25 @@ module.exports.getAllProducts = async (req, res) => {
}
};
// getting product name by id
exports.getProductName = async (req, res) => {
try {
const { productId } = req.body;
// Find the product by productId
const product = await Product.findOne({ _id: productId }).select('name');
if (!product) {
return res.status(404).json({ error: 'Product not found' });
}
// Send the product name in the response
res.json(product);
} catch (error) {
console.error('Error getting product name:', error);
res.status(500).json({ error: 'Internal Server Error' });
}
};
// retrieve all active products controller
exports.getAllActiveProducts = async (req, res) => {

@ -38,6 +38,9 @@ router.post(`/create-order`, verify, verifyNonAdmin, productControllers.createOr
// Route for getting the information of specific product
router.get("/:productId", productControllers.getProduct);
// Route for getting product name by id
router.post('/getProductName', productControllers.getProductName);
// My Cart
router.post('/add-to-cart', verify, verifyNonAdmin, productControllers.addProductToCart);

Loading…
Cancel
Save