Skip to content

Spot booking api using Clean Architecture. #express.js #typescript #node.js

Notifications You must be signed in to change notification settings

imVinayPandya/spot-booking

Repository files navigation

Book Parking Sport

Table of Contents


📍 About The Project

This repo demonstrate how you can build Parking Spot booking api using Clean Architecture with Node.js, Express and Postgresql.

🚀 Getting Started

To get a local copy up and running, follow these simple example steps.

Prerequisites

  • Nod.js v20.12.0
  • docker-compose or postgresql

Setup Database & env

If you have already installed Postgresql on your machine. you can create database spot_booking and skip this step.

  • use docker-compose to run database. Open root of the project in terminal and run this command

    docker-compose up
    
  • Rename .env.example to .env and update the DATABASE_URL

    DATABASE_URL="postgresql://postgres:password@0.0.0.0:5432/spot_booking?schema=public"
    

Run project for local development

  • Install Dependencies npm install

  • Setup .env as previously mentioned

  • Run database migration npm run migrate

  • Seed dummy data into database npm run seed

  • Start server npm run dev

  • visit http://localhost:8000

Run on Production

  • npm run build

  • npm start

Run test

To run test cases npm run test


Seed Dummy data

  • npm run seed to seed dummy data into database and You will have following data in your database

Users

userId name role token
user-1 vinay admin token-1
user-2 shivam standard token-2

Parking Spot

spotId name
abc-1 spot_one
abc-2 spot_two

🤖 List of test cases

BookingController onCreateBooking
  • should return 400 if request body is invalid
  • should return 400 if endDateTime should be greater than startDateTime
  • should return 403 if standard user tries to create booking for other users
  • should return 409 if booking already exists for the given parking spot and time
  • should return PrismaClientKnownRequestError if parkingSpot or forUserId is does not exist in DB (52 ms)
  • should return 201 if booking is created successfully
BookingController onGetBooking
  • should return 200 and should do DB query with Offset=0, limit=2
  • Should return 200 and return all bookings for Admin user
  • Should return 200 and return bookings of standard user
BookingController onUpdateBooking
  • should return 409 if booking already exists for the given parking spot and time
  • should return 404 if booking does not exist in DB (3 ms)
  • should return 400 if request body is invalid
  • should return 403 if standard user tries to update other user's booking
  • should return 200 if booking is updated successfully
BookingController onDeleteBooking
  • should return 400 if bookingId not found in request params
  • should return 404 if booking not found in database
  • should return 403 if standard user tries to delete other user's booking
  • should return 200 if booking is deleted successfully

TODOs: (Things can be done)

My initial goal is to keep my focus on creating api with business requirement. I have listed few Todo or things can be done differently

  • Docker for Node.js app
  • Different error handler for httpError, Database error, validation error
  • Unified response object (for error & success)
  • implement intigretion test
  • Improve folder structure
  • Api versioning

About

Spot booking api using Clean Architecture. #express.js #typescript #node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published