merge Axel
This commit is contained in:
@@ -20,7 +20,7 @@ export class PeriodoController {
|
|||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
@Post()
|
@Post()
|
||||||
create(@Body() data: CreatePeriodoDto) {
|
create(@Body() data: CreatePeriodoDto) {
|
||||||
return this.periodoService.create(data);
|
return this.periodoService.create(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,21 +39,21 @@ export class PeriodoController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard, RolesGuard)
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
||||||
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
@Roles(Role.ADMINISTRADOR, Role.SUPER_ADMINISTRADOR)
|
||||||
@Get('compare')
|
@Get('compare')
|
||||||
compare(
|
compare(
|
||||||
@Query('p1') p1: number,
|
@Query('p1') p1: number,
|
||||||
@Query('p2') p2: number,
|
@Query('p2') p2: number,
|
||||||
) {
|
) {
|
||||||
return this.periodoService.comparePeriodos(p1, p2);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export class PeriodoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findAll() {
|
async findAll() {
|
||||||
return this.periodoRepository.find({order:{'id_periodo':"DESC"}});
|
return this.periodoRepository.find({ order: { 'id_periodo': "DESC" } });
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPeriodoActivo(): Promise<Periodo> {
|
async getPeriodoActivo(): Promise<Periodo> {
|
||||||
@@ -71,48 +71,48 @@ export class PeriodoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async comparePeriodos(id1: number, id2: number) {
|
async comparePeriodos(id1: number, id2: number) {
|
||||||
const periodo1 = await this.periodoRepository.findOne({
|
const periodo1 = await this.periodoRepository.findOne({
|
||||||
where: { id_periodo: id1 },
|
where: { id_periodo: id1 },
|
||||||
});
|
});
|
||||||
|
|
||||||
const periodo2 = await this.periodoRepository.findOne({
|
const periodo2 = await this.periodoRepository.findOne({
|
||||||
where: { id_periodo: id2 },
|
where: { id_periodo: id2 },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!periodo1 || !periodo2) {
|
if (!periodo1 || !periodo2) {
|
||||||
throw new NotFoundException('Uno de los periodos no existe');
|
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 {
|
async getPeriodosEnRango(id1: number, id2: number) {
|
||||||
periodo1: {
|
const min = Math.min(id1, id2);
|
||||||
id: periodo1.id_periodo,
|
const max = Math.max(id1, id2);
|
||||||
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) {
|
return this.periodoRepository.find({
|
||||||
const min = Math.min(id1, id2);
|
where: {
|
||||||
const max = Math.max(id1, id2);
|
id_periodo: Between(min, max),
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
id_periodo: 'ASC',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return this.periodoRepository.find({
|
|
||||||
where: {
|
|
||||||
id_periodo: Between(min, max),
|
|
||||||
},
|
|
||||||
order: {
|
|
||||||
id_periodo: 'ASC',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user