From af0602b7dfacf773d705d993289ebe3ad6132d84 Mon Sep 17 00:00:00 2001 From: lemuel Date: Thu, 3 Nov 2022 11:37:49 -0600 Subject: [PATCH] listo para pruebas passcode --- src/passcode/passcode.service.ts | 33 +++++++++---------------- src/prestamo/dto/output/prestamo.dto.ts | 3 +++ src/prestamo/prestamo.module.ts | 2 ++ src/prestamo/prestamo.service.ts | 26 ++++++++++++++++--- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/passcode/passcode.service.ts b/src/passcode/passcode.service.ts index 084baa1..34c47c9 100644 --- a/src/passcode/passcode.service.ts +++ b/src/passcode/passcode.service.ts @@ -21,18 +21,18 @@ export class PasscodeService { ) {} crearPasscode(prestamo: Prestamo) { - const aux = { - 1: '00000', - 2: '0000', - 3: '000', - 4: '00', - 5: '0', - 6: '', - }; - return this.repository .save(this.repository.create({ prestamo })) .then((passcodeInterno) => { + const aux = { + 1: '00000', + 2: '0000', + 3: '000', + 4: '00', + 5: '0', + 6: '', + }; + passcodeInterno.passcode = `${prestamo.equipo.carrito.id_carrito}${ aux[passcodeInterno.id_passcode.toString().length] }${passcodeInterno.id_passcode}${Math.floor( @@ -101,16 +101,7 @@ export class PasscodeService { }); } - // findPasscode(id_prestamo: number) { - // return this.repository - // .findOne({ where: { prestamo: { id_prestamo } } }) - // .then(async (passcode) => { - // if (!passcode) - // throw new BadRequestException({ - // message: `Este passcode no existe`, - // code: 6, - // }); - // return passcode.passcode; - // }); - // } + findByPrestamo(prestamo: Prestamo) { + return this.repository.findOne({ where: { prestamo } }); + } } diff --git a/src/prestamo/dto/output/prestamo.dto.ts b/src/prestamo/dto/output/prestamo.dto.ts index c83aac2..5309df4 100644 --- a/src/prestamo/dto/output/prestamo.dto.ts +++ b/src/prestamo/dto/output/prestamo.dto.ts @@ -20,6 +20,9 @@ export class PrestamoOutputDto { @Expose() hora_max_recoger; + @Expose() + passcode; + @Expose() @Type(() => EquipoMinOutputDto) equipo; diff --git a/src/prestamo/prestamo.module.ts b/src/prestamo/prestamo.module.ts index 8d293a5..ad83016 100644 --- a/src/prestamo/prestamo.module.ts +++ b/src/prestamo/prestamo.module.ts @@ -16,6 +16,7 @@ import { InstitucionTipoCarritoModule } from '../institucion-tipo-carrito/instit import { InstitucionTipoEntradaModule } from '../institucion-tipo-entrada/institucion-tipo-entrada.module'; import { InstitucionUsuarioModule } from '../institucion-usuario/institucion-usuario.module'; import { OperadorModule } from '../operador/operador.module'; +import { PasscodeModule } from '../passcode/passcode.module'; import { ModuloModule } from '../modulo/modulo.module'; import { MultaModule } from '../multa/multa.module'; import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module'; @@ -35,6 +36,7 @@ import { ValidarUsuarioModule } from '../validar-usuario/validar-usuario.module' forwardRef(() => MultaModule), OperadorModule, PassportModule.register({ defaultStrategy: 'jwt' }), + forwardRef(() => PasscodeModule), TypeOrmModule.forFeature([ Prestamo, InformacionPrestamoView, diff --git a/src/prestamo/prestamo.service.ts b/src/prestamo/prestamo.service.ts index 86b27a5..e0e931d 100644 --- a/src/prestamo/prestamo.service.ts +++ b/src/prestamo/prestamo.service.ts @@ -37,6 +37,7 @@ import { InstitucionUsuarioService } from '../institucion-usuario/institucion-us import { ModuloService } from '../modulo/modulo.service'; import { MultaService } from '../multa/multa.service'; import { OperadorService } from '../operador/operador.service'; +import { PasscodeService } from '../passcode/passcode.service'; import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service'; import { UsuarioService } from '../usuario/usuario.service'; @@ -50,6 +51,8 @@ export class PrestamoService { private fullInformacionPrestamoView: Repository, @InjectRepository(PrestamoInformacionView) private prestamoInformacionView: Repository, + @Inject(forwardRef(() => PasscodeService)) + private passcodeService: PasscodeService, private appGateway: AppGateway, private equipoService: EquipoService, private institucionService: InstitucionService, @@ -241,7 +244,7 @@ export class PrestamoService { .then((prestamo) => { // Actualizo la interfaz del operador this.appGateway.actualizarOperador(modulo.institucion.id_institucion); - return prestamo; + return this.prestamoPasscode(prestamo); }); } @@ -616,7 +619,8 @@ export class PrestamoService { .then((infoPrestamo) => { if (!infoPrestamo) throw new NotFoundException('No existe este id préstamo.'); - return this.repository.create({ + + const prestamo = this.repository.create({ id_prestamo: infoPrestamo.id_prestamo, activo: infoPrestamo.activo === 1, cancelado_operador: infoPrestamo.cancelado_operador === 1, @@ -649,6 +653,8 @@ export class PrestamoService { status: { id_status: infoPrestamo.id_status }, }, }); + + return this.prestamoPasscode(prestamo); }); } @@ -660,7 +666,8 @@ export class PrestamoService { throw new NotFoundException( 'Este usuario no tiene un préstamo activo.', ); - return this.repository.create({ + + const prestamo = this.repository.create({ id_prestamo: infoPrestamo.id_prestamo, activo: infoPrestamo.activo === 1, fecha_inicio: infoPrestamo.fecha_inicio, @@ -690,6 +697,8 @@ export class PrestamoService { status: { id_status: infoPrestamo.id_status }, }, }); + + return this.prestamoPasscode(prestamo); }); } @@ -740,6 +749,17 @@ export class PrestamoService { }); } + private prestamoPasscode(prestamo: Prestamo) { + if ( + prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 4 || + prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 5 + ) + return this.passcodeService + .findByPrestamo(prestamo) + .then((passcode) => ({ ...prestamo, passcode: passcode.passcode })); + return prestamo; + } + async regresar( operadorRegreso: Operador, modulo: Modulo,