Updated routes
Some checks failed
Deploy Express API / deploy (push) Has been cancelled

This commit is contained in:
Edward-1100
2025-11-24 18:32:45 -07:00
parent 7cb29179a2
commit eaf76f94a1
2 changed files with 120 additions and 63 deletions

View File

@@ -11,32 +11,43 @@ router.get("/routes", (req, res) => {
router.get("/routes/:routeId", (req, res) => {
const routeId = req.params.routeId;
let route = dal.getRouteById(routeId) ?? null;
const route = dal.getRouteById(routeId);
if (route === null) {
const all = dal.getRoutes();
route = all.find(r => {
const rid = r.route_id ?? r.routeId ?? r.route;
return rid != null && String(rid) === String(routeId);
}) ?? null;
}
if (!route) return res.status(404).json({error: "Route Was Not Found"});
const routePath = dal.getRoutePath(routeId);
const stations = dal.getStopsByRoute(routeId);
res.json({data: {route, routePath, stations}});
});
const routePath = dal.getRoutePath(routeId) ?? null;
let stations = dal.getStopsByRoute(routeId) ?? [];
router.get("/route/:routeId", (req, res) => {
const routeId = req.params.routeId;
const route = dal.getRouteById(routeId);
if (!route) return res.status(404).json({error: "Route Was Not Found"});
const routePath = dal.getRoutePath(routeId);
const stations = dal.getStopsByRoute(routeId);
res.json({data: {route, routePath, stations}});
});
router.get("/routes/:routeId/stations", (req, res) => {
const routeId = req.params.routeId;
const stations = dal.getStopsByRoute(routeId) ?? [];
const stations = dal.getStopsByRoute(routeId);
res.json({meta: {routeId: String(routeId), returned: stations.length}, data: stations});
});
router.get("/stops/:routeId", (req, res) => {
const routeId = req.params.routeId;
const stations = dal.getStopsByRoute(routeId);
res.json({meta: {routeId: String(routeId), returned: stations.length}, data: stations});
});
router.get("/stations", (req, res) => {
const route = req.query.route;
const stations = route ? (dal.getStopsByRoute(route) ?? []) : (dal.getStations() ?? []);
const stations = route ? dal.getStopsByRoute(route) : dal.getStations();
res.json({meta: {returned: stations.length}, data: stations});
});
@@ -44,8 +55,8 @@ router.get("/stations", (req, res) => {
router.get("/station/:stationId", (req, res) => {
const stationId = req.params.stationId;
const station = dal.getStationById(stationId);
if (!station) return res.status(404).json({error: "Station Was Not Found"});
if (!station) return res.status(404).json({error: "Station Was Not Found"});
res.json({data: station});
});