forked from dhairyagothi/StationGuide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
127,388 additions
and
795 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import stations from "../dataset/stations.js" | ||
|
||
|
||
//sending the data to frontend | ||
|
||
export const sendStations = async (req,res) =>{ | ||
|
||
// console.log() | ||
try{ | ||
res.json(stations); | ||
}catch(err){ | ||
console.log("Error : ",err) | ||
} | ||
} |
Oops, something went wrong.