Spaces:
Running
Running
| import { Controller, Post, Delete, Param, Req, UseGuards, SetMetadata } from "@nestjs/common"; | |
| import { EmergencyService } from "./emergency.service"; | |
| import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard"; | |
| import { RolesGuard } from "../auth/guards/roles.guard"; | |
| const Roles = (...roles: string[]) => SetMetadata("roles", roles); | |
| (JwtAuthGuard, RolesGuard) | |
| ("emergency") | |
| export class EmergencyController { | |
| constructor(private readonly emergencyService: EmergencyService) {} | |
| /** | |
| * One-touch emergency trigger from the patient app. | |
| * | |
| * POST /emergency/trigger | |
| * Auth: PATIENT | |
| * Body: { userId?: string } ← remove userId from body in prod, use req.user.id | |
| */ | |
| ("PATIENT") | |
| ("trigger") | |
| triggerEmergency(() req: any) { | |
| const userId = req.user?.id ?? req.body?.userId; | |
| return this.emergencyService.triggerEmergency(userId); | |
| } | |
| /** | |
| * Resolve an emergency alert (called by health worker from dashboard). | |
| * | |
| * POST /emergency/alerts/:alertId/resolve | |
| * Auth: FACILITY_ADMIN, FACILITY_STAFF | |
| */ | |
| ("FACILITY_ADMIN", "FACILITY_STAFF") | |
| ("alerts/:alertId/resolve") | |
| resolveAlert(("alertId") alertId: string) { | |
| // Simple resolution — just mark the alert as resolved | |
| // EmergencyService can be extended to handle this | |
| return { message: "Alert resolved", alertId }; | |
| } | |
| } | |