Untitled
unknown
plain_text
2 years ago
796 B
11
Indexable
const idExistsValidator = (id) => !id || id === undefined;
const nameExistsValidator = (name) => !name || name === undefined;
const updateProductName = async (req, res) => {
const { id } = req.params;
const { name } = req.body;
try {
if (idExistsValidator(id)) {
return res.status(404).json({ message: 'Product not found' });
}
if (nameExistsValidator(name)) {
return res.status(400).json({ message: '"name" is required' });
}
if (name.length < 5) {
return res.status(422).json({ message: '"name" length must be at least 5 characters long' });
}
const updatedProduct = await productsService.updateProductName(id, name);
res.status(200).json(updatedProduct);
} catch (error) {
res.status(404).json({ message: error.message });
}
};Editor is loading...
Leave a Comment