- Use NestJs to create a restful-API using the db scheme and the endpoint description in the AppIndex
- Try not to use the ORM for serialization and making the query
- Use custom validation pipe /decorators
- Document how to fire up the project
- Please use a git based version control and share the repo with us
- Use redis or any other in-memory cache technique.
- Create docker containers for the user service with it's database. The system consists of three containers:
- A relational database service of your choice (ex: mysql, mssql, postgres, etc...)
- A node js service running the NestJs framework
- A redis instance
- Extra for a full stack position:
- Create react app (looks are not important) using the endpoints you created in NestJs and ship it with the project (Login/Register/Profile)
The core application is located directly in the main AppModule
. It contains user and profile creation. Then you will find three more modules:
AuthModule
which contains:- The
AuthGuard
used to secureGET /api/profile
endpoint - The
AuthService
,JWTService
andJWTAuthStrategy
to process login and generate the JWT token - The
AuthController
to expose/auth
endpoint to log in
- The
DatabaseModule
to connect to PostgreSQL. Since using an ORM was not encouraged, instead of having repositories for the different entities, I created a custom service by using pg node-postgres client for all DB queries.RedisCacheModule
which uses NestJS cache manager with Redis as a data store to save a cache for recently retrieved Profiles.- Note: I left a console log on propouse at this line to easily see if the Profile requested is comming from the Database.
- Note: Cache time to live timer is set to 60 seconds.
The only pre requisite is that you need to have Docker installed in your machine. After that, you can set up the applicacion by simply running the docker containers. You can use the environment configuration file provided in this repo:
$ docker-compose --env-file service/src/utils/credentials.env up
- Create a user by doing a POST request to
/api/users
with the user data:
curl --location --request POST 'localhost:5000/api/users' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Profile Name",
"username": "username",
"password": "pa$$word",
"address": "Street 1234",
"cityId": 1
}'
- Before getting you profile information again, you will also need to log in by doing a POST to
/auth
:
curl --location --request POST 'localhost:5000/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
"username": "username",
"password": "pa$$word"
}'
- All set! Now you can use the retrieved JWT token to GET you profile with
/api/profile
curl --location --request GET 'http://localhost:5000/api/profile' \
--header 'Authorization: Bearer {JWT Token}'
- Simply go to http://localhost:3000 and create an user.
- Once you have an user created, go to Login page and retrieve your profile information. Is that easy!