MaternAlert / src /referral /referral.controller.ts
Auspicious14's picture
refactor: replace HEALTH_WORKER with FACILITY roles
a133601
Raw
History Blame Contribute Delete
2.09 kB
import {
Controller,
Get,
Post,
Patch,
Param,
Body,
UseGuards,
Req,
SetMetadata,
} from "@nestjs/common";
import { Request } from "express";
import { ReferralsService, UpdateReferralDto } from "./referral.service";
import { CreateReferralDto } from "./dto/create-referral-dto";
import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard";
import { RolesGuard } from "src/auth/guards/roles.guard";
const Roles = (...roles: string[]) => SetMetadata("roles", roles);
@Controller("health-worker/referrals")
@UseGuards(JwtAuthGuard, RolesGuard)
export class ReferralsController {
constructor(private readonly referralsService: ReferralsService) {}
/** POST /health-worker/referrals */
@Post()
@Roles("FACILITY_ADMIN", "FACILITY_STAFF")
create(@Body() dto: CreateReferralDto, @Req() req: Request & { user: any }) {
const facilityId = req.user.healthcareWorker?.facilityId;
return this.referralsService.create(dto, facilityId);
}
/** GET /health-worker/referrals */
@Get()
@Roles("FACILITY_ADMIN", "FACILITY_STAFF")
findAll(@Req() req: Request & { user: any }) {
const facilityId = req.user.healthcareWorker?.facilityId;
return this.referralsService.findAll(facilityId);
}
/** GET /health-worker/referrals/stats */
@Get("stats")
@Roles("FACILITY_ADMIN", "FACILITY_STAFF")
getStats(@Req() req: Request & { user: any }) {
const facilityId = req.user.healthcareWorker?.facilityId;
return this.referralsService.getReferralStats(facilityId);
}
@Get(":id")
@Roles("FACILITY_ADMIN", "FACILITY_STAFF")
findOne(@Param("id") id: string, @Req() req: Request & { user: any }) {
const facilityId = req.user.healthcareWorker?.facilityId;
return this.referralsService.findOne(id, facilityId);
}
@Patch(":id/status")
@Roles("FACILITY_ADMIN", "FACILITY_STAFF")
updateStatus(@Param("id") id: string, @Body() dto: UpdateReferralDto, @Req() req: Request & { user: any }) {
const facilityId = req.user.healthcareWorker?.facilityId;
return this.referralsService.updateStatus(id, dto, facilityId);
}
}