Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions backend/routes/productRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ router.get('/', async (req, res) => {
);
res.send(products);
});
router.delete('/',isAuth,isAdmin,async(req,res) => {
const product = await Product.remove({});
res.status(200).send({
data: product,
message: 'All the products are deleted successfully'
});
});

router.get('/:id', async (req, res) => {
const product = await Product.findOne({ _id: req.params.id });
Expand Down Expand Up @@ -55,6 +62,18 @@ router.post('/:id/reviews', isAuth, async (req, res) => {
res.status(404).send({ message: 'Product Not Found' });
}
});
router.get('/:id/reviews', isAuth, async (req, res) => {
const product = await Product.findById(req.params.id);
if (product) {
res.status(200).send({
data: product.reviews,
message: 'Reviews for the product with product id :' + req.params.id
});
} else {
res.status(404).send({ message: 'Product Not Found' });
}
});

router.put('/:id', isAuth, isAdmin, async (req, res) => {
const productId = req.params.id;
const product = await Product.findById(productId);
Expand Down Expand Up @@ -86,6 +105,7 @@ router.delete('/:id', isAuth, isAdmin, async (req, res) => {
}
});


router.post('/', isAuth, isAdmin, async (req, res) => {
const product = new Product({
name: req.body.name,
Expand Down