Added controller and route for check existing product

master
parent 232180bb1e
commit b6ebb9f2dc

@ -30,6 +30,26 @@ module.exports.createProduct = async (req, res) => {
}
};
module.exports.isProductExisting = async (req, res) => {
try {
const { productName } = req.body;
const existingProduct = await Product.findOne({ name: productName });
const productExists = !!existingProduct;
if (productExists == true) {
res.json(true);
} else {
res.json(false);
}
} catch (error) {
console.error(error);
res.status(500).json(false);
}
};
// retrieve all products controller
module.exports.getAllProducts = async (req, res) => {

@ -11,6 +11,8 @@ const {verify, verifyAdmin, verifyNonAdmin} = auth;
// Route for creating a product
router.post(`/create`, verify, verifyAdmin, productControllers.createProduct);
// Route for check a existing product
router.post('/check-product-existence', verify, verifyAdmin, productControllers.isProductExisting);
// Route for retrieving all products
router.get(`/all`, verify, verifyAdmin, productControllers.getAllProducts);

Loading…
Cancel
Save