week-10-sanhendrindp-production.up.railway.app/
In this week 10 project, we built a RESTful API server using the MongoDB database. This app, later on, can do basic registration for new users and login. Users must have an account by registering and then login. And users will have a role, which is maker and approver. Maker can create a transfer request, but that request will be in pending status first. Then approver can change that status transfer to approved or not approved.
Here, i will try to explain the structure of important folders for this project by using the image below.
- Middleware: This folder serves to store middlewares for this project. It contains 3 files:
- database-middleware.js : Connection to MongoDB database (linked to Railway).
- authentication-middleware.js : To authenticate transfer requests by using JWT token. Creating a transfer and getting all transfers will need a token that is obtained when the user login.
- authorization-middleware : To authorize based on users role, maker or approver.
- Routes: This folder serves to set the route for users and transfers, contains 2 files:
- user-route.js : For login and users register.
- transfer-route.js : For transfer route.
- Controller: This folder contains logic code for folder routes. It contains 2 files:
- user-controller.js : Logic code for user-route.js
- transfer-controller.js : Logic code for transfer-route.js
- Config: Contain jwt.js to configure JWT token signature.
- Docs: Contain openapi.yaml for API documentation which can be run by using Swagger.
-
POST : /users/register
For register, users need to input their username and password which is for password needs a minimum length of 8, and should contain alphanumeric. Users need to input their role which is maker or approver.
-
POST : /users/login
When users login, they will generate a token that will be used to get all transfer lists and create a transfer request.
-
POST : /transfers
By login, users will generate a token, that token can be used for creating a new transfer request. To create a transfer request user needs to input the amount of transfer and information about the transfer.
-
GET : /transfers
With token, users also can see all transfers lists.
-
PUT : /transfer/approve
When login as approver role, user approver need to input ID transfer and then can update the transfer status created by the user maker to approved or not approved status. But remember, to update the status, user approver needs to input the token that is generated when they login.
Approve Status by Approver Role
Thank you ๐