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:
@@ -72,52 +72,54 @@ All endpoints require an `Authorization: Bearer {token}` header.
|
||||
|
||||
### Schedule
|
||||
|
||||
Schedules are weekly templates. Each row in `transit.schedules` represents one
|
||||
Schedules are weekly templates. Each row in `"transit.bus".schedules` represents one
|
||||
departure time for one bus line and one `day_of_week`:
|
||||
|
||||
- `1` to `5`: weekdays
|
||||
- `6`: Saturday
|
||||
- `0`: Sunday
|
||||
|
||||
Driver assignments are stored separately in `transit.shifts` with
|
||||
Driver assignments are stored separately in `"transit.bus".shifts` with
|
||||
`(schedule_id, driver_id)`, where `driver_id` references `workers.users(id)`.
|
||||
The current `shifts` shape represents the active assignment. To retain different
|
||||
assignments for different calendar weeks, add a `week_start` (or assignment date
|
||||
range) column and include it in the unique key.
|
||||
|
||||
**GET** `/driver/schedules/daily?date=2026-09-18`
|
||||
**GET** `/bus/driver/schedules/daily?date=2026-09-18`
|
||||
|
||||
- Returns only weekly schedule templates assigned to the authenticated driver through `transit.shifts`.
|
||||
- Returns only weekly schedule templates assigned to the authenticated driver through `"transit.bus".shifts`.
|
||||
|
||||
**PATCH** `/driver/weekly-schedules/:scheduleId/status`
|
||||
**PATCH** `/bus/driver/weekly-schedules/:scheduleId/status`
|
||||
|
||||
- Updates the status of an assigned weekly schedule.
|
||||
|
||||
**GET** `/admin/weekly-schedules`
|
||||
**GET** `/bus/admin/weekly-schedules`
|
||||
|
||||
- Lists weekly templates and their current driver assignments.
|
||||
|
||||
**GET** `/admin/shift-drivers`
|
||||
**GET** `/bus/admin/shift-drivers`
|
||||
|
||||
- Lists drivers from `workers.users` for shift assignment.
|
||||
|
||||
**POST** `/admin/weekly-schedules`
|
||||
**POST** `/bus/admin/weekly-schedules`
|
||||
|
||||
- Creates one template. Body: `{ "busLineId": 1, "dayOfWeek": 1, "startTime": "08:00", "endTime": "09:00", "driverId": 12 }`.
|
||||
|
||||
**POST** `/admin/weekly-schedules/bulk`
|
||||
**POST** `/bus/admin/weekly-schedules/bulk`
|
||||
|
||||
- Creates multiple departures in one transaction. The API derives each end time
|
||||
from the selected bus line duration. Body: `{ "busLineId": 1, "dayOfWeeks": [1,2,3,4,5], "startTimes": ["06:00", "06:30", "07:00"], "driverId": 12 }`.
|
||||
|
||||
**PUT** `/admin/weekly-schedules/:scheduleId/shift`
|
||||
**PUT** `/bus/admin/weekly-schedules/:scheduleId/shift`
|
||||
|
||||
- Replaces the driver assignment. Pass `{ "driverId": 12 }` or `{ "driverId": null }`.
|
||||
|
||||
The legacy `/admin/schedules` and `/schedule/daily` endpoints remain for older
|
||||
clients, but new clients must use the weekly schedule endpoints above.
|
||||
The legacy `/admin/schedules` and `/schedule/daily` aliases remain for older
|
||||
clients, but new clients must use the `/bus/`-prefixed canonical endpoints
|
||||
(`/bus/admin/schedules`, `/bus/schedule/daily`) and the weekly schedule
|
||||
endpoints above.
|
||||
|
||||
**GET** `/schedule/daily?date=2024-05-05`
|
||||
**GET** `/bus/schedule/daily?date=2024-05-05`
|
||||
|
||||
- Retrieve daily schedule for driver
|
||||
- Response:
|
||||
@@ -145,14 +147,14 @@ clients, but new clients must use the weekly schedule endpoints above.
|
||||
}
|
||||
```
|
||||
|
||||
**GET** `/routes/:routeId`
|
||||
**GET** `/bus/routes/:routeId`
|
||||
|
||||
- Details of a specific route
|
||||
- Response: `{ "route": {...} }`
|
||||
|
||||
### Public Schedule Overview
|
||||
|
||||
**GET** `/schedules/overview?date=2026-05-06&lineId=1`
|
||||
**GET** `/bus/schedules/overview?date=2026-05-06&lineId=1`
|
||||
|
||||
- Fetches a date-based overview of scheduled services
|
||||
- Weekly templates are selected by `day_of_week` and driver assignments by `shifts`
|
||||
@@ -160,17 +162,18 @@ clients, but new clients must use the weekly schedule endpoints above.
|
||||
- Filters: `driverId`/`chauffeurId`, `stopId`/`busStopId`, `lineId`, `status`
|
||||
- Response: `{ "date": "2026-05-06", "summary": {...}, "schedules": [...] }`
|
||||
|
||||
The legacy endpoint **GET** `/schedules` remains available for existing clients.
|
||||
The legacy endpoint **GET** `/schedules` remains available as a deprecated alias
|
||||
for existing clients; the canonical path is **GET** `/bus/schedules`.
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
curl "https://transit.xtransit.testinstance.nl/schedules/overview?date=2026-05-06&chauffeurId=12&busStopId=3"
|
||||
curl "https://transit.xtransit.testinstance.nl/bus/schedules/overview?date=2026-05-06&chauffeurId=12&busStopId=3"
|
||||
```
|
||||
|
||||
### Navigation
|
||||
|
||||
**POST** `/navigation/route`
|
||||
**POST** `/bus/navigation/route`
|
||||
|
||||
- Save calculated route from OSRM
|
||||
- Body:
|
||||
@@ -191,7 +194,7 @@ curl "https://transit.xtransit.testinstance.nl/schedules/overview?date=2026-05-0
|
||||
}
|
||||
```
|
||||
|
||||
**GET** `/bus-lines/:busLineId/stops`
|
||||
**GET** `/bus/bus-lines/:busLineId/stops`
|
||||
|
||||
- All stops of a bus line (for navigation waypoints)
|
||||
- Response:
|
||||
@@ -212,7 +215,7 @@ curl "https://transit.xtransit.testinstance.nl/schedules/overview?date=2026-05-0
|
||||
|
||||
### GPS Tracking
|
||||
|
||||
**POST** `/gps/track`
|
||||
**POST** `/bus/gps/track`
|
||||
|
||||
- Save real-time position
|
||||
- Body:
|
||||
@@ -228,7 +231,7 @@ curl "https://transit.xtransit.testinstance.nl/schedules/overview?date=2026-05-0
|
||||
}
|
||||
```
|
||||
|
||||
**GET** `/gps/route/:routeId`
|
||||
**GET** `/bus/gps/route/:routeId`
|
||||
|
||||
- All recorded position points of a route
|
||||
- Response:
|
||||
@@ -250,7 +253,7 @@ curl "https://transit.xtransit.testinstance.nl/schedules/overview?date=2026-05-0
|
||||
|
||||
### Route Status
|
||||
|
||||
**PATCH** `/routes/:routeId/status`
|
||||
**PATCH** `/bus/routes/:routeId/status`
|
||||
|
||||
- Update route status
|
||||
- Body: `{ "status": "in_progress" }`
|
||||
@@ -260,7 +263,7 @@ curl "https://transit.xtransit.testinstance.nl/schedules/overview?date=2026-05-0
|
||||
|
||||
All admin endpoints require, in addition to a valid JWT token, that your `userCode` is present in `ADMIN_USER_CODES`.
|
||||
|
||||
**POST** `/admin/stops`
|
||||
**POST** `/bus/admin/stops`
|
||||
|
||||
- Create a reusable stop
|
||||
- Body:
|
||||
@@ -273,7 +276,7 @@ All admin endpoints require, in addition to a valid JWT token, that your `userCo
|
||||
}
|
||||
```
|
||||
|
||||
**POST** `/admin/bus-lines/:busLineId/stops`
|
||||
**POST** `/bus/admin/bus-lines/:busLineId/stops`
|
||||
|
||||
- Link an existing stop to a bus line
|
||||
- Body:
|
||||
|
||||
Reference in New Issue
Block a user