Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backend] Create DELETE Testimonial API #1044

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
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
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 { 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;
Loading