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,34 @@
|
||||
const { store } = require("../mock/store");
|
||||
const { checkDriverConflict } = require("../lib/schedule");
|
||||
const { reportError } = require("../lib/report-error");
|
||||
|
||||
// Driver repository methods (DEV_MOCK mode).
|
||||
|
||||
async function listDrivers(req) {
|
||||
try {
|
||||
const drivers = store.drivers
|
||||
.slice()
|
||||
.filter((d) => d.status === "active");
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
drivers: drivers.map((d) => ({
|
||||
...d,
|
||||
available: !checkDriverConflict(
|
||||
d.id,
|
||||
new Date().toISOString(),
|
||||
new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
|
||||
[],
|
||||
store.schedules || [],
|
||||
),
|
||||
})),
|
||||
},
|
||||
};
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
reportError({ partofservice: `${req.method} ${req.originalUrl}`, error: err.stack || err.message });
|
||||
return { statusCode: 500, body: { error: "internal_error", details: err.message } };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { listDrivers };
|
||||
Reference in New Issue
Block a user