This repo demonstrate how you can build Parking Spot booking api using Clean Architecture with Node.js, Express and Postgresql.
To get a local copy up and running, follow these simple example steps.
- Nod.js
v20.12.0
- docker-compose or postgresql
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 theDATABASE_URL
DATABASE_URL="postgresql://postgres:password@0.0.0.0:5432/spot_booking?schema=public"
-
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
-
npm run build
-
npm start
To run test cases npm run test
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 |
- 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
- 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
- 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
- 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
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