return to past
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import { Injectable, InternalServerErrorException } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PagoKioscoService } from 'src/pago-kiosco/pago-kiosco.service';
|
||||
import { PagoPatronatoService } from 'src/pago-patronato/pago-patronato.service';
|
||||
import { PersonaService } from 'src/persona/persona.service';
|
||||
import { TransaccionService } from 'src/transaccion/transaccion.service';
|
||||
|
||||
@@ -11,42 +9,8 @@ export class OperationsService {
|
||||
private readonly transaccionService: TransaccionService,
|
||||
private readonly pagoKioscoService: PagoKioscoService,
|
||||
private readonly personaService: PersonaService,
|
||||
private readonly pagoPatronatoService: PagoPatronatoService,
|
||||
) {}
|
||||
|
||||
async login() {
|
||||
try {
|
||||
const response = await axios.post(`${process.env.API_AT_URL}/user`, {
|
||||
usuario: process.env.USER,
|
||||
password: process.env.PASS,
|
||||
});
|
||||
|
||||
return response.data.access_token;
|
||||
} catch (error) {
|
||||
throw new InternalServerErrorException(
|
||||
'Error al autenticar con API externa',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async addCredit(token: string, data: any) {
|
||||
try {
|
||||
const response = await axios.post(
|
||||
`${process.env.API_AT_URL}/operations/receipt`,
|
||||
data,
|
||||
{
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
},
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
throw new InternalServerErrorException(
|
||||
'Error al registrar crédito en API externa',
|
||||
error,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async depositKiosco({ cantidad, idKiosco, transaccion }, idPersona: number) {
|
||||
const today = new Date().toString();
|
||||
|
||||
@@ -59,8 +23,6 @@ export class OperationsService {
|
||||
|
||||
const responseTransaccion = this.transaccionService.create(transaction);
|
||||
|
||||
const newSaldo = this.personaService.updateSaldo(idPersona, cantidad);
|
||||
|
||||
const pagoKiosco = {
|
||||
idTransaccion: (await responseTransaccion).idTransaccion,
|
||||
monto: cantidad,
|
||||
@@ -69,20 +31,9 @@ export class OperationsService {
|
||||
pagoPatronatoCreado: false,
|
||||
};
|
||||
|
||||
const pagoK = this.pagoKioscoService.create(pagoKiosco);
|
||||
this.pagoKioscoService.create(pagoKiosco);
|
||||
|
||||
const pagoP = this.pagoPatronatoService.findById(
|
||||
(await pagoK).idPagoKiosco,
|
||||
);
|
||||
|
||||
const token = await this.login();
|
||||
|
||||
await this.addCredit(token, {
|
||||
id_cuenta: idPersona,
|
||||
monto: cantidad,
|
||||
fecha_recibo: today,
|
||||
folio_recibo: (await pagoP)?.folio,
|
||||
});
|
||||
const newSaldo = this.personaService.updateSaldo(idPersona, cantidad);
|
||||
|
||||
return newSaldo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user