Can use validations
matheushenriquecsb opened this issue · comments
Matheus Henrique commented
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);
}