Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d0217b445b |
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, UseGuards } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Put, Query, UseGuards } from '@nestjs/common';
|
||||
import { PeriodoService } from './periodo.service';
|
||||
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||
import { JwtAuthGuard } from 'src/user/jwt.guard';
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -37,4 +37,23 @@ export class PeriodoController {
|
||||
modifiedDate(@Body() data: ModifiedDateDto, @Param("id_periodo") id_periodo: number) {
|
||||
return this.periodoService.modifiedDate(data, id_periodo)
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Get('range')
|
||||
getRange(
|
||||
@Query('p1') p1: number,
|
||||
@Query('p2') p2: number,
|
||||
) {
|
||||
return this.periodoService.getPeriodosEnRango(p1, p2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Periodo } from './entities/periodo.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Between, Repository } from 'typeorm';
|
||||
import { CreatePeriodoDto, ModifiedDateDto } from './dto/create-periodo.dto';
|
||||
|
||||
@Injectable()
|
||||
@@ -69,4 +69,50 @@ export class PeriodoService {
|
||||
async modifiedDate(data: ModifiedDateDto, id_periodo) {
|
||||
return this.periodoRepository.update(id_periodo, data)
|
||||
}
|
||||
|
||||
async comparePeriodos(id1: number, id2: number) {
|
||||
const periodo1 = await this.periodoRepository.findOne({
|
||||
where: { id_periodo: id1 },
|
||||
});
|
||||
|
||||
const periodo2 = await this.periodoRepository.findOne({
|
||||
where: { id_periodo: id2 },
|
||||
});
|
||||
|
||||
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,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
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',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user