MaternAlert / src /emergency /emergency.controller.ts
Auspicious14's picture
refactor: replace HEALTH_WORKER with FACILITY roles
a133601
Raw
History Blame Contribute Delete
1.39 kB
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);
@UseGuards(JwtAuthGuard, RolesGuard)
@Controller("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
*/
@Roles("PATIENT")
@Post("trigger")
triggerEmergency(@Req() 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
*/
@Roles("FACILITY_ADMIN", "FACILITY_STAFF")
@Post("alerts/:alertId/resolve")
resolveAlert(@Param("alertId") alertId: string) {
// Simple resolution — just mark the alert as resolved
// EmergencyService can be extended to handle this
return { message: "Alert resolved", alertId };
}
}