File size: 1,875 Bytes
c35b446
 
 
 
 
 
 
 
 
 
 
 
a133601
 
 
 
 
 
 
 
 
 
c35b446
b5a54b6
a133601
c35b446
a133601
c35b446
 
a133601
 
 
 
c35b446
a133601
3dd2cda
a133601
 
 
c35b446
a133601
 
 
 
 
c35b446
a133601
 
 
 
 
 
 
 
 
 
 
 
 
c35b446
a133601
 
 
 
 
c35b446
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
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);
  }
}