Files
The-transit-Project/transit_api/mock/store.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

184 lines
3.7 KiB
JavaScript

// Development mock storage when DEV_MOCK=1
const { DEV_MOCK } = require("../lib/env");
const store = {
stops: [],
routeStops: [],
busLines: [],
fleetBuses: [],
schedules: [],
scheduleStopProgress: [],
drivers: [],
nextStopId: 1,
nextRouteStopId: 1,
nextBusLineId: 1,
nextFleetBusId: 1,
nextScheduleId: 1,
nextScheduleStopProgressId: 1,
nextDriverId: 1,
};
// Initialize mock drivers
if (DEV_MOCK) {
store.drivers = [
{
id: 1,
name: "Jan Peterse",
email: "jan@transit.local",
phone: "06-12345678",
status: "active",
},
{
id: 2,
name: "Maria Kuijpers",
email: "maria@transit.local",
phone: "06-87654321",
status: "active",
},
{
id: 3,
name: "Robert Smits",
email: "robert@transit.local",
phone: "06-55555555",
status: "active",
},
{
id: 4,
name: "Anja Voorn",
email: "anja@transit.local",
phone: "06-44444444",
status: "inactive",
},
];
store.nextDriverId = 5;
// Initialize test bus lines
store.busLines = [
{
id: 1,
lineNumber: 1,
startStop: "Central Station",
endStop: "Airport",
estimatedDurationMinutes: 45,
description: "Main route",
},
{
id: 2,
lineNumber: 2,
startStop: "Central Station",
endStop: "Harbor",
estimatedDurationMinutes: 30,
description: "Harbor route",
},
];
store.nextBusLineId = 3;
// Initialize test stops
store.stops = [
{
id: 1,
name: "Central Station",
latitude: 52.0116,
longitude: 4.7055,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
id: 2,
name: "City Center",
latitude: 52.0125,
longitude: 4.71,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
id: 3,
name: "Airport",
latitude: 52.03,
longitude: 4.75,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
];
store.nextStopId = 4;
// Initialize test route stops
store.routeStops = [
{
id: 1,
busLineId: 1,
stopId: 1,
stopOrder: 1,
estimatedArrivalMinutes: 0,
name: "Central Station",
latitude: 52.0116,
longitude: 4.7055,
},
{
id: 2,
busLineId: 1,
stopId: 2,
stopOrder: 2,
estimatedArrivalMinutes: 15,
name: "City Center",
latitude: 52.0125,
longitude: 4.71,
},
{
id: 3,
busLineId: 1,
stopId: 3,
stopOrder: 3,
estimatedArrivalMinutes: 45,
name: "Airport",
latitude: 52.03,
longitude: 4.75,
},
];
store.nextRouteStopId = 4;
// Initialize test fleet buses
store.fleetBuses = [
{
id: 1,
name: "Bus 101",
seatCapacity: 45,
licensePlate: "AB-01-CD",
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
{
id: 2,
name: "Bus 102",
seatCapacity: 50,
licensePlate: "AB-02-CD",
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
];
store.nextFleetBusId = 3;
// Initialize test schedule
const now = new Date();
const tomorrow = new Date(now.getTime() + 24 * 60 * 60 * 1000);
tomorrow.setHours(10, 0, 0, 0);
const endTime = new Date(tomorrow.getTime() + 45 * 60 * 1000);
store.schedules = [
{
id: 1,
busLineId: 1,
busId: 1,
driverId: null,
startTime: tomorrow.toISOString(),
endTime: endTime.toISOString(),
weekdays: [],
status: "planned",
createdAt: new Date().toISOString(),
},
];
store.nextScheduleId = 2;
}
module.exports = { store };