Skip to content

Commit

Permalink
Create DELETE Testimonial API
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgaur99 committed Jun 12, 2024
1 parent e09bbe7 commit fedeec1
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);

Check failure

Code scanning / CodeQL

Missing rate limiting High test

This route handler performs
authorization
, but is not rate-limited.

module.exports = router;

0 comments on commit fedeec1

Please sign in to comment.