updated transit api
Build and Push Docker Images / detect-changes (push) Successful in 10s
Build and Push Docker Images / build-auth-api (push) Successful in 1m0s
Build and Push Docker Images / build-employee-api (push) Successful in 1m3s
Build and Push Docker Images / build-transit-api (push) Successful in 59s
Build and Push Docker Images / build-error-log-api (push) Successful in 1m9s
Build and Push Docker Images / build-admin-ui (push) Successful in 1m20s
Build and Push Docker Images / deploy-test-node (push) Successful in 4s

This commit is contained in:
Sven laptop
2026-09-18 20:08:10 +02:00
parent 1154d1d658
commit f935bbeb8c
9 changed files with 144 additions and 13 deletions
+6
View File
@@ -59,6 +59,12 @@ API draait op `https://transit.xtransit.testinstance.nl`
Alle endpoints vereisen een `Authorization: Bearer {token}` header.
**GET** `/health`
- Controleert of de gedeployde transit API draait en de database bereikbaar is.
- Geeft `200` met `{"status":"ok","database":"ok"}` bij succes.
- Geeft `503` als de API wel draait maar de database niet bereikbaar is.
### Schedule
Schedules are weekly templates. Each row in `transit.schedules` represents one
+27 -4
View File
@@ -13,6 +13,14 @@ const ERROR_LOG_API_URL =
process.env.ERROR_LOG_API_URL ||
"https://error.xtransit.testinstance.nl/error_log";
function isValidDateKey(value) {
if (!/^\d{4}-\d{2}-\d{2}$/.test(String(value || ""))) return false;
const date = new Date(`${value}T00:00:00Z`);
return (
!Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value
);
}
function friendlyErrorMessage(statusCode) {
if (statusCode === 400) return "Controleer je invoer en probeer opnieuw.";
if (statusCode === 401) return "Je sessie is verlopen. Log opnieuw in.";
@@ -53,6 +61,16 @@ app.use((req, res, next) => {
next();
});
app.get("/health", async (_req, res) => {
try {
await db.query("SELECT 1");
res.json({ status: "ok", service: "transit_api", database: "ok" });
} catch (err) {
console.error("GET /health error:", err);
res.status(503).json({ status: "unavailable", service: "transit_api" });
}
});
// Development mock storage when DEV_MOCK=1
const DEV_MOCK = process.env.DEV_MOCK === "1";
const _mock = {
@@ -1081,8 +1099,9 @@ app.get("/schedule/daily", authMiddleware, async (req, res) => {
app.get("/driver/schedules/daily", authMiddleware, async (req, res) => {
try {
const { date } = req.query;
if (!date)
return res.status(400).json({ error: "date query parameter required" });
if (!isValidDateKey(date)) {
return res.status(400).json({ error: "date must use YYYY-MM-DD format" });
}
const result = await db.query(
`
@@ -1090,9 +1109,13 @@ app.get("/driver/schedules/daily", authMiddleware, async (req, res) => {
bl.line_number, bl.start_stop, bl.end_stop, bl.estimated_duration_minutes,
bl.description
FROM transit.schedules s
JOIN transit.shifts sh ON sh.schedule_id = s.id AND sh.driver_id = $1
JOIN transit.bus_lines bl ON bl.id = s.bus_line_id
WHERE s.day_of_week = EXTRACT(DOW FROM $2::date)::int
WHERE EXISTS (
SELECT 1
FROM transit.shifts sh
WHERE sh.schedule_id = s.id AND sh.driver_id = $1
)
AND s.day_of_week = EXTRACT(DOW FROM $2::date)::int
AND s.status <> 'cancelled'
ORDER BY s.start_time ASC
`,