-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from haseebzaki-07/new_branch
Added cloakroom and wheelchair booking backend routes
- Loading branch information
Showing
8 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters