Files
The-transit-Project/transit_api/repo/drivers.mock.js
T
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

34 lines
987 B
JavaScript

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 };