52 lines
2.3 KiB
TypeScript
52 lines
2.3 KiB
TypeScript
import { Body, Controller, Delete, Get, Param, Post, Query, Req, UseGuards } from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
|
import { AppointmentsService } from './appointments.service';
|
|
import { CreateAppointmentDto } from './dto/create-appointment.dto';
|
|
import { ListAppointmentsDto } from './dto/list-appointments.dto';
|
|
|
|
@ApiTags('appointments')
|
|
@ApiBearerAuth('JWT-auth')
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('appointments')
|
|
export class AppointmentsController {
|
|
constructor(private readonly appointmentsService: AppointmentsService) {}
|
|
|
|
@Get('column-providers')
|
|
@ApiOperation({
|
|
summary:
|
|
'Staff columns: active non-owner members with TAB_TREATMENT_EDIT. Owners are excluded. Requires TAB_APPOINTMENTS_READ or owner.',
|
|
})
|
|
columnProviders(@Req() req: { user: { id: string; organizationId?: string } }) {
|
|
const organizationId = this.appointmentsService.getOrganizationIdFromUser(req.user);
|
|
return this.appointmentsService.listColumnProviders(organizationId, req.user.id);
|
|
}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List appointments intersecting a time range (requires TAB_APPOINTMENTS_READ or owner)' })
|
|
list(@Query() query: ListAppointmentsDto, @Req() req: { user: { id: string; organizationId?: string } }) {
|
|
const organizationId = this.appointmentsService.getOrganizationIdFromUser(req.user);
|
|
return this.appointmentsService.list(query, organizationId, req.user.id);
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create appointment (requires TAB_APPOINTMENTS_EDIT or owner)' })
|
|
create(
|
|
@Body() dto: CreateAppointmentDto,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.appointmentsService.getOrganizationIdFromUser(req.user);
|
|
return this.appointmentsService.create(dto, organizationId, req.user.id);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: 'Delete appointment (requires TAB_APPOINTMENTS_EDIT or owner)' })
|
|
remove(
|
|
@Param('id') id: string,
|
|
@Req() req: { user: { id: string; organizationId?: string } },
|
|
) {
|
|
const organizationId = this.appointmentsService.getOrganizationIdFromUser(req.user);
|
|
return this.appointmentsService.remove(id, organizationId, req.user.id);
|
|
}
|
|
}
|