The Sports Facility Booking Platform allows users to book sports facilities with ease and provides admins the ability to manage these facilities and bookings.
https://sports-booking-platform.vercel.app
- TypeScript
- Node.js
- Express.js
- Mongoose
- JWT
- Zod
-
User Authentication and Authorization: Users can sign up and log in using their email and password. Admins have additional powers for managing facilities and bookings.
-
Facility Management: Admins can create, update, and delete facilities. Each facility has details like name, description, price per hour, and location.
-
Booking System: Users can book facilities by specifying the date, start time, and end time. The system calculates the payable amount based on the duration of the booking.
-
Availability Checking: Users can check the availability of facilities for a specific date.
-
View Bookings: Admins can view all bookings, while users can view only their own bookings. This helps in managing and tracking reservations efficiently.
-
Booking Cancellation: Users have the ability to cancel their bookings.
-
Error Handling: Comprehensive error handling ensures proper responses and messages for validation errors, duplicate entries, and not found routes.
-
Authentication Middleware: Middleware is implemented to protect routes, ensuring that only authenticated users and admins can access their respective routes.
-
Security: WT based authentication is implemented to protect routes and ensure that only authorized users and admins can access their respective routes.
git clone https://github.com/Rahad-Ullah/Sports-Facility-Booking-server.git
npm install
- Create a
.env
file in the root directory. - Add the following environment variables:
PORT=5000
DATABASE_URL=your_database_url
BCRYPT_SALT_ROUNDS=any_integer_number
JWT_ACCESS_SECRET=your_jwt_secret
JWT_REFRESH_SECRET=your_jwt_secret
JWT_ACCESS_EXPIRES_IN=1d
JWT_REFRESH_EXPIRES_IN=365d
npm run start:dev
- Endpoint:
POST /api/auth/signup
- Request Body:
{
"name": "Rahad Ullah",
"email": "rahadullah@gmail.com",
"password": "password123",
"phone": "1234567890",
"role": "user",
"address": "123 Savar, Dhaka"
}
- Endpoint:
POST /api/auth/login
- Request Body:
{
"email": "rahadullah@email.com",
"password": "password123"
}
- Endpoint:
POST /api/facility
- Headers:
Authorization: Bearer YOUR_JWT_TOKEN
- Request Body:
{
"name": "Football Gallery",
"description": "Outdoor football gallery with synthetic surface.",
"pricePerHour": 100,
"location": "53 National Stadium"
}
- Endpoint:
PUT /api/facility/:id
- Headers:
Authorization: Bearer YOUR_JWT_TOKEN
- Request Body:
{
"name": "Update Football Gallery",
"description": "Outdoor football gallery with synthetic surface.",
"pricePerHour": 120,
"location": "53 National Stadium"
}
- Endpoint:
DELETE /api/facility/:id
- Headers:
Authorization: Bearer YOUR_JWT_TOKEN
- Endpoint:
GET /api/facility
- Endpoint:
GET /api/check-availability
- Query Parameters:
date=2024-07-09
- Endpoint:
POST /api/bookings
- Headers:
Authorization: Bearer YOUR_JWT_TOKEN
- Request Body:
{
"facility": "60d9c4e4f3b4b544b8b8d1c5",
"date": "2024-07-09",
"startTime": "12:00",
"endTime": "15:00"
}
Note: The startTime and endTime should be in HH:MM
with 24 hours format and date should be in YYYY-MM-DD
format.
- Endpoint:
GET /api/bookings
- Headers:
Authorization: Bearer YOUR_JWT_TOKEN
- Endpoint:
GET /api/bookings/user
- Headers:
Authorization: Bearer YOUR_JWT_TOKEN
- Endpoint:
DELETE /api/bookings/:id
- Headers:
Authorization: Bearer YOUR_JWT_TOKEN
The application handles errors such as validation errors, duplicate entries, and not found routes with appropriate error messages and status codes.
JWT based authentication is implemented to protect routes and ensure that only authorized users and admins can access their respective routes. By following these steps and using the endpoints provided, you can efficiently manage users, facilities, and bookings in the sports facility booking platform.