A simple API for reserving tables at a restaurant. The API is based on the REST architectural style and uses Node.js, TypeScript, Express, TypeORM and stores the data in MySQL database. All is running in Docker containers.
- Use Node.js, TypeScript.
- Store data in a MySQL database.
- Run everything on Docker containers.
- Pay attention to:
- validation rules,
- error handling,
- type safety,
- dependency management.
- Nice to have:
- Use functional programming paradigms.
- OpenAPI documentation.
- Use TDD (test driven development) paradigms.
- Deploy the API to Heroku or Vercel.
- There should be a
Userentity. Users should havenameandemailfields. A user should be unique by email.- Create a
Userstable in database. - Create a
Usermodel. - Generate some fake users.
- It should be possibile to create a new user.
- Create a
- There should be a
Restaurantentity. For simplicity a restaurant should have only 5 tables, each with 4 seats. Seating time is 1 hour and a restaurant is open every day from 19:00 to 00:00.- Create a
Restaurantstable in database. - Create a
Restaurantmodel. - Generate some fake restaurants.
- It should be possibile to create a new restaurant.
- Each restaurant should 5 tables with 4 seats each.
- Nice to have:
- It should be possible to get the list of all restaurants.
- It should be possible to get the list of all restaurants not fully booked in a specific date.
- It should be possible to get the list of all restaurants that have at least 1 free table in a certain date and hour.
- In the future:
- Introduce
superadmin,restaurant_ownerandgeneric_userroles. - Restaurants should be associated to a user with
restaurant_ownerprivileges. - Users with
restaurant_ownerprivileges should be able to create, update and delete their own restaurants. - Users with
superadminprivileges should be able to create, update and delete users. - Users with
superadminprivileges should be able to update and delete restaurants and reservations.
- Introduce
- Create a
- There should be a
Reservationentity.- Create a
Reservationstable in database. - Create a
Reservationmodel. - Generate some fake reservation.
- It should be possibile to make a reservation (book a restaurant) in a specific date and time.
- It should be possibile to get all reservations given a specific date range.
- The results of the reservation list should be paginated.
- Overbooking should not be allowed.
- Each researvation's seating time is 1 hour.
- Nice to have:
- It should be possibile to get all reservations given a restaurant.
- It should be possibile to get all reservations given a user.
- It should be possibile to get all reservations given a specific date range and a restaurant.
- It should be possibile to get all reservations given a specific date range and a user.
- It should be possibile to get all reservations given a specific restaurant and a user.
- It should be possibile to get all reservations given a specific date, restaurant and user.
- Create a
Clone the project
$ git clone git@github.com:formidablae/restaurant-reservation-api.git
Change directory to inside the project
$ cd restaurant-reservation-api
Copy environment variables from .env.example to .env
$ cp .env.example .env
Fire up the containers with the database and the API.
To run with Docker see the alternative instructions in the end.
$ docker-compose up -d
Run the migrations
$ docker exec -it restaurant_reservations_app /bin/bash -c "node --require ts-node/register ./node_modules/typeorm/cli.js migration:run"
Sync the database
$ docker exec -it restaurant_reservations_app /bin/bash -c "node --require ts-node/register ./node_modules/typeorm/cli.js schema:sync && npm run db:migrate"
If anything isn't working as expected:
$ docker-compose down -v
$ docker container prune
$ docker volume prune
$ docker image ls # ids of the images to remove
$ docker image rm <IMAGE ID 1> <IMAGE ID 2> # get the ids from previous command
$ docker-compose up --build -d
... continue with the rest of the instructions from above.
Install the packages
$ npm install
Create the database
$ npm run db:create
Do the migrations
$ npm run db:migrate
Sync the database
$ npm run db:sync
Run the project
$ npm run build
$ npm run start
or
$ npm run dev
or
$ npm run debug