Skip to content

Latest commit

 

History

History
124 lines (80 loc) · 1.82 KB

put.md

File metadata and controls

124 lines (80 loc) · 1.82 KB

Update product

Description

Update product in database.

URL : /api/products/:id

URL parameter: id=[string] where id is mongoose object id syntax.

Method: PUT

Data constraints

{
  "name": "[string (4-100 characters range)]",
  "price": "[integer]"
}

Data example

{
  "name": "ball",
  "price": 105
}

Success Response

Code: 200 OK

Condition: If product with provided correctly id exists and request body data is correct.

Context example

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"
}

Error Response

ID

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" }

Body

Name

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" }

Price

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" }