RESTful API that allows users to create, retrieve, update, and delete data on a PostgreSQL database
- node >= 18.18.0
- postgres >= 16.1
- docker >= 20.10.6 (intergrating docker-compose version)
Run the following command in root folder to install needed depedencies
npm install
Remember create rest_app
database before migrating.
Run the following command for migrating
npm run migration:run
Run the following command in root folder to startup the server
npm run start:dev
Open browser and go to link http://localhost:3000/swagger
or http://127.0.0.1:3000/swagger
for swagger UI and begin testing the API
Run the following command in root folder
docker compose up -d
Two containers:
- restful-app-database-1 listens on 5432 port (for postgres database)
- restful-app-nest-1 listens on 3000 port (for server code)
Please notice that the containers name maybe different in your local machine, to confirm container name, try to run:
docker ps
and pay attention to the containers those have restful-app
prefix in name.
Run the following command for migrating
docker exec restful-app-nest-1 npm run migration:run
Open browser and go to link http://localhost:3000/swagger
or http://127.0.0.1:3000/swagger
for swagger UI and begin testing the API
Remember create rest_app_test
database before migrating.
Run the following command for test database migrating
npm run migration:test:run
Run the following command for executing test (for all)
npm run test
Run the following command for executing test (for specify file)
npm run test [file_path]
for example:
npm run test src/users/infrastructure/rdb-repository/user/index.spec.ts
After starting up the docker container for both database and server
Run the following command for test database migrating
docker exec restful-app-nest-1 npm run migration:test:run
Run the following command for executing test (for all)
docker exec restful-app-nest-1 npm run test
Run the following command for executing test (for specify file)
docker exec restful-app-nest-1 npm run test [file_path]
for example:
docker exec restful-app-nest-1 npm run test src/users/infrastructure/rdb-repository/user/index.spec.ts
- domain: business domain logic will be here
- application: feature logic will be here
- presentation: API endpoints will be here
- infrastructure: interacts with external system (DB, APIs, ...)
In application layer, I split it into
- command: for updating, creating and deleting data logic.
- query: for getting data logic only.
The inside layer will never be depending on the outside layer, for example:
- domain will never be depending on application
- application will never be depending on presentation
And the outside layer will never be depending on the inside layer, for example:
- application will be depending on domain
- presentation will be depending on application
- domain will have
DomainError
- application will have
CommandError
andQueryError
- presentation will have
PresentationError
- infrastructure will have
InfrastructureError
See libs/exception
folder for more details.
Run the following command
npm run migration:generate --name="MigrationName"
to create new migration if you want.