64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
import express from "express";
|
|
import * as dal from "../dal/staticDal.js";
|
|
|
|
const router = express.Router();
|
|
|
|
router.get("/routes", (req, res) => {
|
|
const routes = dal.getRoutes();
|
|
|
|
res.json({meta: {returned: routes.length}, data: routes});
|
|
});
|
|
|
|
router.get("/routes/: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("/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);
|
|
|
|
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();
|
|
|
|
res.json({meta: {returned: stations.length}, data: stations});
|
|
});
|
|
|
|
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"});
|
|
res.json({data: station});
|
|
});
|
|
|
|
export default router;
|