This is a Node.js application for managing a train system. It provides functionalities for user authentication, signing up, logging in, adding trains, checking seat availability, booking seats, and fetching booking details.
- Node.js installed on your machine
- MySQL server running locally
-
Clone the repository to your local machine:
-
Navigate to the project directory:
-
Install dependencies:
npm install
-
Set up your MySQL database:
- Run the MySQL server.
- Execute the provided SQL commands in your MySQL database to create the necessary tables. You can find the SQL commands in the comments at the end of
app.js
file.
-
Configure the MySQL connection:
- Open
app.js
file. - Update the MySQL connection parameters (host, user, password, database) according to your MySQL setup.
- Open
-
Start the server:
npm start
-
The server will start running on port 3000 by default.
-
You can access the endpoints using a tool like Postman or by sending HTTP requests programmatically.
- GET /: Welcome message indicating the successful running of the server.
- POST /signup: Endpoint for user signup. Requires
username
,password
, andisAdmin
(boolean) fields in the request body. - POST /login: Endpoint for user login. Requires
username
andpassword
fields in the request body. - POST /trains: Endpoint for adding a new train. Requires
source
,destination
, anduserId
fields in the request body. - GET /trains: Endpoint for retrieving available trains based on
source
anddestination
query parameters. - POST /book: Endpoint for booking a seat on a train. Requires
userId
andtrainId
fields in the request body. - GET /bookings/:userId: Endpoint for fetching booking details for a specific user identified by
userId
parameter.
- authenticateUser: Middleware function to ensure user authentication for protected routes. It checks if a valid
userId
is present in the request body.
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request.
Tests are not included in this version of the application. However, you can write your own tests using testing frameworks like Mocha and Chai. Feel free to contribute tests if you find it necessary.
This project is licensed under the MIT License - see the LICENSE file for details.