This is a Node.js + Express + MongoDB backend for Assignment 2, implementing two core booking endpoints.
- Clone the repo or copy files
- Install dependencies:
npm install - Set up your
.envfile:MONGODB_URI=mongodb://localhost:27017/assignment2 JWT_SECRET=your_jwt_secret_here PORT=5000 - Start MongoDB locally (or use MongoDB Atlas)
- Run the server:
or
npm run devnpm start
- Purpose: Register a new user
- Body:
{ "email": "[email protected]", "password": "Test123!@#", "firstName": "John", "lastName": "Doe", "role": "user" } - Success Response:
{ "message": "User registered successfully", "token": "<jwt_token>", "user": { "id": "<user_id>", "email": "[email protected]", "firstName": "John", "lastName": "Doe", "role": "user" } }
- Purpose: Login user
- Body:
{ "email": "[email protected]", "password": "Test123!@#" } - Success Response:
{ "message": "Login successful", "token": "<jwt_token>", "user": { "id": "<user_id>", "email": "[email protected]", "firstName": "John", "lastName": "Doe", "role": "user" } }
- Purpose: Book a seat for an event
- Headers:
Authorization: Bearer <jwt_token> - Body:
{ "eventId": "<event_id>", "userId": "<user_id>", "seatNumber": "B14", "paymentId": "pay_123456" } - Success Response:
{ "message": "Booking confirmed", "bookingId": "<booking_id>", "qrCode": "<base64-string>" }
- Purpose: Get all bookings for a user
- Headers:
Authorization: Bearer <jwt_token> - Success Response:
[ { "bookingId": "<booking_id>", "eventName": "ReactJS Conference", "seat": "B14", "eventDate": "2025-07-28", "qrCode": "<base64-string>" } ]
- JWT-based authentication
- Token expiration (24 hours)
- Password hashing with bcrypt
- Role-based access control (user, organizer, admin)
- Users can only access their own bookings
- Middleware validation for all endpoints
- Email format validation
- Password strength validation (min 8 chars, 1 number, 1 special)
- Name sanitization
- MongoDB ObjectID validation
- Required field validation
- Make sure to create some Event documents in your database for testing.
- You can use Postman to test the endpoints.
- For deployment, use Render, Heroku, or AWS as required by your assignment.