diff --git a/backend/controllers/WheelchairController.js b/backend/controllers/WheelchairController.js new file mode 100644 index 0000000..7f534a2 --- /dev/null +++ b/backend/controllers/WheelchairController.js @@ -0,0 +1,32 @@ +import WheelchairBooking from "../models/WheelChairBooking.js"; + +export const createWheelchairBooking = async (req, res) => { + const { station, bookingDate, bookingTime, wheelchairType } = req.body; + + if (!station || !bookingDate || !bookingTime) { + return res + .status(400) + .json({ + message: + "Please provide all required fields: station, bookingDate, bookingTime", + }); + } + + try { + const newBooking = new WheelchairBooking({ + station, + bookingDate: new Date(bookingDate), + bookingTime, + wheelchairType: wheelchairType || "manual", + }); + + const savedBooking = await newBooking.save(); + + res.status(201).json(savedBooking); + } catch (error) { + console.error("Error creating wheelchair booking:", error); + res + .status(500) + .json({ message: "Server error. Could not create wheelchair booking." }); + } +}; diff --git a/backend/controllers/cloakroomController.js b/backend/controllers/cloakroomController.js new file mode 100644 index 0000000..473b98a --- /dev/null +++ b/backend/controllers/cloakroomController.js @@ -0,0 +1,31 @@ +import CloakroomBooking from "../models/CloakroomBooking.js"; + +export const createCloakroomBooking = async (req, res) => { + const { station, items, storageStartDate, storageEndDate, charges } = + req.body; + + if (!station || !items || !storageStartDate || !storageEndDate || !charges) { + return res + .status(400) + .json({ message: "Please provide all required fields" }); + } + + try { + const newBooking = new CloakroomBooking({ + station, + items, + storageStartDate: new Date(storageStartDate), + storageEndDate: new Date(storageEndDate), + charges, + }); + + const savedBooking = await newBooking.save(); + + res.status(201).json(savedBooking); + } catch (error) { + console.error("Error creating cloakroom booking:", error); + res + .status(500) + .json({ message: "Server error. Could not create booking." }); + } +}; diff --git a/backend/controllers/coolieController.js b/backend/controllers/coolieController.js new file mode 100644 index 0000000..59442ef --- /dev/null +++ b/backend/controllers/coolieController.js @@ -0,0 +1,48 @@ +import CoolieBooking from "../models/CoolieBooking.js"; + +export const createCoolieBooking = async (req, res) => { + try { + const { + station, + pickupLocation, + departureLocation, + bookingDate, + bookingTime, + price, + } = req.body; + + if ( + !station || + !pickupLocation || + !departureLocation || + !bookingDate || + !bookingTime || + !price + ) { + return res + .status(400) + .json({ message: "Please fill all the required fields." }); + } + + const coolieBooking = new CoolieBooking({ + station, + pickupLocation, + departureLocation, + bookingDate, + bookingTime, + price, + }); + + const savedBooking = await coolieBooking.save(); + + res.status(201).json({ + message: "Coolie booking created successfully.", + data: savedBooking, + }); + } catch (error) { + console.error("Error creating coolie booking:", error); + res + .status(500) + .json({ message: "An error occurred while creating the booking." }); + } +}; diff --git a/backend/index.js b/backend/index.js index 7ab24be..25374be 100644 --- a/backend/index.js +++ b/backend/index.js @@ -23,7 +23,9 @@ connectDB(); // Routes import authRoutes from './routes/authRoutes.js'; + app.use('/auth', authRoutes); +app.use('/api', authRoutes); app.get('/', (req, res) => { res.send('Working...'); diff --git a/backend/models/CloakroomBooking.js b/backend/models/CloakroomBooking.js new file mode 100644 index 0000000..8199e85 --- /dev/null +++ b/backend/models/CloakroomBooking.js @@ -0,0 +1,36 @@ +import mongoose from "mongoose"; + +const Schema = mongoose.Schema; + +const cloakroomBookingSchema = new Schema( + { + station: { + type: String, + required: true, + trim: true, + }, + items: { + type: String, + required: true, + trim: true, + }, + storageStartDate: { + type: Date, + required: true, + }, + storageEndDate: { + type: Date, + required: true, + }, + charges: { + type: Number, + required: true, + }, + }, + { + timestamps: true, + } +); + +const CloakroomBooking = mongoose.model('CloakroomBooking', cloakroomBookingSchema); +export default CloakroomBooking; diff --git a/backend/models/CoolieBooking.js b/backend/models/CoolieBooking.js new file mode 100644 index 0000000..2092ccc --- /dev/null +++ b/backend/models/CoolieBooking.js @@ -0,0 +1,43 @@ +import mongoose from "mongoose"; + +const Schema = mongoose.Schema; + +const coolieBookingSchema = new Schema( + { + station: { + type: String, + required: true, + trim: true, + }, + pickupLocation: { + type: String, + required: true, + trim: true, + }, + departureLocation: { + type: String, + required: true, + trim: true, + }, + bookingDate: { + type: Date, + required: true, + }, + bookingTime: { + type: String, + required: true, + }, + price: { + type: Number, + required: true, + min: 0, + }, + }, + { + timestamps: true, + } +); + +const CoolieBooking = mongoose.model("CoolieBooking", coolieBookingSchema); + +export default CoolieBooking; diff --git a/backend/models/WheelchairBooking.js b/backend/models/WheelchairBooking.js new file mode 100644 index 0000000..b1d8a06 --- /dev/null +++ b/backend/models/WheelchairBooking.js @@ -0,0 +1,30 @@ +import mongoose from 'mongoose'; + +const Schema = mongoose.Schema; + +const wheelchairBookingSchema = new Schema({ + station: { + type: String, + required: true, + trim: true + }, + bookingDate: { + type: Date, + required: true + }, + bookingTime: { + type: String, + required: true + }, + wheelchairType: { + type: String, + enum: ['manual', 'electric', 'standard'], + default: 'manual' + }, +}, { + timestamps: true +}); + +const WheelchairBooking = mongoose.model('WheelchairBooking', wheelchairBookingSchema); + +export default WheelchairBooking; diff --git a/backend/routes/authRoutes.js b/backend/routes/authRoutes.js index f944c6c..b20713a 100644 --- a/backend/routes/authRoutes.js +++ b/backend/routes/authRoutes.js @@ -1,5 +1,8 @@ import express from 'express'; import { registerUser, loginUser, logoutUser, verifyUser } from '../controllers/authController.js'; +import { createCloakroomBooking } from '../controllers/cloakroomController.js'; +import { createWheelchairBooking } from '../controllers/WheelchairController.js'; +import { createCoolieBooking } from '../controllers/coolieController.js'; const router = express.Router(); @@ -15,4 +18,15 @@ router.post('/logout', logoutUser); // Verify route router.get('/verify', verifyUser); +//cloakroom bookings route +router.post('/bookCloakroom', createCloakroomBooking); + +//wheelchair bookings route +router.post('/bookWheelchair', createWheelchairBooking); + +//coolie bookings route +router.post('/bookCoolie', createCoolieBooking); + + + export default router; \ No newline at end of file