From ce6bfe714f92dd59413f3e0eeb30f7bcd14fac3c Mon Sep 17 00:00:00 2001 From: xXpuma99Xx <51341582+xXpuma99Xx@users.noreply.github.com> Date: Tue, 14 Jun 2022 12:03:08 -0500 Subject: [PATCH] hora-excepcion input output dto --- .../create.dto.ts} | 2 +- .../delete.dto.ts} | 2 +- .../get.dto.ts} | 2 +- .../update.dto.ts} | 2 +- .../dto/output/hora-excepcion.dto.ts | 12 ++++++++++++ .../entity/hora-excepcion.entity.ts | 1 - .../hora-excepcion.controller.ts | 19 +++++++++++-------- 7 files changed, 27 insertions(+), 13 deletions(-) rename src/hora-excepcion/dto/{hora-excepcion-create.dto.ts => input/create.dto.ts} (83%) rename src/hora-excepcion/dto/{hora-excepcion-delete.dto.ts => input/delete.dto.ts} (68%) rename src/hora-excepcion/dto/{hora-excepcion-get.dto.ts => input/get.dto.ts} (74%) rename src/hora-excepcion/dto/{hora-excepcion-update.dto.ts => input/update.dto.ts} (85%) create mode 100644 src/hora-excepcion/dto/output/hora-excepcion.dto.ts diff --git a/src/hora-excepcion/dto/hora-excepcion-create.dto.ts b/src/hora-excepcion/dto/input/create.dto.ts similarity index 83% rename from src/hora-excepcion/dto/hora-excepcion-create.dto.ts rename to src/hora-excepcion/dto/input/create.dto.ts index 425528c..9deec7f 100644 --- a/src/hora-excepcion/dto/hora-excepcion-create.dto.ts +++ b/src/hora-excepcion/dto/input/create.dto.ts @@ -1,6 +1,6 @@ import { IsInt, IsMilitaryTime } from 'class-validator'; -export class HoraExcepcionCreateDto { +export class CreateHoraExcepcionDto { @IsInt() id_institucion_dia: number; diff --git a/src/hora-excepcion/dto/hora-excepcion-delete.dto.ts b/src/hora-excepcion/dto/input/delete.dto.ts similarity index 68% rename from src/hora-excepcion/dto/hora-excepcion-delete.dto.ts rename to src/hora-excepcion/dto/input/delete.dto.ts index 93a19b9..053d4ab 100644 --- a/src/hora-excepcion/dto/hora-excepcion-delete.dto.ts +++ b/src/hora-excepcion/dto/input/delete.dto.ts @@ -1,6 +1,6 @@ import { IsInt } from 'class-validator'; -export class HoraExcepcionDeleteDto { +export class DeleteHoraExcepcionDto { @IsInt() id_hora_excepcion: number; } diff --git a/src/hora-excepcion/dto/hora-excepcion-get.dto.ts b/src/hora-excepcion/dto/input/get.dto.ts similarity index 74% rename from src/hora-excepcion/dto/hora-excepcion-get.dto.ts rename to src/hora-excepcion/dto/input/get.dto.ts index eaad62b..91b4abd 100644 --- a/src/hora-excepcion/dto/hora-excepcion-get.dto.ts +++ b/src/hora-excepcion/dto/input/get.dto.ts @@ -1,6 +1,6 @@ import { IsNumberString } from 'class-validator'; -export class HoraExcepcionGetDto { +export class GetHoraExcepcionDto { @IsNumberString() id_institucion_dia: string; } diff --git a/src/hora-excepcion/dto/hora-excepcion-update.dto.ts b/src/hora-excepcion/dto/input/update.dto.ts similarity index 85% rename from src/hora-excepcion/dto/hora-excepcion-update.dto.ts rename to src/hora-excepcion/dto/input/update.dto.ts index e599e59..3e43168 100644 --- a/src/hora-excepcion/dto/hora-excepcion-update.dto.ts +++ b/src/hora-excepcion/dto/input/update.dto.ts @@ -1,6 +1,6 @@ import { IsInt, IsMilitaryTime, IsOptional } from 'class-validator'; -export class HoraExcepcionUpdateDto { +export class UpdateHoraExcepcionDto { @IsInt() id_hora_excepcion: number; diff --git a/src/hora-excepcion/dto/output/hora-excepcion.dto.ts b/src/hora-excepcion/dto/output/hora-excepcion.dto.ts new file mode 100644 index 0000000..e775478 --- /dev/null +++ b/src/hora-excepcion/dto/output/hora-excepcion.dto.ts @@ -0,0 +1,12 @@ +import { Expose } from 'class-transformer'; + +export class HoraExcepcionOutputDto { + @Expose() + id_hora_excepcion; + + @Expose() + hora_fin; + + @Expose() + hora_inicio; +} diff --git a/src/hora-excepcion/entity/hora-excepcion.entity.ts b/src/hora-excepcion/entity/hora-excepcion.entity.ts index 1960cdb..80b10a3 100644 --- a/src/hora-excepcion/entity/hora-excepcion.entity.ts +++ b/src/hora-excepcion/entity/hora-excepcion.entity.ts @@ -21,7 +21,6 @@ export class HoraExcepcion { @ManyToOne( () => InstitucionDia, (institucionDia) => institucionDia.horasExcepcion, - { eager: true }, ) @JoinColumn({ name: 'id_institucion_dia' }) institucionDia: InstitucionDia; diff --git a/src/hora-excepcion/hora-excepcion.controller.ts b/src/hora-excepcion/hora-excepcion.controller.ts index 3017ef5..a7bc8d4 100644 --- a/src/hora-excepcion/hora-excepcion.controller.ts +++ b/src/hora-excepcion/hora-excepcion.controller.ts @@ -8,11 +8,13 @@ import { Query, } from '@nestjs/common'; import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger'; +import { Serealize } from '../interceptors/serialize.interceptor'; import { HoraExcepcionService } from './hora-excepcion.service'; -import { HoraExcepcionCreateDto } from './dto/hora-excepcion-create.dto'; -import { HoraExcepcionDeleteDto } from './dto/hora-excepcion-delete.dto'; -import { HoraExcepcionGetDto } from './dto/hora-excepcion-get.dto'; -import { HoraExcepcionUpdateDto } from './dto/hora-excepcion-update.dto'; +import { CreateHoraExcepcionDto } from './dto/input/create.dto'; +import { DeleteHoraExcepcionDto } from './dto/input/delete.dto'; +import { GetHoraExcepcionDto } from './dto/input/get.dto'; +import { UpdateHoraExcepcionDto } from './dto/input/update.dto'; +import { HoraExcepcionOutputDto } from './dto/output/hora-excepcion.dto'; @Controller('hora-excepcion') @ApiTags('hora-excepcion') @@ -35,7 +37,7 @@ export class HoraExcepcionController { }, }, }) - create(@Body() body: HoraExcepcionCreateDto) { + create(@Body() body: CreateHoraExcepcionDto) { return this.horaExcepcionService.create( body.id_institucion_dia, body.hora_inicio, @@ -51,16 +53,17 @@ export class HoraExcepcionController { description: 'Es obligatorio mandar la variable id_hora_excepcion.', examples: { ejemplo: { value: { id_hora_excepcion: 1 } } }, }) - delete(@Body() body: HoraExcepcionDeleteDto) { + delete(@Body() body: DeleteHoraExcepcionDto) { return this.horaExcepcionService.delete(body.id_hora_excepcion); } + @Serealize(HoraExcepcionOutputDto) @Get() @ApiOperation({ description: 'Endpoint que retorna las horas excepcion de un día de una institución.', }) - get(@Query() query: HoraExcepcionGetDto) { + get(@Query() query: GetHoraExcepcionDto) { return this.horaExcepcionService.findAllByIdInstitucionDia( parseInt(query.id_institucion_dia), ); @@ -80,7 +83,7 @@ export class HoraExcepcionController { }, }, }) - update(@Body() body: HoraExcepcionUpdateDto) { + update(@Body() body: UpdateHoraExcepcionDto) { return this.horaExcepcionService.update(body); } }