Refactor transit_api into a repo/routes module split
Split the 5,441-line index.js into an 86-line bootstrap, thin domain
route modules, shared lib/ helpers, and a repo/ layer that isolates the
DEV_MOCK branches (repo/*.mock.js). Repo methods return {statusCode, body};
routes are one-line wrappers. Pin search_path to "transit.bus" and
document the /bus/ prefix with legacy root aliases (Deprecation header).
Parity verified: 57/57 byte-identical on the stub differential harness
plus 24/24 live read-only responses vs the original against real
PostgreSQL. The only intentional behavior change: mock reorder/delete
bus-line endpoints no longer require a live DB (previously 500 in
DEV_MOCK=1 without PG). DEV_MOCK gate and node --check clean.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const { authMiddleware } = require("../middleware");
|
||||
const repo = require("../repo");
|
||||
|
||||
router.patch(
|
||||
"/driver/schedules/:scheduleId/status",
|
||||
authMiddleware,
|
||||
async (req, res) => {
|
||||
const out = await repo.updateDriverScheduleStatus(req);
|
||||
return res.status(out.statusCode).json(out.body);
|
||||
},
|
||||
);
|
||||
|
||||
router.get("/schedules", async (req, res) => {
|
||||
const out = await repo.listSchedules(req);
|
||||
return res.status(out.statusCode).json(out.body);
|
||||
});
|
||||
|
||||
router.get("/schedules/overview", async (req, res) => {
|
||||
const out = await repo.getSchedulesOverview(req);
|
||||
return res.status(out.statusCode).json(out.body);
|
||||
});
|
||||
|
||||
router.get("/schedules/recurring", async (req, res) => {
|
||||
const out = await repo.listRecurringSchedules(req);
|
||||
return res.status(out.statusCode).json(out.body);
|
||||
});
|
||||
|
||||
router.get("/schedules/:scheduleId", async (req, res) => {
|
||||
const out = await repo.getScheduleById(req);
|
||||
return res.status(out.statusCode).json(out.body);
|
||||
});
|
||||
|
||||
router.get("/schedules/:scheduleId/stops", async (req, res) => {
|
||||
const out = await repo.getScheduleStops(req);
|
||||
return res.status(out.statusCode).json(out.body);
|
||||
});
|
||||
|
||||
router.post(
|
||||
"/driver/schedules/:scheduleId/stops/:stopOrder/passed",
|
||||
authMiddleware,
|
||||
async (req, res) => {
|
||||
const out = await repo.markStopPassed(req);
|
||||
return res.status(out.statusCode).json(out.body);
|
||||
},
|
||||
);
|
||||
|
||||
router.get("/public/schedules/:scheduleId/progress", async (req, res) => {
|
||||
const out = await repo.getPublicScheduleProgress(req);
|
||||
return res.status(out.statusCode).json(out.body);
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user