added operations and EP abonoKiosco
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
import { IsNumber } from 'class-validator';
|
||||
|
||||
export class abonoKioscoDto {
|
||||
@IsNumber()
|
||||
monto: number;
|
||||
|
||||
@IsNumber()
|
||||
idKiosco: number;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { OperationsController } from './operations.controller';
|
||||
import { OperationsService } from './operations.service';
|
||||
|
||||
describe('OperationsController', () => {
|
||||
let controller: OperationsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<OperationsController>(OperationsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Controller, Post, Body, UseGuards, Req } from '@nestjs/common';
|
||||
import { OperationsService } from './operations.service';
|
||||
import { abonoKioscoDto } from './dto/create-operation.dto';
|
||||
import { JwtAuthGuard } from 'src/persona/jwt.guard';
|
||||
|
||||
@Controller('operations')
|
||||
export class OperationsController {
|
||||
constructor(private readonly operationsService: OperationsService) {}
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('abonoKiosco')
|
||||
depositKiosco(@Body() abonoKiosco: abonoKioscoDto, @Req() req) {
|
||||
const idPersona = req.user.idPersona;
|
||||
return this.operationsService.depositKiosco(abonoKiosco, idPersona);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { OperationsService } from './operations.service';
|
||||
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';
|
||||
|
||||
@Module({
|
||||
imports: [TransaccionModule, PagoKioscoModule, PersonaModule],
|
||||
controllers: [OperationsController],
|
||||
providers: [OperationsService],
|
||||
})
|
||||
export class OperationsModule {}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { OperationsService } from './operations.service';
|
||||
|
||||
describe('OperationsService', () => {
|
||||
let service: OperationsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [OperationsService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<OperationsService>(OperationsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PagoKioscoService } from 'src/pago-kiosco/pago-kiosco.service';
|
||||
import { PersonaService } from 'src/persona/persona.service';
|
||||
import { TransaccionService } from 'src/transaccion/transaccion.service';
|
||||
|
||||
@Injectable()
|
||||
export class OperationsService {
|
||||
constructor(
|
||||
private readonly transaccionService: TransaccionService,
|
||||
private readonly pagoKioscoService: PagoKioscoService,
|
||||
private readonly personaService: PersonaService,
|
||||
) {}
|
||||
|
||||
async depositKiosco({ monto, idKiosco }, idPersona: number) {
|
||||
const today = new Date().toString();
|
||||
|
||||
const transaccion = {
|
||||
idNombreTransaccion: 1,
|
||||
idPersona,
|
||||
fecha: today,
|
||||
tipoTransaccion: 2,
|
||||
};
|
||||
|
||||
const responseTransaccion = this.transaccionService.create(transaccion);
|
||||
|
||||
const pagoKiosco = {
|
||||
idTransaccion: (await responseTransaccion).idTransaccion,
|
||||
monto,
|
||||
fecha: today,
|
||||
idKiosco,
|
||||
pagoPatronatoCreado: false,
|
||||
};
|
||||
|
||||
this.pagoKioscoService.create(pagoKiosco);
|
||||
|
||||
const newSaldo = this.personaService.updateSaldo(idPersona, monto);
|
||||
|
||||
return newSaldo;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user