Back-End Web Development (BED) CA1 Assignment Developed endpoints in the back-end side for a flight booking website
- Open the zip and open the extracted folder in Visual Studio Code
- Open the db_init.sql file, paste it on the query and run it on the Workbench by clicking on the lightning icon
- If you cannot open the file, open the SQL file in a text editor and copy and paste the contents on the query
- On the databaseConfig.js file located in the model folder, change the password to your own password that you usually use in the Workbench
- On the terminal, run “nodemon" or "node server.js" if the first command does not work and you do not have nodemon installed
- Test all of the endpoints on POSTMAN based on the documentations below
- Install all the required node packages using “npm install”
- Refer to README.md for more details about the code
- Body Parser
- Express
- Multer
- MySQL
- Nodemon
Refer to the package.json file to view all the dependencies
- Controller
- App.js
- Model
- airport.js
- booking.js
- databaseConfig.js
- flight.js
- promotion.js
- user.js
- Uploads (Uploaded images from POSTMAN)
- Package-lock.json
- Package.json
- README.md
- Server.js
Database name: sp_air
-
user - stores user information
- user id
- username
- contact number
- password
- role
- profile picture
- created_at
-
flight - stores flight information
- flight id
- flight code
- aircraft type
- origin airport
- destination airport
- embark date
- travel time
- price
- product listing image
- created_at
-
airport - stores airport name and country
- airport id
- name of airport
- country of airport
- description of airport
-
bookings - stores booking made by a user
- booking id
- name
- passport
- nationality
- age
- booked_at
-
promotion - store promotion period dates and discounts
- promotion id
- flight id
- startDate
- endDate
- discount
- airport.airportid = flight.originAirport and flight.destinationAirport
- flight.flightid = booking.flightid
- user.userid = booking.userid
- user.username = booking.name
- flight.flightid = promotion.flightid
- Endpoint 1 - POST /users/ - Create a new user
- Endpoint 2 - GET /users/ - Get all users from the user database
- Endpoint 3 - GET /users/:id - Get user by their id
- Endpoint 4 - PUT /users/:id - Update a user by their id
- Endpoint 5 - POST /airport - Add a new airport
- Endpoint 6 - GET /airport - Get all airports from the airport database
- Endpoint 7 - POST /flight - Update airport information
- Endpoint 8 - GET /flightDirect/:originAirportId/:destinationAirportId - Get flights travelling from origin airport to destination airport
- Endpoint 9 - POST /booking/:userid/:flightid - Add a new booking to the booking database
- Endpoint 10 - DELETE /flight/:id/ - Delete a flight by its id
- Endpoint 11 - GET /transfer/flight/:originAirportId/:destinationAirportId - Get transfer flights to destination
-
Implementation of Multer in app.js to support uploading of image files into form-data in POSTMAN
- File size limited to 1MB, otherwise error will be outputted
- Only JPG and PNG files are accepted, using fileFilter function in Multer object and comparing with file mimetype
- Feature is only available for user and flight endpoints
- Uploaded files can be found under the uploads folder
-
Endpoints related to promotional discounts for certain periods
- Retrieves flightid and cross references promotion table to check if promotion exists for the flight
- Checks if promotion applicable for flight by checking if booking date within promotion period, if not no discount
- Applies discount if there is promotion for flight within promotion period
- Endpoint 12 - POST /promotions/:flightid - Create a new promotion
- Endpoint 13 - GET /promotions - Get all promotions
- Endpoint 14 - GET /promotions/:promotionid - Get promotion by promotionid
- Endpoint 15 - DELETE /promotion/:promotionid - Delete a promotion by promotionid
-
Checkout Feature
- Endpoint 16 - GET /checkout/:bookingid
- Check if booking exists to be checked out
- Gives user option to select flight class in their booked flight (Economy, Business, First)
- Standard price for flights is for Economy Class
- Business Class tickets cost 50% more than Economy Class tickets
- First Class tickets cost 100% more than Economy Class tickets
- Users can indicate quantity of tickets (must be for the same class)
- Final price will be calculated, taking into account discounts, class and quantity
- Checkout information will be displayed and resets every time a new checkout is made
-
Searching for flights based on airline
- Endpoint 17 - GET /searchAirline?query=
- Shows all the flights offered by the airline (all origin and destination cities)
-
Searching for flights between certain ranges user specifies
- Endpoint 18 - GET /flights/price?min=&max=
- Minimum and maximum range to be specified by the user in the body