added request to api AT
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { Controller, Get, Post, Body } from '@nestjs/common';
|
||||
import { AbonoTicketService } from './abono-ticket.service';
|
||||
import { CreateAbonoTicketDto } from './dto/create-abono-ticket.dto';
|
||||
import { UpdateAbonoTicketDto } from './dto/update-abono-ticket.dto';
|
||||
@@ -11,24 +11,4 @@ export class AbonoTicketController {
|
||||
create(@Body() createAbonoTicketDto: CreateAbonoTicketDto) {
|
||||
return this.abonoTicketService.create(createAbonoTicketDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.abonoTicketService.findAll();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.abonoTicketService.findOne(+id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateAbonoTicketDto: UpdateAbonoTicketDto) {
|
||||
return this.abonoTicketService.update(+id, updateAbonoTicketDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.abonoTicketService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ import { AbonoTicket } from './entities/abono-ticket.entity';
|
||||
imports: [TypeOrmModule.forFeature([AbonoTicket])],
|
||||
controllers: [AbonoTicketController],
|
||||
providers: [AbonoTicketService],
|
||||
exports: [AbonoTicketService],
|
||||
})
|
||||
export class AbonoTicketModule {}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { CreateAbonoTicketDto } from './dto/create-abono-ticket.dto';
|
||||
import { UpdateAbonoTicketDto } from './dto/update-abono-ticket.dto';
|
||||
import { AbonoTicket } from './entities/abono-ticket.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
@@ -11,25 +10,20 @@ export class AbonoTicketService {
|
||||
@InjectRepository(AbonoTicket)
|
||||
private readonly abonoTicketRepository: Repository<AbonoTicket>,
|
||||
) {}
|
||||
|
||||
async findByTransaccion(transaccion) {
|
||||
const abonoTicket = await this.abonoTicketRepository.findOne({
|
||||
where: { transaccion },
|
||||
});
|
||||
if (!abonoTicket) {
|
||||
throw new NotFoundException('abonoTicket not found');
|
||||
}
|
||||
return abonoTicket;
|
||||
}
|
||||
|
||||
async create(createAbonoTicketDto: CreateAbonoTicketDto) {
|
||||
const create = this.abonoTicketRepository.create(createAbonoTicketDto);
|
||||
await this.abonoTicketRepository.save(create);
|
||||
return 'success';
|
||||
}
|
||||
|
||||
findAll() {
|
||||
return `This action returns all abonoTicket`;
|
||||
}
|
||||
|
||||
findOne(id: number) {
|
||||
return `This action returns a #${id} abonoTicket`;
|
||||
}
|
||||
|
||||
update(id: number, updateAbonoTicketDto: UpdateAbonoTicketDto) {
|
||||
return `This action updates a #${id} abonoTicket`;
|
||||
}
|
||||
|
||||
remove(id: number) {
|
||||
return `This action removes a #${id} abonoTicket`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,15 @@ import { OperationsController } from './operations.controller';
|
||||
import { TransaccionModule } from 'src/transaccion/transaccion.module';
|
||||
import { PagoKioscoModule } from 'src/pago-kiosco/pago-kiosco.module';
|
||||
import { PersonaModule } from 'src/persona/persona.module';
|
||||
import { AbonoTicketModule } from 'src/abono-ticket/abono-ticket.module';
|
||||
|
||||
@Module({
|
||||
imports: [TransaccionModule, PagoKioscoModule, PersonaModule],
|
||||
imports: [
|
||||
TransaccionModule,
|
||||
PagoKioscoModule,
|
||||
PersonaModule,
|
||||
AbonoTicketModule,
|
||||
],
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
import { AbonoTicketService } from 'src/abono-ticket/abono-ticket.service';
|
||||
import { PagoKioscoService } from 'src/pago-kiosco/pago-kiosco.service';
|
||||
import { PersonaService } from 'src/persona/persona.service';
|
||||
import { TransaccionService } from 'src/transaccion/transaccion.service';
|
||||
@@ -10,6 +11,7 @@ export class OperationsService {
|
||||
private readonly transaccionService: TransaccionService,
|
||||
private readonly pagoKioscoService: PagoKioscoService,
|
||||
private readonly personaService: PersonaService,
|
||||
private readonly abonoTicket: AbonoTicketService,
|
||||
) {}
|
||||
|
||||
async depositKiosco({ cantidad, idKiosco, transaccion }, idPersona: number) {
|
||||
@@ -23,7 +25,12 @@ export class OperationsService {
|
||||
};
|
||||
|
||||
const responseTransaccion = this.transaccionService.create(transaction);
|
||||
console.log(responseTransaccion);
|
||||
|
||||
const newSaldo = this.personaService.updateSaldo(idPersona, cantidad);
|
||||
|
||||
const abonoTicket = this.abonoTicket.findByTransaccion(
|
||||
(await responseTransaccion).idTransaccion,
|
||||
);
|
||||
const pagoKiosco = {
|
||||
idTransaccion: (await responseTransaccion).idTransaccion,
|
||||
monto: cantidad,
|
||||
@@ -34,21 +41,19 @@ export class OperationsService {
|
||||
|
||||
this.pagoKioscoService.create(pagoKiosco);
|
||||
|
||||
const newSaldo = this.personaService.updateSaldo(idPersona, cantidad);
|
||||
const res = await axios.post(
|
||||
`${process.env.API_AT_URL}/operations/receipt`,
|
||||
{
|
||||
id_cuenta: idPersona,
|
||||
monto: cantidad,
|
||||
fecha_recibo: today,
|
||||
folio_recibo: (await abonoTicket).idTicket,
|
||||
},
|
||||
);
|
||||
|
||||
// const res = await axios.post(
|
||||
// `${process.env.API_AT_URL}/operations/receipt`,
|
||||
// {
|
||||
// id_cuenta: idPersona,
|
||||
// monto: cantidad,
|
||||
// fecha_recibo: today,
|
||||
// folio_recibo: `FOL-${Date.now()}`,
|
||||
// },
|
||||
// );
|
||||
|
||||
// if (res.status !== 200) {
|
||||
// throw new Error('Error al registrar crédito en API externa');
|
||||
// }
|
||||
if (res.status !== 200) {
|
||||
throw new Error('Error al registrar crédito en API externa');
|
||||
}
|
||||
|
||||
return newSaldo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user