MCPcopy Create free account
hub / github.com/Muhammadsiddiq-code/backend-group-lessons / updateCar

Function updateCar

controller/carController.js:81–126  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

79
80// Update car
81const updateCar = async (req, res) => {
82 try {
83 const { id } = req.params;
84 const {
85 model,
86 description,
87 color,
88 horsePower,
89 carType,
90 charging,
91 weight,
92 gasoline,
93 yearMachine,
94 price,
95 } = req.body;
96
97 const updatedCar = await Car.findByIdAndUpdate(
98 id,
99 {
100 model,
101 description,
102 color,
103 horsePower,
104 carType,
105 charging,
106 weight,
107 gasoline,
108 yearMachine,
109 price,
110 },
111 { new: true }
112 );
113
114 if (!updatedCar) {
115 return res.status(404).json({ message: "Bunday id mavjud emas" });
116 }
117
118 res.json({
119 message: "Mashina muvaffaqiyatli o'zgartirildi",
120 car: updatedCar,
121 });
122 } catch (error) {
123 console.log(error);
124 res.status(500).json({ message: error.message });
125 }
126};
127
128// Delete car
129const deleteCar = async (req, res) => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected