diff --git a/src/operations/operations.service.ts b/src/operations/operations.service.ts index 2f7e4c0..43c8669 100644 --- a/src/operations/operations.service.ts +++ b/src/operations/operations.service.ts @@ -45,25 +45,31 @@ export class OperationsService { let newSaldo: number; if (transaccion === 'Inscripcion') { - newSaldo = await this.personaService.saldo(idPersona); - const persona = await this.personaService.findById(idPersona); - - const alumno = await this.alumnoService.findOneById( - Number(persona.numeroIdentificar), - ); if (!plataforma) { throw new NotFoundException('Debe de colocar una plataforma'); } - const periodo = await this.periodoService.getLatestPeriodo(); - const plataform = await this.plataformaService.getByName(plataforma); + const [saldoActual, persona, periodo, plataformaData] = await Promise.all( + [ + this.personaService.saldo(idPersona), + this.personaService.findById(idPersona), + this.periodoService.getLatestPeriodo(), + this.plataformaService.getByName(plataforma), + ], + ); + + const alumno = await this.alumnoService.findOneById( + Number(persona.numeroIdentificar), + ); await this.alumnoInscritoServie.create({ id_cuenta: alumno.id_cuenta, id_periodo: periodo.id_periodo, - id_plataforma: plataform.id_plataforma, + id_plataforma: plataformaData.id_plataforma, }); + + newSaldo = saldoActual; } else { newSaldo = await this.personaService.updateSaldo(idPersona, cantidad); }