A Restaurant (Table) Reservation API built with Node, TypeScript, Express, TypeORM, a MySQL DB, all running on Docker containers

Overview

Restaurant (Table) Reservation API

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.

Requirements

Tech stack & best practice requirements:

  • 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.

Feature requirements:

  • There should be a User entity. Users should have name and email fields. A user should be unique by email.
    • Create a Users table in database.
    • Create a User model.
    • Generate some fake users.
    • It should be possibile to create a new user.
  • There should be a Restaurant entity. 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 Restaurants table in database.
    • Create a Restaurant model.
    • 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_owner and generic_user roles.
      • Restaurants should be associated to a user with restaurant_owner privileges.
      • Users with restaurant_owner privileges should be able to create, update and delete their own restaurants.
      • Users with superadmin privileges should be able to create, update and delete users.
      • Users with superadmin privileges should be able to update and delete restaurants and reservations.
  • There should be a Reservation entity.
    • Create a Reservations table in database.
    • Create a Reservation model.
    • 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.

Instructions on how to run the project

Clone the project

$ git clone [email protected]: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.

Alternatively, you can run the following commands in a terminal to build and run without Docker

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

You might also like...

Simple REST API using Express with TypeScript, PostgreSQL, and MySQL to practice the Clean Architecture by Uncle Bob.

Clean-Architecture Simple REST API using Express with TypeScript, PostgreSQL, and MySQL to practice the Clean Architecture by Uncle Bob. About This RE

Oct 16, 2022

Blog application api in Node.js express.js sequelize ORM and MYSQL Database

Node Express Mysql Sequelise Blog System Api Node api with express mysql sequelise Usage To get started with this api follow the steps below $ git clo

Nov 9, 2022

This restaurant project is a SPA (single-page application) website. The user can navigate between the home, menu and contact page. I used the MealDB API to display some menu items.

This restaurant project is a SPA (single-page application) website. The user can navigate between the home, menu and contact page. I used the MealDB API to display some menu items.

Fresh Cuisine This restaurant project is from the Odin Project and it is a SPA (single-page application) website. The user can navigate between the ho

Nov 2, 2022

A Nest.js API for a restaurant storage management system.

Restaurant Storage Management System Description A Nest.js API for a restaurant storage management system. Installation $ yarn install Database Seeder

Sep 12, 2022

REST API built with Node.js, MongoDB, Mongoose & TypeScript. I also dabbled with Docker and Caddy for deployments

REST API built with Node.js, MongoDB, Mongoose & TypeScript. I also dabbled with Docker and Caddy for deployments

REST API with Node.js, Mongoose & TypeScript Note: This repository includes the postman collection for the finished API Note 2: Make sure you add .env

Sep 16, 2022

Application template for NestJS + Docker + Prisma + MySQL

nestjs-docker-prisma-mysql Application template for NestJS + Docker + Prisma + MySQL Setup # install $ yarn # Setup env file for database $ cp .env.e

Oct 15, 2022

A dockerized express mysql starter using typescript which iclude user management

A dockerized express mysql starter using typescript which iclude user management

Jan 26, 2022

practice site to utilize node.js, Express, and mySQL

fishing_site practice site to utilize node.js, Express, and mySQL Run Locally create local instance of MySQL database. Run DB/fishing_Schema.sql to cr

Jan 22, 2022

Node.js Express + MySQL vulnerable boilerplate project

Node.js Express + MySQL vulnerable boilerplate project

Node.js Express + MySQL vulnerable boilerplate project

Sep 16, 2022
Comments
  • Major changes to API routes and functionalities

    Major changes to API routes and functionalities

    • Implemented functionality to get reservations filtering by user_id, by restaurant_id and with pagination and sorting. Get and delete reservation by id
    • Implemented functionality to get restaurants filtering by fully booked, not fully booked or all, from and to datetime, with pagination and sorting. Get and delete restaurant by id
    • Made a onetomany relation between restaurants and their reservations. Included service from previous commit
    • Restaurant service from previous commits
    • Implemented functionality to get and delete users by id
    • Updated restaurant routes to include new filtered, getbyid and delete functionalities
    • Updated reservations routes to include new filtered, getbyid and delete functionalities
    • Updated user routes to include getbyid and delete functionalities
    • Updated README with overall project progress ticks
    • Updated Postman collection queries

    Closes #30 Closes #31 Closes #32 Closes #33 Closes #34 Closes #35 Closes #36 Closes #37 Closes #38 Closes #39 Closes #30 Closes #40 Closes #41 Closes #42

    documentation enhancement 
    opened by formidablae 0
  • Implementation of route to get, add and filter. Addition of API docs. Other small fixes

    Implementation of route to get, add and filter. Addition of API docs. Other small fixes

    • Added API docs and collections from Postman (Closes #20 , #19 )
    • Corrected directory paths for migrations and seeders
    • Fixed schema of OpenAPI docs for Users, Restaurants and Reservations to be arrays of their objects
    • Added Reservation model (Closes #21 )
    • Added reservation service (Closes #22
    • Renamed database and users services
    • Updated User and Restaurant models
    • Fixed UserController to return a message when there are no users found (Closes #23 )
    • Added a restaurants service (Closes #24 )
    • Added routes for restaurants and reservations (Closes #25 )
    • Added RestaurantController and ReservationController to get and add restaurants and reservations. Reservations can be filtered by a date range (Closes #26 )
    • Added routes to get and add restaurants and reservations
    documentation enhancement 
    opened by formidablae 0
Owner
Software Developer
null
This is boilerplate of express, typescript and postgreSql with typeorm and docker based setup

express-typescript-postgres-typeorm-docker-swagger-boilerplate This is boilerplate of express, typescript and postgreSql with typeorm and docker based

beBhavyhere 2 Jun 2, 2022
Running webdriverio in docker containers so you can easily add tests to your CI.

WebDriverIO tests in Docker Running WebdriverIO tests in a docker container allows you to easily add tests to your CI. About This project uses the aut

Promenade 6 Dec 3, 2022
Personal Blog - a project developed with Angular for the front-end interface and Wordpress for the back-end API served with Docker containers

PersonalBlog This project was generated with Angular CLI version 13.0.1. Front-end Interface Development server Run ng serve or ng serve --configurati

null 9 Oct 5, 2022
Jugglr is a tool for managing test data and running tests with a dedicated database running in a Docker container.

Jugglr Jugglr is a tool for managing test data and running tests with a lightweight, dedicated database. Jugglr enables developers, testers, and CI/CD

OSLabs Beta 74 Aug 20, 2022
converts nuggies to usd and usd to nuggies for a variety of restaurant chains. Also includes a rest api. Built using NextJS and TypeScript

Prices All prices are currently based on the 4-piece from the respective chain or the equivalent lowest amount of nuggies. Plan is to add multiple pri

Sean Maizel 2 Jan 14, 2022
Docker: Criando containers sem dor de cabeça.

Docker: Criando containers sem dor de cabeça. A evolução do host de aplicações Antigamente... Várias aplicações, vários servidores. Capacidade pouco a

Lucas Magalhães 3 Jun 23, 2022
Customizable browser's home page to interact with your homeserver's Docker containers (e.g. Sonarr/Radarr)

Homarr A homepage for your server. Demo ↗️ • Install ➡️ Join the discord! ?? Table of Contents ?? Table of Contents ?? Getting Started ℹ️ About ?? Kno

Thomas Camlong 1.6k Jan 7, 2023
Govinor is a platform to deploy and preview docker containers.

Govinor A platform for creating and managing Docker containers that integrates with Github to offer branch preview links. Note: This is a work in prog

iFixit 2 Jan 10, 2022
⛴ Manage Docker containers from the menu bar.

Captain INTRODUCTION Manage Docker containers. Instantly from the menu bar. See which containers are running and which have stopped. Conveniently star

Rick Wong 19 Dec 8, 2022
🐶 Puppies Rest Api built with NestJs, TypeOrm, PostgreSQL, Swagger

?? Quick start: Install node Install nest cli: `npm i -g @nestjs/cli` Initialize a nestjs project `nest new project-name` Swagger Docs swagger docs P

Ogunnusi Abayomi Joseph 3 Oct 1, 2022