Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cloakroom and wheelchair booking backend routes #107

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions backend/controllers/WheelchairController.js
Original file line number Diff line number Diff line change
@@ -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." });
}
};
31 changes: 31 additions & 0 deletions backend/controllers/cloakroomController.js
Original file line number Diff line number Diff line change
@@ -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." });
}
};
48 changes: 48 additions & 0 deletions backend/controllers/coolieController.js
Original file line number Diff line number Diff line change
@@ -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." });
}
};
2 changes: 2 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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...');
Expand Down
36 changes: 36 additions & 0 deletions backend/models/CloakroomBooking.js
Original file line number Diff line number Diff line change
@@ -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;
43 changes: 43 additions & 0 deletions backend/models/CoolieBooking.js
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions backend/models/WheelchairBooking.js
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions backend/routes/authRoutes.js
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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;
Loading