safak / youtube2022

Season 2 on Lama Dev
2.39k stars 2.24k forks source link

Can use validations #107

Open matheushenriquecsb opened 1 year ago

matheushenriquecsb commented 1 year ago

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); }