There is a slight problem with updating the object via put request in my code. When i send put request with postman, request returns only the id of the genre object. Genre object has an id and a name properties.
app.put('/vidly/genres/:id', (req, res) => {
const genre = genres.find(g => g.id === parseInt(req.params.id));
if (!genre) return res.status(404).send('The genre was not found.');
const result = validateGenre(req.body.name);
if (result.error) return res.status(400).send(error.details[0].message);
genre.name = req.body.name;
res.send(genre);
});
function validateGenre(genre) {
const schema = Joi.object({
name: Joi.string().min(3).required()
});
return schema.validate(genre);
};
I am struggling to find a proper solution. Any help would be useful. If somebody could explain what am i doing wrong so i can have better understanding of this problem. Thank you very much