From 4db486a8c667b3a8d2938d137e7509aa47e1c010 Mon Sep 17 00:00:00 2001 From: IO <320154041@pcpuma.acatlan.unam.mx> Date: Thu, 28 May 2026 14:02:16 -0500 Subject: [PATCH] merge Axel --- src/periodo/periodo.controller.ts | 34 +++++++------- src/periodo/periodo.service.ts | 74 +++++++++++++++---------------- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/periodo/periodo.controller.ts b/src/periodo/periodo.controller.ts index d30269e..34afbe7 100644 --- a/src/periodo/periodo.controller.ts +++ b/src/periodo/periodo.controller.ts @@ -20,7 +20,7 @@ export class PeriodoController { @UseGuards(JwtAuthGuard, RolesGuard) @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) @Post() - create(@Body() data: CreatePeriodoDto) { + create(@Body() data: CreatePeriodoDto) { return this.periodoService.create(data); } @@ -39,21 +39,21 @@ export class PeriodoController { } @UseGuards(JwtAuthGuard, RolesGuard) -@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) -@Get('compare') -compare( - @Query('p1') p1: number, - @Query('p2') p2: number, -) { - return this.periodoService.comparePeriodos(p1, p2); -} + @Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR) + @Get('compare') + compare( + @Query('p1') p1: number, + @Query('p2') p2: number, + ) { + return this.periodoService.comparePeriodos(p1, p2); + } + + @Get('range') + getRange( + @Query('p1') p1: number, + @Query('p2') p2: number, + ) { + return this.periodoService.getPeriodosEnRango(p1, p2); + } -@Get('range') -getRange( - @Query('p1') p1: number, - @Query('p2') p2: number, -) { - return this.periodoService.getPeriodosEnRango(p1, p2); -} - } diff --git a/src/periodo/periodo.service.ts b/src/periodo/periodo.service.ts index 2a06bb4..a70c017 100644 --- a/src/periodo/periodo.service.ts +++ b/src/periodo/periodo.service.ts @@ -16,7 +16,7 @@ export class PeriodoService { } async findAll() { - return this.periodoRepository.find({order:{'id_periodo':"DESC"}}); + return this.periodoRepository.find({ order: { 'id_periodo': "DESC" } }); } async getPeriodoActivo(): Promise { @@ -71,48 +71,48 @@ export class PeriodoService { } async comparePeriodos(id1: number, id2: number) { - const periodo1 = await this.periodoRepository.findOne({ - where: { id_periodo: id1 }, - }); + const periodo1 = await this.periodoRepository.findOne({ + where: { id_periodo: id1 }, + }); - const periodo2 = await this.periodoRepository.findOne({ - where: { id_periodo: id2 }, - }); + const periodo2 = await this.periodoRepository.findOne({ + where: { id_periodo: id2 }, + }); - if (!periodo1 || !periodo2) { - throw new NotFoundException('Uno de los periodos no existe'); + if (!periodo1 || !periodo2) { + throw new NotFoundException('Uno de los periodos no existe'); + } + + return { + periodo1: { + id: periodo1.id_periodo, + nombre: periodo1.semestre, + fecha_inicio: periodo1.fecha_inicio_servicio, + fecha_fin: periodo1.fecha_fin_servicio, + }, + periodo2: { + id: periodo2.id_periodo, + nombre: periodo2.semestre, + fecha_inicio: periodo2.fecha_inicio_servicio, + fecha_fin: periodo2.fecha_fin_servicio, + }, + }; } - return { - periodo1: { - id: periodo1.id_periodo, - nombre: periodo1.semestre, - fecha_inicio: periodo1.fecha_inicio_servicio, - fecha_fin: periodo1.fecha_fin_servicio, - }, - periodo2: { - id: periodo2.id_periodo, - nombre: periodo2.semestre, - fecha_inicio: periodo2.fecha_inicio_servicio, - fecha_fin: periodo2.fecha_fin_servicio, - }, - }; -} + async getPeriodosEnRango(id1: number, id2: number) { + const min = Math.min(id1, id2); + const max = Math.max(id1, id2); -async getPeriodosEnRango(id1: number, id2: number) { - const min = Math.min(id1, id2); - const max = Math.max(id1, id2); + return this.periodoRepository.find({ + where: { + id_periodo: Between(min, max), + }, + order: { + id_periodo: 'ASC', + }, + }); + } - return this.periodoRepository.find({ - where: { - id_periodo: Between(min, max), - }, - order: { - id_periodo: 'ASC', - }, - }); -} - }