Spaces:
Running
Running
File size: 2,132 Bytes
c35b446 b5a54b6 c35b446 5f952c4 c35b446 395abdc b5a54b6 c35b446 b5a54b6 c35b446 395abdc 5f952c4 c35b446 a133601 c35b446 a133601 c35b446 a133601 c35b446 a133601 c35b446 395abdc c35b446 a133601 c35b446 a133601 b5a54b6 a133601 c35b446 b5a54b6 a133601 b5a54b6 395abdc b5a54b6 a133601 b5a54b6 395abdc a133601 395abdc c35b446 a133601 c35b446 5f952c4 a133601 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 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);
@Controller("patients")
@UseGuards(JwtAuthGuard, RolesGuard)
export class PatientsController {
constructor(private readonly patientsService: PatientsService) {}
@Post()
@Roles("SUPER_ADMIN", "FACILITY_ADMIN", "FACILITY_STAFF")
create(
@Body()
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);
}
@Get()
@Roles("SUPER_ADMIN", "FACILITY_ADMIN", "FACILITY_STAFF")
findAll(
@Req()
req: Request & {
user: any;
},
@Query()
query: GetPatientsDto,
) {
if (req.user.role === "SUPER_ADMIN") {
return this.patientsService.findAll(undefined, query);
}
return this.patientsService.findAll(
req.user.healthcareWorker?.facilityId,
query,
);
}
@Get("defaulters")
@Roles("FACILITY_ADMIN", "FACILITY_STAFF")
getDefaulters(
@Req()
req: Request & {
user: any;
},
) {
return this.patientsService.getDefaulters(
req.user.healthcareWorker?.facilityId,
);
}
@Get(":id")
@Roles("SUPER_ADMIN", "FACILITY_ADMIN", "FACILITY_STAFF", "PATIENT")
findOne(@Param("id") id: string) {
return this.patientsService.findOne(id);
}
@Put(":id")
@Roles("SUPER_ADMIN", "FACILITY_ADMIN", "FACILITY_STAFF")
update(@Param("id") id: string, @Body() data: UpdatePatientDto) {
return this.patientsService.update(id, data);
}
}
|