Files
Sven laptop 7d55580d87 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.
2026-09-24 20:18:32 +02:00

36 lines
1.1 KiB
JavaScript

const { DEV_MOCK } = require("../lib/env");
// The repository layer merges every domain's PostgreSQL implementation with the
// mock implementations. In DEV_MOCK mode the mock methods (which read the
// in-memory `mock/store`) shadow the DB-backed ones; endpoints that have no
// mock branch always use the PostgreSQL implementation, exactly as the original
// handlers did.
//
// Every method takes the Express `req` (the original handlers read params,
// query, body and user from it) and returns `{ statusCode, body }`. Route
// handlers only transform that into `res.status(...).json(...)`.
const pg = {
...require("./stops"),
...require("./lines"),
...require("./fleet"),
...require("./drivers"),
...require("./daily"),
...require("./weekly"),
...require("./adminSchedules"),
...require("./schedules"),
...require("./route"),
...require("./navigation"),
...require("./gps"),
};
const mock = {
...require("./stops.mock"),
...require("./lines.mock"),
...require("./fleet.mock"),
...require("./drivers.mock"),
...require("./adminSchedules.mock"),
...require("./schedules.mock"),
};
module.exports = DEV_MOCK ? { ...pg, ...mock } : pg;