-
Notifications
You must be signed in to change notification settings - Fork 119
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 #228 from haseebzaki-07/new_branch_4
Added station services
- Loading branch information
Showing
13 changed files
with
361 additions
and
114 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,47 @@ | ||
import Station from "../models/Stations.js"; | ||
|
||
export const createStation = async (req, res) => { | ||
try { | ||
const { name, location, stationCode, capacity, services } = req.body; | ||
|
||
const newStation = new Station({ | ||
name, | ||
location, | ||
stationCode, | ||
capacity, | ||
services, | ||
}); | ||
|
||
const savedStation = await newStation.save(); | ||
|
||
res.status(201).json({ | ||
message: "Station created successfully", | ||
station: savedStation, | ||
}); | ||
} catch (error) { | ||
console.error("Error creating station:", error); | ||
res.status(500).json({ | ||
message: "Failed to create station", | ||
error: error.message, | ||
}); | ||
} | ||
}; | ||
|
||
export const getAllStations = async (req, res) => { | ||
try { | ||
const stations = await Station.find() | ||
.populate("coolies", "name") | ||
.populate("wheelchairs", "name") | ||
.populate("cloakrooms", "name"); | ||
|
||
if (!stations || stations.length === 0) { | ||
return res.status(404).json({ message: "No stations found" }); | ||
} | ||
|
||
return res.status(200).json(stations); | ||
} catch (error) { | ||
return res | ||
.status(500) | ||
.json({ message: "Server error", error: error.message }); | ||
} | ||
}; |
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,74 @@ | ||
import Station from "../models/Stations.js"; | ||
import CoolieBooking from "../models/CoolieBooking.js"; | ||
import WheelchairBooking from "../models/WheelchairBooking.js"; | ||
import CloakroomBooking from "../models/CloakroomBooking.js"; | ||
|
||
export const getStationBookings = async (req, res) => { | ||
try { | ||
const stationId = req.params.id; | ||
|
||
const station = await Station.findById(stationId); | ||
if (!station) { | ||
return res.status(404).json({ message: "Station not found" }); | ||
} | ||
|
||
const coolieBookings = await CoolieBooking.find({ station: stationId }); | ||
const wheelchairBookings = await WheelchairBooking.find({ | ||
station: stationId, | ||
}); | ||
const cloakroomBookings = await CloakroomBooking.find({ | ||
station: stationId, | ||
}); | ||
|
||
const response = { | ||
station: station, | ||
coolieBookings: coolieBookings, | ||
wheelchairBookings: wheelchairBookings, | ||
cloakroomBookings: cloakroomBookings, | ||
}; | ||
|
||
return res.status(200).json(response); | ||
} catch (error) { | ||
return res.status(500).json({ message: error.message }); | ||
} | ||
}; | ||
|
||
export const getCoolieBookingsByStation = async (req, res) => { | ||
try { | ||
const stationId = req.params.id; | ||
|
||
const coolieBookings = await CoolieBooking.find({ station: stationId }); | ||
|
||
return res.status(200).json(coolieBookings); | ||
} catch (error) { | ||
return res.status(500).json({ message: error.message }); | ||
} | ||
}; | ||
|
||
export const getWheelchairBookingsByStation = async (req, res) => { | ||
try { | ||
const stationId = req.params.id; | ||
|
||
const wheelchairBookings = await WheelchairBooking.find({ | ||
station: stationId, | ||
}); | ||
|
||
return res.status(200).json(wheelchairBookings); | ||
} catch (error) { | ||
return res.status(500).json({ message: error.message }); | ||
} | ||
}; | ||
|
||
export const getCloakroomBookingsByStation = async (req, res) => { | ||
try { | ||
const stationId = req.params.id; | ||
|
||
const cloakroomBookings = await CloakroomBooking.find({ | ||
station: stationId, | ||
}); | ||
|
||
return res.status(200).json(cloakroomBookings); | ||
} catch (error) { | ||
return res.status(500).json({ message: error.message }); | ||
} | ||
}; |
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
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
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 |
---|---|---|
@@ -1,30 +1,30 @@ | ||
// wheelchairBooking.js | ||
import mongoose from 'mongoose'; | ||
|
||
const Schema = mongoose.Schema; | ||
|
||
const wheelchairBookingSchema = new Schema({ | ||
station: { | ||
type: String, | ||
type: Schema.Types.ObjectId, | ||
ref: 'Station', | ||
required: true, | ||
trim: true | ||
}, | ||
bookingDate: { | ||
type: Date, | ||
required: true | ||
required: true, | ||
}, | ||
bookingTime: { | ||
type: String, | ||
required: true | ||
required: true, | ||
}, | ||
wheelchairType: { | ||
type: String, | ||
enum: ['manual', 'electric', 'standard'], | ||
default: 'manual' | ||
default: 'manual', | ||
}, | ||
}, { | ||
timestamps: true | ||
timestamps: true, | ||
}); | ||
|
||
const WheelchairBooking = mongoose.model('WheelchairBooking', wheelchairBookingSchema); | ||
|
||
const WheelchairBooking = mongoose.models.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// routes.js | ||
import express from 'express'; | ||
import { getCloakroomBookingsByStation, getCoolieBookingsByStation, getStationBookings, getWheelchairBookingsByStation } from '../controllers/stationBookingsController.js'; | ||
import { createStation, getAllStations } from '../controllers/StationController.js'; | ||
|
||
const router = express.Router(); | ||
|
||
// Route to fetch all bookings for a station | ||
router.get('/:id/bookings', getStationBookings); | ||
router.get('/', getAllStations) | ||
router.post('/', createStation); | ||
|
||
|
||
// Routes to fetch specific types of bookings by station ID | ||
router.get('/:id/coolies', getCoolieBookingsByStation); | ||
router.get('/:id/wheelchairs', getWheelchairBookingsByStation); | ||
router.get('/:id/cloakrooms', getCloakroomBookingsByStation); | ||
|
||
export default router; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.