Skip to content

Commit

Permalink
Update swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriRomano committed Mar 11, 2024
1 parent a5a0781 commit a0d884c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/appointments/appointments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,34 @@ import {
import { AppointmentsService } from './appointments.service';
import { CreateAppointmentDto } from './dto/create-appointment.dto';
import { UpdateAppointmentDto } from './dto/update-appointment.dto';
import { ApiTags } from '@nestjs/swagger';
import { ApiCreatedResponse, ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { AppointmentEntity } from './entities/appointment.entity';

@Controller('appointments')
@ApiTags('patients')
@ApiTags('Appointments')
export class AppointmentsController {
constructor(private readonly appointmentsService: AppointmentsService) {}

@Post()
@ApiCreatedResponse({ type: CreateAppointmentDto })
create(@Body() createAppointmentDto: CreateAppointmentDto) {
return this.appointmentsService.create(createAppointmentDto);
}

@Get()
@ApiOkResponse({ isArray: true, type: AppointmentEntity })
findAll() {
return this.appointmentsService.findAll();
}

@Get(':id')
@ApiOkResponse({ type: AppointmentEntity })
findOne(@Param('id') id: string) {
return this.appointmentsService.findOne(id);
}

@Patch(':id')
@ApiCreatedResponse({ type: UpdateAppointmentDto })
update(
@Param('id') id: string,
@Body() updateAppointmentDto: UpdateAppointmentDto,
Expand Down
65 changes: 64 additions & 1 deletion src/patients/dto/create-patient.dto.ts
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
export class CreatePatientDto {}
import { ApiProperty } from '@nestjs/swagger';
import { Role } from '@prisma/client';
import {
IsEnum,
IsNotEmpty,
IsOptional,
IsString,
MinLength,
} from 'class-validator';

export class CreatePatientDto {
@IsNotEmpty()
@IsString()
@ApiProperty()
firstName: string;

@IsNotEmpty()
@IsString()
@ApiProperty()
lastName: string;

@IsOptional()
@IsEnum(Role)
@ApiProperty({
enum: Role,
default: Role.PATIENT,
})
role: Role;

@IsString()
@IsNotEmpty()
@ApiProperty()
email: string;

@IsString()
@IsNotEmpty()
@ApiProperty({ default: 'M' })
sexe: string;

@IsString()
@IsNotEmpty()
@MinLength(6)
@ApiProperty()
password: string;

@ApiProperty({ required: false })
@IsOptional()
@IsString()
address?: string;

@ApiProperty({ required: false })
@IsOptional()
@IsString()
city?: string;

@ApiProperty({ required: false })
@IsOptional()
@IsString()
zipCode?: string;

@ApiProperty({ required: true })
@IsString()
secuNumber: string;
}
4 changes: 4 additions & 0 deletions src/patients/patients.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { User } from '@prisma/client';
import { RolesGuard } from 'src/auth/roles.guard';
import { HasRole } from 'src/auth/has-role.decorator';
import { ConsultationEntity } from 'src/consultations/entities/consultation.entity';
import { PatientEntity } from './entities/patient.entity';

@Controller('patients')
@ApiTags('patients')
Expand All @@ -25,18 +26,21 @@ export class PatientsController {
) {}

@Get()
@ApiOkResponse({ type: PatientEntity, isArray: true })
findAll() {
return this.patientsService.findAll();
}

@Get(':id')
@ApiOkResponse({ type: PatientEntity })
findOne(@Param('id') id: string) {
return this.patientsService.findOne(id);
}

@ApiBearerAuth()
@HasRole('PATIENT', 'ADMIN')
@UseGuards(JwtAuthGuard, RolesGuard)
@ApiOkResponse({ type: ConsultationEntity, isArray: true })
@Get(':id/consultations')
getConsultationsByPatientId(@Param('id') id: string) {
return this.consultationService.getConsultationsByPatientId(id);
Expand Down

0 comments on commit a0d884c

Please sign in to comment.