This system is designed to manage gym operations efficiently. It allows for class scheduling, trainer management, and trainee bookings. The system defines three roles: Admin, Trainer, and Trainee, each with specific permissions.
- Backend: Node.js with Express.js
- Language: TypeScript
- Database: MongoDB
- ORM: Mongoose
- Authentication: JSON Web Tokens (JWT)
- Validation: Zod
- POST /api/auth/register - Register a new user (trainer or trainee)
- POST /api/auth/login - User login
- GET /api/trainer/all - Get all trainers
- GET /api/trainer/:id - Get a specific trainer
- POST /api/trainer - Create a new trainer (Admin only)
- PUT /api/trainer/:id - Update a trainer (Admin only)
- DELETE /api/trainer/:id - Delete a trainer (Admin only)
- GET /api/trainee/profile - Get the logged-in trainee's profile
- PATCH /api/trainee/update-profile - Update the logged-in trainee's profile
- GET /api/schedule/all - Get all schedules (Admin and Trainer only)
- GET /api/schedule/:id - Get a specific schedule (Admin only)
- POST /api/schedule - Create a new schedule (Admin only)
- PUT /api/schedule/:id - Update a schedule (Admin only)
- DELETE /api/schedules/:id - Delete a schedule (Admin only)
- GET /api/booking/trainee - Get all bookings for the logged-in trainee
- POST /api/booking - Create a new booking (Trainee only)
- DELETE /api/booking/cancel/:id - Cancel a booking (Trainee only)
{
name: string;
email: string;
password: string;
role: "admin" | "trainer" | "trainee";
}{
userId: Types.ObjectId;
name: string;
specialization: string;
experience: number;
}{
trainer: Types.ObjectId;
date: Date;
startTime: string;
endTime: string;
capacity: number;
bookedTrainees: Types.ObjectId[];
}{
traineeId: Types.ObjectId;
scheduleId: Types.ObjectId;
status: "confirmed" | "cancelled";
}- Email: [email protected]
- Password: admin123
- Email: [email protected]
- Password: trainer123
- Email: [email protected]
- Password: trainee123
Trainee's email will increase by one repectively for further check while password will be same..
-
Clone the repository:
git clone https://github.com/labibahmed10/gym-management-be.git cd gym-management-be -
Install dependencies:
npm install -
Set up environment variables: Create a
.envfile in the root directory and add the following:NODE_ENV=development PORT=5000 DATABASE_URL=your_mongodb_connection_string BCRYPT_SALT_ROUND=number JWT_ACCESS_SECRET=your_jwt_access_secret ACCESS_TOKEN_EXPIRES_IN=your_access_token_expires_in -
Run the development server:
npm run dev -
The server should now be running on
http://localhost:5000
https://gym-management-be-xi.vercel.app
Use these credentials to log in as an admin:
- Email: [email protected]
- Password: admin123
- Log in as an admin using the credentials provided above.
- Send a POST request to
/api/trainerwith the following body:{ "userId": "<user_id>", "name": "John Doe", "specialization": "Yoga", "experience": 5 } - You should receive a 201 status code with the created trainer details.
- Ensure you're logged in as an admin.
- Send a POST request to
/api/scheduleswith the following body:Replace{ "trainer": "<trainer_id>", "date": "2023-06-01", "startTime": "10:00", "endTime": "12:00" }<trainer_id>with an actual trainer ID from your database. - You should receive a 201 status code with the created schedule details.
- Register a new trainee account or use an existing one.
- Log in as the trainee.
- Send a POST request to
/api/bookingswith the following body:Replace{ "scheduleId": "<schedule_id>", "traineeId": "<trainee_id>", "bookingDate": "date" }<schedule_id>with an actual schedule ID from your database. - You should receive a 201 status code with the booking details.
- Ensure you're logged in as a trainee with an existing booking.
- Send a DELETE request to
/api/booking/cancel/<booking_id>. - You should receive a 200 status code with the updated booking status.
- Log in as a trainer.
- Send a GET request to
/api/schedule/all. - You should receive a 200 status code with a list of schedules assigned to the trainer.
- Log in as a trainee.
- Send a GET request to
/api/booking/trainee. - You should receive a 200 status code with a list of all bookings for the specified schedule.
- Replace placeholder IDs (like
<trainer_id>,<schedule_id>,<booking_id>) with actual IDs from your database. - Ensure you're using the correct authentication token for each request. The token should be included in the Authorization header as a Bearer token.
- Pay attention to the response status codes and error messages for proper error handling.
- Test edge cases, such as:
- Trying to book a full class
- Attempting to create more than 5 schedules per day
- Booking conflicting time slots
- Accessing routes without proper authorization
For a more comprehensive testing experience, consider using API testing tools like Postman or Insomnia. These tools allow you to save and organize your API requests, making it easier to test your application thoroughly.
