Spaces:
Running
Running
| import { | |
| Body, | |
| Controller, | |
| Get, | |
| Post, | |
| Put, | |
| Param, | |
| UseGuards, | |
| Req, | |
| Query, | |
| SetMetadata, | |
| } from "@nestjs/common"; | |
| import { Request } from "express"; | |
| import { PatientsService } from "./patients.service"; | |
| import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard"; | |
| import { RolesGuard } from "../auth/guards/roles.guard"; | |
| import { GetPatientsDto } from "./dto/get-patient-dto"; | |
| import { UpdatePatientDto } from "./dto/update-patient.dto"; | |
| const Roles = (...roles: string[]) => SetMetadata("roles", roles); | |
| ("patients") | |
| (JwtAuthGuard, RolesGuard) | |
| export class PatientsController { | |
| constructor(private readonly patientsService: PatientsService) {} | |
| () | |
| ("SUPER_ADMIN", "FACILITY_ADMIN", "FACILITY_STAFF") | |
| create( | |
| () | |
| data: { | |
| firstName: string; | |
| lastName: string; | |
| phone: string; | |
| age: number; | |
| address?: string; | |
| gestationalAge: number; | |
| estimatedDeliveryDate?: Date; | |
| facilityId: string; | |
| email?: string; | |
| password: string; | |
| }, | |
| ) { | |
| return this.patientsService.create(data); | |
| } | |
| () | |
| ("SUPER_ADMIN", "FACILITY_ADMIN", "FACILITY_STAFF") | |
| findAll( | |
| () | |
| req: Request & { | |
| user: any; | |
| }, | |
| () | |
| query: GetPatientsDto, | |
| ) { | |
| if (req.user.role === "SUPER_ADMIN") { | |
| return this.patientsService.findAll(undefined, query); | |
| } | |
| return this.patientsService.findAll( | |
| req.user.healthcareWorker?.facilityId, | |
| query, | |
| ); | |
| } | |
| ("defaulters") | |
| ("FACILITY_ADMIN", "FACILITY_STAFF") | |
| getDefaulters( | |
| () | |
| req: Request & { | |
| user: any; | |
| }, | |
| ) { | |
| return this.patientsService.getDefaulters( | |
| req.user.healthcareWorker?.facilityId, | |
| ); | |
| } | |
| (":id") | |
| ("SUPER_ADMIN", "FACILITY_ADMIN", "FACILITY_STAFF", "PATIENT") | |
| findOne(("id") id: string) { | |
| return this.patientsService.findOne(id); | |
| } | |
| (":id") | |
| ("SUPER_ADMIN", "FACILITY_ADMIN", "FACILITY_STAFF") | |
| update(("id") id: string, () data: UpdatePatientDto) { | |
| return this.patientsService.update(id, data); | |
| } | |
| } | |