/TTD

Primary LanguageJavaScript

TTD

  • RESTful endpoint for TTD product CRUD operation

How to run

  • Make sure sequelize installed
  • run command "sequelize db:migrate"
  • run command "sequelize db:seed:all"
  • node index.js / nodemon (if already installed)

POST /product

create product

Request Header

not needed

Request Body

{
    name: <name of the product>,
    qty : <quantity of the product>,
    picture: <picture of the product in base64 format>,
    expiredAt: <product's expired date in "yyyy-mm-dd" format>,
}

Response (201)

{
    message: `A product created`,
    result: {
        "id": <id of the product>,
        "name": <name of the product>,
        "qty": <quantity of the product>,
        "picture": <picture of the product in base64 format>,
        "expiredAt": <product's expired date>,
        "isActive": <true by default>,
        "createdAt": <the time when the product created>,
        "updatedAt": <the time when the product last modified>,
    },
}

Response (500 - Internal Server Error)

{
  "message": "Error",
  "error": <returned error message>
}

GET /product

Get all Prodyct

Request Header

not needed

Request Body

not needed

Response (200)

{
    "message": "success retrieve product",
    "result": [{
        "id": <id of the product>,
        "name": <name of the product>,
        "qty": <quantity of the product>,
        "picture": <picture of the product in base64 format>,
        "expiredAt": <product's expired date>,
        "isActive": <true by default>,
        "createdAt": <the time when the product created>,
        "updatedAt": <the time when the product last modified>,
    },
    {},
    {},
    ....
    ]
}

Response (500 - Internal Server Error)

{
    message: "Error",
    error: <returned error message>,
}

GET /product/:id

Get a Product based on id

Request Header

{
    "access_token": <This access token generated automatically when you Log-in>
}

Request Params

{
    id: <id of the product>
}

Response (200)

{
    "message": "success retrieve product with id <id>",
    "result": {
        "id": <id of the product>,
        "name": <name of the product>,
        "qty": <quantity of the product>,
        "picture": <picture of the product in base64 format>,
        "expiredAt": <product's expired date>,
        "isActive": <true by default>,
        "createdAt": <the time when the product created>,
        "updatedAt": <the time when the product last modified>,
    }
}

Response (400 - ID missing)

{
    message: "Id is missing",
}

Response (404 - product not found)

{
    message: `product with id ${id} not found`,
    result: [],
}

Response (500 - Internal Server Error)

{
    message: "Error",
    error: <returned error message>,
}

PUT /product/:id

update a Product by id

Request Header

not needed

Request Params

{
    id: <id of the product>
}

Request Body

{
    name: <new name of the product>,
    qty : <new quantity of the product>,
    picture: <new picture of the product in base64 format>,
    expiredAt: <new product's expired date in "yyyy-mm-dd" format>,
}

Response (200 - Ok)

{
    message: `successfully update a product with id ${id}`,
}

Response (400 - Something is missing in body)

{
    message: "something is missing",
}

Response (400 - missing ID)

{
    message: "Id is missing",
}

Response (404 - Not Found)

{
    message: "Product not found",
}

Response (500 - Internal Server Error)

{
    message: "Error"
    error: <returned error message>
}

DELETE /product/:id

soft Delete a product based on id

Request Header

not needed

Request Params

{
    id: <ID of the product>
}

Response (200 - Ok)

{
    message: `successfully soft delete a product with id ${id}`,
}

Response (400 - Missing Id)

{
    message: "Id is missing",
}

Response (404 - Not Found)

{
     message: "Product not found",
}

Response (500 - Internal Server Error)

{
    message: "Error"
    error: <returned error message>
}