Files
ws_health/api/routes/index.js
2026-05-25 12:34:16 +08:00

38 lines
1.4 KiB
JavaScript

import Router from "koa-router";
import { HandlerEscortRecord } from "../handler/escort_record.js";
import { HandlerResource } from "../handler/resource.js";
function printRoutes(stack) {
for (const layer of stack) {
if (layer.path) {
const methods = layer.methods.filter(m => m !== '_all');
methods.forEach(m => console.log(` [${m.toUpperCase()}] ${layer.path}`));
}
}
}
function registerRoutes(app) {
const router = new Router({ prefix: '/health' });
const handlerEscortRecord = new HandlerEscortRecord();
const handlerResource = new HandlerResource();
router.get("/escort-record/my", handlerEscortRecord.getMyRecords.bind(handlerEscortRecord));
router.get("/escort-record/attendant", handlerEscortRecord.getAttendantRecords.bind(handlerEscortRecord));
router.get("/escort-record/:id", handlerEscortRecord.getRecordById.bind(handlerEscortRecord));
router.post("/escort-record", handlerEscortRecord.createRecord.bind(handlerEscortRecord));
router.put("/escort-record/:id", handlerEscortRecord.updateRecord.bind(handlerEscortRecord));
router.patch("/escort-record/:id/status", handlerEscortRecord.updateStatus.bind(handlerEscortRecord));
router.get("/service", handlerResource.getServices.bind(handlerResource));
app.use(router.routes());
app.use(router.allowedMethods());
console.log('API Routes:');
printRoutes(router.stack);
return router;
}
export default registerRoutes;