Backend test for Solveware.
Environment variables are availabel in .env.example
file.
Make sure you have filled out all environment variables listed in .env.example
file and have created the database.
git clone https://github.com/rafiandria23/solveware-test.git
npm install
# DB Migration (Development Only)
npm run migrate
# DB Seed (Development Only)
npm run seed
# Production
npm start
# Development
npm run dev
Endpoint: /users/register
Method: POST
Request Body
{
"email": "john@gmail.com",
"password": "password123"
}
Response Body
{
"message": "Successfully registered!",
"user": {
"name": "John Doe",
"email": "john@gmail.com
},
"accessToken": "exampleAccessToken"
}
Endpoint: /users/login
Method: POST
Request Body
{
"email": "john@gmail.com",
"password": "password123"
}
Response Body
{
"message": "Successfully logged in!",
"user": {
"name": "John Doe",
"email": "john@gmail.com
},
"accessToken": "exampleAccessToken"
}
Endpoint: /carts/:productId
Method: POST
Response Body
{
"message": "Successfully added to cart!",
"cart": {
"userId": 1,
"productId": 1,
"qty": 1,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
}
}
Endpoint: /transactions/:cartId
Method: POST
Response Body
{
"message": "Successfully created transaction!",
"transaction": {
"userId": 1,
"productId": 1,
"datetime": "2021-05-08T20:49:38.274Z",
"paid": true,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
}
}
Endpoint: /transactions
Method: GET
Response Body
{
"transactions": [
{
"userId": 1,
"productId": 1,
"datetime": "2021-05-08T20:49:38.274Z",
"paid": true,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
},
...
]
}
Endpoint: /transactions/:transactionId
Method: GET
Response Body
{
"transaction": {
"userId": 1,
"productId": 1,
"datetime": "2021-05-08T20:49:38.274Z",
"paid": true,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
}
}
Endpoint: /admins/login
Method: POST
Request Body
{
"email": "john@admin.com",
"password": "password123"
}
Response Body
{
"message": "Successfully logged in!",
"user": {
"name": "John Doe",
"email": "john@admin.com
},
"accessToken": "exampleAccessToken"
}
Endpoint: /products
Method: GET
Response Body
{
"products": [
{
"name": "MacBook Air - Apple M1 Chip with 8-Core CPU and 7-Core GPU 256 GB Storage",
"price": 1449,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
},
...
]
}
Endpoint: /products/:productId
Method: GET
Response Body
{
"products": {
"id:": 1,
"name": "MacBook Air - Apple M1 Chip with 8-Core CPU and 7-Core GPU 256 GB Storage",
"price": 1449,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
}
}
Endpoint: /products
Method: POST
Request Body
{
"name": "iPhone 12 Pro Max - 256 GB - Grey",
"price": 1799
}
Response Body
{
"message": "Successfully added product!",
"product": {
"name": "iPhone 12 Pro Max - 256 GB - Grey",
"price": 1799,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
}
}
Endpoint: /products/:productId
Method: PUT
Request Body
{
"name": "iPhone 12 Pro Max - 512 GB - Grey",
"price": 1799
}
Response Body
{
"message": "Successfully updated product!",
"product": {
"name": "iPhone 12 Pro Max - 512 GB - Grey",
"price": 1799,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T22:44:43.903Z"
}
}
Endpoint: /products/:productId
Method: DELETE
Response Body
{
"product": {
"name": "iPhone 12 Pro Max - 512 GB - Grey",
"price": 1799,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T22:44:43.903Z"
}
}
Endpoint: /users
Method: GET
{
"users": [
{
"name": "John Doe",
"email": "john@gmail.com",
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
},
...
]
}
Endpoint: /users/:userId
Method: GET
{
"user": {
"name": "John Doe",
"email": "john@gmail.com",
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
}
}
Endpoint: /transactions/all Method: GET
Response Body
{
"transactions": [
{
"userId": 1,
"productId": 1,
"datetime": "2021-05-08T20:49:38.274Z",
"paid": true,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
},
...
]
}
Endpoint: /transactions/:transactionId
Method: GET
Response Body
{
"transaction": {
"userId": 1,
"productId": 1,
"datetime": "2021-05-08T20:49:38.274Z",
"paid": true,
"createdAt": "2021-05-08T20:49:38.274Z",
"updatedAt": "2021-05-08T20:49:38.274Z"
}
}