getPeriodoActivoWhitoutError
This commit is contained in:
@@ -32,12 +32,21 @@ export class PeriodoService {
|
||||
return periodo;
|
||||
}
|
||||
|
||||
async getPeriodoActivoWhitoutError(): Promise<Periodo | null> {
|
||||
const periodo = await this.periodoRepository.findOne({
|
||||
where: { activo: true },
|
||||
order: { id_periodo: 'DESC' },
|
||||
});
|
||||
|
||||
return periodo;
|
||||
}
|
||||
|
||||
async delete(id_periodo: number) {
|
||||
this.periodoRepository.delete(id_periodo)
|
||||
await this.periodoRepository.delete(id_periodo)
|
||||
}
|
||||
|
||||
async periodoDisable(id_periodo:number) {
|
||||
this.periodoRepository.update(id_periodo, { activo: false })
|
||||
await this.periodoRepository.update(id_periodo, { activo: false })
|
||||
}
|
||||
|
||||
async create(data: CreatePeriodoDto) {
|
||||
@@ -47,9 +56,11 @@ export class PeriodoService {
|
||||
throw new BadRequestException("El periodo ya existe")
|
||||
}
|
||||
|
||||
const periodoActive = await this.getPeriodoActivo();
|
||||
const periodoActive = await this.getPeriodoActivoWhitoutError();
|
||||
|
||||
this.periodoDisable(periodoActive.id_periodo)
|
||||
if(periodoActive){
|
||||
await this.periodoDisable(periodoActive.id_periodo)
|
||||
}
|
||||
|
||||
const create = this.periodoRepository.create(data)
|
||||
return this.periodoRepository.save(create)
|
||||
|
||||
Reference in New Issue
Block a user