Welcome to the Sports Facility Booking Platform! This project is designed to provide a hassle-free way for users to book sports facilities. The backend is built with TypeScript, Express.js, and Mongoose for MongoDB. It includes user authentication, facility management, booking creation, and availability checking.
- Programming Language: TypeScript
- Web Framework: Express.js
- ODM & Validation Library: Mongoose for MongoDB
- Authentication: JWT (JSON Web Tokens)
- Validation: Zod
- Package Manager: Yarn
- Node.js (v18 or higher)
- Yarn
- Clone the repository:
git clone https://github.com/MdMuzahid07/P-HERO-Level-2-Assignment-3.git
- Navigate to the project directory:
cd ./P-HERO-Level-2-Assignment-3
- Install dependencies:
yarn install
- Create a
.env
file in the root directory and add the following environment variables:
DB_USERNAME=
DB_PASSWORD=
DB_URL=
PORT=5000
NODE_ENV=development
BCRYPT_SALT_ROUND=10
JWT_ACCESS_SECRET_KEY=
JWT_REFRESH_SECRET_KEY=
JWT_ACCESS_TOKEN_EXPIRES_IN=3d
JWT_REFRESH_TOKEN_EXPIRES_IN=10d
- Start the development server:
yarn start-dev
To build the project and run it in production mode:
yarn build
yarn start
yarn lint
yarn lint-fix
yarn prettier
yarn prettier-fix
-
User Sign Up
- Route:
POST /api/auth/signup
- Request Body:
{ "name": "Programming Hero", "email": "[email protected]", "password": "programming-hero", "phone": "01322901105", "role": "admin", // or 'user' "address": "Level-4, 34, Awal Centre, Banani, Dhaka" }
- Response:
{ "success": true, "statusCode": 200, "message": "User registered successfully", "data": { "_id": "60d9c4e4f3b4b544b8b8d1c4", "name": "Programming Hero", "email": "[email protected]", "role": "admin", "phone": "01322901105", "address": "Level-4, 34, Awal Centre, Banani, Dhaka" } }
- Route:
-
User Login
- Route:
POST /api/auth/login
- Request Body:
{ "email": "[email protected]", "password": "programming-hero" }
- Response:
{ "success": true, "statusCode": 200, "message": "User logged in successfully", "token": "JWT_TOKEN", "data": { "_id": "60d9c4e4f3b4b544b8b8d1c4", "name": "Programming Hero", "email": "[email protected]", "role": "admin", "phone": "01322901105", "address": "Level-4, 34, Awal Centre, Banani, Dhaka" } }
- Route:
-
Create a Facility (Admin Only)
- Route:
POST /api/facility
- Headers:
Authorization: Bearer JWT_TOKEN
- Request Body:
{ "name": "Tennis Court", "description": "Outdoor tennis court with synthetic surface.", "pricePerHour": 30, "location": "456 Sports Ave, Springfield" }
- Response:
{ "success": true, "statusCode": 200, "message": "Facility added successfully", "data": { "_id": "60d9c4e4f3b4b544b8b8d1c5", "name": "Tennis Court", "description": "Outdoor tennis court with synthetic surface.", "pricePerHour": 30, "location": "456 Sports Ave, Springfield", "isDeleted": false } }
- Route:
-
Update a Facility (Admin Only)
- Route:
PUT /api/facility/:id
- Headers:
Authorization: Bearer JWT_TOKEN
- Request Body:
{ "name": "Updated Tennis Court", "description": "Updated outdoor tennis court with synthetic surface.", "pricePerHour": 35, "location": "789 Sports Ave, Springfield" }
- Response:
{ "success": true, "statusCode": 200, "message": "Facility updated successfully", "data": { "_id": "60d9c4e4f3b4b544b8b8d1c5", "name": "Updated Tennis Court", "description": "Updated outdoor tennis court with synthetic surface.", "pricePerHour": 35, "location": "789 Sports Ave, Springfield", "isDeleted": false } }
- Route:
-
Delete a Facility - Soft Delete (Admin Only)
- Route:
DELETE /api/facility/:id
- Headers:
Authorization: Bearer JWT_TOKEN
- Response:
{ "success": true, "statusCode": 200, "message": "Facility deleted successfully", "data": { "_id": "60d9c4e4f3b4b544b8b8d1c5", "name": "Updated Tennis Court", "description": "Updated outdoor tennis court with synthetic surface.", "pricePerHour": 35, "location": "789 Sports Ave, Springfield", "isDeleted": true } }
- Route:
-
Get All Facilities
- Route:
GET /api/facility
- Response:
{ "success": true, "statusCode": 200, "message": "Facilities retrieved successfully", "data": [ { "_id": "60d9c4e4f3b4b544b8b8d1c5", "name": "Tennis Court", "description": "Outdoor tennis court with synthetic surface.", "pricePerHour": 30, "location": "456 Sports Ave, Springfield", "isDeleted": false } ] }
- Route:
-
Check Availability
- Route:
GET /api/check-availability
- Query Parameters:
date
(optional): The date for which availability is to be checked. Format:YYYY-MM-DD
. If not provided, today's date will be used by default.
- Response:
{ "success": true, "statusCode": 200, "message": "Availability checked successfully", "data": [ { "startTime": "08:00", "endTime": "10:00" }, { "startTime": "14:00", "endTime": "16:00" } ] }
- Route:
-
Create a Booking (User Only)
- Route:
POST /api/bookings
- Headers:
Authorization: Bearer JWT_TOKEN
- Request Body:
{ "facility": "60d9c4e4f3b4b544b8b8d1c5", "date": "2024-06-15", "startTime": "10:00", "endTime": "13:00" }
- Response:
{ "success": true, "statusCode": 200, "message": "Booking
- Route: