Namastecorp assignment
Here's a high-level diagram of the components in our application:
Before you begin, make sure your development environment includes the following:
- Docker
- Docker Compose
- Clone the repository:
git clone https://github.com/minhhieple97/namastecorp-assignment.git
-
Create a
.env
file in the root of the project, following the example in.env.example
, and fill in the necessary environment variables. -
Build and start the development containers with Docker Compose (Container may take up to 30 seconds to start up):
docker-compose up -d api_dev
This will build the Docker images and start the containers for the development environment.
- Access the Nest.js application at
http://localhost:3000
.
To use the API, follow these steps:
- Open your browser or a tool like Postman and make a POST request to
http://localhost:3000/flights
with thex-api-key
header set toasjdfh23r9u23r9fj
. - In the request body, include a JSON object with an array of flight data:
{
"flights": [
{
"from": "HN",
"to": "HCM"
},
{
"from": "HCM",
"to": "SFO"
},
{
"from": "SFO",
"to": "GRU"
},
{
"from": "GRU",
"to": "SCL"
},
{
"from": "SCL",
"to": "LHR"
},
{
"from": "LHR",
"to": "CDG"
},
{
"from": "CDG",
"to": "SYD"
},
{
"from": "SYD",
"to": "JFK"
}
]
}
To run the unit tests, run npm run test
in the terminal. This will run all the unit tests and output the results to the console.
Need run all command bellow inside container
- Generate a migration file for initializing the database schema:
npm run migration:generate -- src/db/migrations/<fileName>
- Create a migration file:
npm run migration:create -- src/db/migrations/<fileName>
- Run migration file
npm run migration:run
- Build image for specify environment
docker-compose build --no-cache --build-arg TARGET=<environment> <image_name>
To run the application in production, you should first build a Docker image:
docker-compose -f docker-compose.production.yml build --build-arg TARGET=production api_prod
docker-compose -f docker-compose.production.yml up -d