Skip to content

Commit

Permalink
πŸ€[Backend] Create DELETE Testimonial API (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgaur99 authored Jun 12, 2024
1 parent e09bbe7 commit 3fefdb3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions backend/app/routes/testimonial/deleteTestimonial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const to = require('await-to-js').default;
const Testimonial = require('../../models/Testimonial');
const { ErrorHandler } = require('../../../helpers/error');
const constants = require('../../../constants');

module.exports = async (req, res, next) => {
const [err, testimonial] = await to(Testimonial.findByIdAndDelete(req.params.id));
if (!testimonial) {
const error = new ErrorHandler(constants.ERRORS.INPUT, {
statusCode: 400,
message: "Testimonial doesn't exist",
});
return next(error);
}
if (err) {
const error = new ErrorHandler(constants.ERRORS.DATABASE, {
statusCode: 500,
message: 'Mongo Error: Deletion Failed',
errStack: err,
});
return next(error);
}
res.status(200).send({
message: 'Testimonial deleted successfully',
});
return next();
};
3 changes: 2 additions & 1 deletion backend/app/routes/testimonial/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ const { authMiddleware } = require('../../../helpers/middlewares/auth');
const { postTestimonialValidationSchema } = require('./@validationSchema');
const postTestimonial = require('./postTestimonial');
const getTestimonials = require('./getTestimonials');
const deleteTestimonial = require('./deleteTestimonial');

router.post('/', validationMiddleware(postTestimonialValidationSchema), authMiddleware, postTestimonial);
router.get('/getTestimonials', getTestimonials);

router.delete('/:id', authMiddleware, deleteTestimonial);

module.exports = router;

0 comments on commit 3fefdb3

Please sign in to comment.