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

Can use validations #107

Open
matheushenriquecsb opened this issue May 31, 2023 · 0 comments
Open

Can use validations #107

matheushenriquecsb opened this issue May 31, 2023 · 0 comments

Comments

@matheushenriquecsb
Copy link

You can use validation in controllers, when the user makes a search request for the parameter, it would be interesting to use the conditional.

Example in hotelController:

export const deleteHotel = async (req, res) => {
try {
const removeHotel = await Hotel.findByIdAndRemove(req.params.id);
//You can use validate here, is check if id exists before return 200;
if (!removeHotel) {
return res.status(404).json({ message: "Hotel deleted" });
}
return res.status(200).json("Hotel has been deleted!");
} catch (error) {
return res.status(500).json(error);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant