-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e09bbe7
commit fedeec1
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters