This is my Node API practice for Expense & Income App. You can try demo on https://nodeapialancx.herokuapp.com
- Controller -> UserController.js
- createNewUser Register
- login Authen Login
- findUser Getuser information by ID
- Controller -> UserController.js
- createTrans Add new transaction
- getTrans Get Transactions by user
- updateTrans Update Transaction by id
- deleteTrans Delete Transactins by id
First of all you need to register a new user
POST
/users- signup new user with username and password
Body:
{
"username": String,
"password": String
}
Example: POST
/users
Body:
{
"username": "TestUser",
"password": "12345678"
}
{
"_id": "5ce4e91730fa960d7023d8f9",
"username": "TestUser",
"password": "$2b$08$OkWTa4xPnJJXtFGGdker2.b30JrHwno4JRWFK5p2iTKVo58rMRozC"
}
GET
/users/:id
- get user information by user ID
Example: GET
/users/5c39f8e9d7f40f00a448a97e
- get user information that user ID is equal 5c39f8e9d7f40f00a448a97e
{
"_id": "5c39f8e9d7f40f00a448a97e",
"username": "myname",
"password": "mypassword"
}
POST
/users/login - login with username and password
Body:
{
"username": String,
"password": String
}
Example: POST
/users/login
Body:
{
"username": "myname",
"password": "mypassword"
}
Response Data:
{
"_id": "5c39f8e9d7f40f00a448a97e",
"username": "myname",
"password": "mypassword"
}
POST
/transactions
Body:
{
"user": userID,
"amount": Number,
"type": enum["income", "expense"],
"remark": String,
"date": Date
}
Example: POST
/transactions
- add new transaction
Body: { "user": "5c39f8e9d7f40f00a448a97e", "amount": 100, "type": "expense", "remark": "employing cost", "date": "2019-01-12T21:35:11+07:00" }
**Can check data in mongo client.
GET
/transactions?user=:user
- get transactions of some user
Example: GET
/transactions?user=5c39f8e9d7f40f00a448a97e
- get transactions of user which equals 5c39f8e9d7f40f00a448a97e
[
{
"_id": "5c39fb3991d29e00d406d3f1",
"user": "5c39f8e9d7f40f00a448a97e",
"amount": 200,
"type": "expense",
"remark": "employing cost",
"date": "2019-01-12T14:35:11.000Z"
}
]
PUT
/transactions/:id
- update transaction by transaction ID
Body:
{
"user": userID,
"amount": Number,
"type": enum["income", "expense"],
"remark": String,
"date": Date
}
Example: PUT
/transactions/5c39fb3991d29e00d406d3f1
- update transaction that transaction ID is equal 5c39fb3991d29e00d406d3f1
Body:
{
"user": "5c39f8e9d7f40f00a448a97e",
"amount": 100,
"type": "expense",
"remark": "employing cost",
"date": "2019-01-12T21:35:11+07:00"
}
DELETE
/transactions/:id
- delete transaction by transaction ID
Example: DELETE
/transactions/5c39fb3991d29e00d406d3f1
- delete transaction which ID equals 5c39fb3991d29e00d406d3f1