import { Controller, Get, Post, Put, Delete, Body, Param, UseGuards, Request, HttpCode, HttpStatus, SetMetadata, } from "@nestjs/common"; import { AppointmentsService } from "./appointments.service"; import { CreateAppointmentDto } from "./dto/create-appointment.dto"; import { UpdateAppointmentDto } from "./dto/update-appointment.dto"; import { JwtAuthGuard } from "../auth/guards/jwt-auth.guard"; import { Appointment } from "@prisma/client"; import { RolesGuard } from "src/auth/guards/roles.guard"; const Roles = (...roles: string[]) => SetMetadata("roles", roles); @Controller("appointments") @UseGuards(JwtAuthGuard, RolesGuard) export class AppointmentsController { constructor(private readonly appointmentsService: AppointmentsService) {} @Post() @Roles("FACILITY_ADMIN", "FACILITY_STAFF") create(@Request() req: any, @Body() dto: CreateAppointmentDto) { return this.appointmentsService.create(req.user.healthcareWorker.facilityId, dto); } @Get() @Roles("FACILITY_ADMIN", "FACILITY_STAFF") findAll(@Request() req: any) { return this.appointmentsService.findAll(req.user.healthcareWorker.facilityId); } @Get(":id") @Roles("FACILITY_ADMIN", "FACILITY_STAFF") findOne(@Param("id") id: string, @Request() req: any) { return this.appointmentsService.findOne(id, req.user.healthcareWorker.facilityId); } @Put(":id") @Roles("FACILITY_ADMIN", "FACILITY_STAFF") update( @Param("id") id: string, @Request() req: any, @Body() dto: UpdateAppointmentDto, ) { return this.appointmentsService.update( id, req.user.healthcareWorker.facilityId, dto, ); } @Delete(":id") @Roles("FACILITY_ADMIN", "FACILITY_STAFF") remove(@Param("id") id: string, @Request() req: any) { return this.appointmentsService.remove(id, req.user.healthcareWorker.facilityId); } }