Cafeteria
Description
This is a demo application for a cafeteria. It is a simple application that allows users to order food and drinks from a cafeteria. The application is built with NestJS and uses a MongoDb database. The application is dockerized and can be run with docker-compose or without docker, details are below.
Toolings
-
Docker version 20.10.17, build 100c701
-
Docker Compose version v2.6.0
-
Node.js version 18
-
NestJS ~
'cli -- common -- core'
version 9.x.x -
TypeScript version ^4.9.5
-
Yarn version 1.22.19
-
ESLint VsCode Extension for development
-
Prettier for development
Installation - without docker
Create and set up a .env
file using the sample in the .env.example
file.
$ yarn install
Running the app
# development
$ yarn run start
# watch mode
$ yarn run start:dev
# production mode
$ yarn run start:prod
Installation - with docker
Install and set up docker
according to your OS requirements
Running the app
You can use all the original docker commands but these few scripts are available for use.
# development - start a docker in undetached mode - we might not be able to watch file changes
$ yarn run docker:dev:up
# production - start a docker in undetached mode
$ yarn run docker:prod:up
# stop the running container
$ yarn run docker:down
# Remove dev container
$ yarn run docker:dev:rm
# Remove prod container
$ yarn run docker:prod:rm
# Restart dev container
$ docker:dev:restart
# Restart production container
$ docker:prod:restart
# At some point you might want to delete and rebuilt the image
$ docker image rm <image-id or repository-name>
API Documentation (Swagger): localhost
The API documentation is available at http://localhost:9092/api/v1/docs
when the application is running on localhost. Your port
can be different from the one above. Check your .env
file or the server logs on the terminal
for the PORT
variable value.
API Documentation (Swagger): live host
The API documentation is available at <your-host>/api/v1/docs
when the application is running.
Test the API
The API can be tested using the swagger documentation.
Create a user account and login to get a token. The token is required to access the protected routes.
Once you login, copy the accessToken and click on the Authorize
button on the top right corner of the page. Logout if not already logout. Paste the token in the input field and click on the Authorize
button. You can now test the API.
Test
# unit tests
$ yarn run test
# e2e tests
$ yarn run test:e2e
# test coverage
$ yarn run test:cov