Update product in database.
URL : /api/products/:id
URL parameter: id=[string]
where id
is mongoose object id syntax.
Method: PUT
{
"name": "[string (4-100 characters range)]",
"price": "[integer]"
}
{
"name": "ball",
"price": 105
}
Code: 200 OK
Condition: If product with provided correctly id exists and request body data is correct.
Updated product returned.
{
"__v": 0,
"_id": "6369523318c90dd1e14fd8b0",
"createdAt": "2022-11-07T18:45:07.229Z",
"name": "ball",
"price": 105,
"updatedAt": "2022-11-07T20:11:20.319Z"
}
Code: 400 BAD REQUEST
Condition: If provided id has incorrect type.
{ "id": "Provided id is incorrect" }
Code: 400 BAD REQUEST
Condition: If product with provided id doesn't exist.
{ "id": "Product with provided id doesn't exist" }
Code: 400 BAD REQUEST
Condition: If no id provided.
{ "id": "No id provided" }
Code: 400 BAD REQUEST
Condition: If no name provided.
{ "name": "Please provide the product name" }
Code: 400 BAD REQUEST
Condition: If provided name is shorter than 4 chars.
{ "name": "Product name is too short. Minimum length is 4 characters" }
Code: 400 BAD REQUEST
Condition: If provided name is longer than 100 chars.
{ "name": "Product name is too long. Maximum length is 100 characters" }
Code: 400 BAD REQUEST
Condition: If no price provided.
{ "price": "Please provide product price" }
Code: 400 BAD REQUEST
Condition: If provided price is not integer type.
{ "price": "Provided price has to be a numeric value" }