Developed with Typescript, Express & TypeORM.
- Clone the repo locally
- Run
npm i && npm start
Note: Currently the project is setup with sqlite db,
database.sqlite
in the root folder of the project. If we reset the db then first we need to runnpm start
and thennpm run migration:run
in order to create the first admin user.
- Endpoint: POST
http://localhost:3000/auth/login
- Body:
{ "username": "admin", "password": "admin" }
- Response:
{ "token": <token> }
- Endpoint: GET
http://localhost:3000/users
- Headers:
jwt-token
=> we should use as the value the token that we received from login.
- Response:
[ { "id": 1, "username": "admin", "role": "ADMIN" }, { "id": 2, "username": "test.account", "role": "USER" } ]
- Endpoint:
http://localhost:3000/users/1
- Headers:
jwt-token
=> we should use as the value the token that we received from login.
- Response:
{ "id": 1, "username": "admin", "role": "ADMIN" }
- Endpoint: GET
http://localhost:3000/users
- Headers:
jwt-token
=> we should use as the value the token that we received from login.
- Body:
{ "username": "new_test.account", "password": "secret", "role": "USER" }
- Response:
{ "message": "User created", "user": { "id": 2, "username": "new_test.account", "role": "USER", "createdAt": "2019-04-25T19:52:33.000Z", "updatedAt": "2019-04-25T19:52:33.000Z" } }
- Endpoint: GET
http://localhost:3000/users/2
- Headers:
jwt-token
=> we should use as the value the token that we received from login.
- Body:
{ "username": "test6.account", "role": "USER" }
- Response:
{ "message": "User updated!", "user": { "id": 2, "username": "test6.account", "role": "USER", "createdAt": "2019-04-25T19:25:38.000Z", "updatedAt": "2019-04-25T20:18:21.000Z" } }
- Endpoint: GET
http://localhost:3000/users/2
- Headers:
jwt-token
=> we should use as the value the token that we received from login.
- Response:
{ "message": "User deleted!" }