pruebas2
This commit is contained in:
@@ -6,7 +6,10 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Modulo } from '../modulo/entity/modulo.entity';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { Passcode } from './entity/passcode.entity';
|
||||
import { Prestamo } from '../prestamo/entity/prestamo.entity';
|
||||
import { PrestamoService } from '../prestamo/prestamo.service';
|
||||
|
||||
@Injectable()
|
||||
@@ -17,54 +20,56 @@ export class PasscodeService {
|
||||
private prestamoService: PrestamoService,
|
||||
) {}
|
||||
|
||||
crearPasscode(id_carrito, id_prestamo) {
|
||||
const prestamo = {
|
||||
crearPasscode(prestamo: Prestamo) {
|
||||
const aux = {
|
||||
1: '00000',
|
||||
2: '0000',
|
||||
3: '000',
|
||||
4: '00',
|
||||
5: '0',
|
||||
6: '',
|
||||
};
|
||||
const passcode =
|
||||
id_carrito +
|
||||
prestamo[id_prestamo.length] +
|
||||
id_prestamo +
|
||||
Math.floor(Math.random() * 99999 + 10000).toString();
|
||||
|
||||
this.repository.save(
|
||||
this.repository.create({
|
||||
passcode,
|
||||
prestamo: { id_prestamo },
|
||||
}),
|
||||
);
|
||||
return passcode;
|
||||
return this.repository
|
||||
.save(this.repository.create({ prestamo }))
|
||||
.then((passcodeInterno) => {
|
||||
passcodeInterno.passcode = `${prestamo.equipo.carrito.id_carrito}${
|
||||
aux[passcodeInterno.id_passcode.toString().length]
|
||||
}${passcodeInterno.id_passcode}${Math.floor(
|
||||
Math.random() * 99999 + 10000,
|
||||
)}`;
|
||||
return this.repository.save(passcodeInterno);
|
||||
});
|
||||
}
|
||||
|
||||
async devolverEquipo(passcode, operador) {
|
||||
const passcodeInterno = await this.findByPasscode(passcode, true);
|
||||
|
||||
// return this.prestamoService
|
||||
// .regresarIdPrestamo(
|
||||
// operador.id_operador,
|
||||
// passcodeInterno.prestamo.id_prestamo,
|
||||
// )
|
||||
// .then((_) => {
|
||||
// return { code: 1 };
|
||||
// });
|
||||
devolverEquipo(operador: Operador, modulo: Modulo, passcode: string) {
|
||||
return this.findByPasscode(passcode, true)
|
||||
.then((passcodeInterno) =>
|
||||
this.prestamoService.regresar(
|
||||
operador,
|
||||
modulo,
|
||||
passcodeInterno.prestamo,
|
||||
1,
|
||||
),
|
||||
)
|
||||
.then((_) => ({ code: 1 }));
|
||||
}
|
||||
|
||||
async entregarEquipo(passcode, estatus, operador) {
|
||||
async entregarEquipo(
|
||||
operador: Operador,
|
||||
modulo: Modulo,
|
||||
passcode: string,
|
||||
estatus: number,
|
||||
) {
|
||||
const passcodeInterno = await this.findByPasscode(passcode, false);
|
||||
|
||||
if (estatus) {
|
||||
if (passcodeInterno.abrio != estatus)
|
||||
passcodeInterno.abrio = estatus === 1 ? true : false;
|
||||
// return this.prestamoService
|
||||
// .entregar(passcodeInterno.prestamo.id_prestamo, operador.id_operador)
|
||||
// .then((_) => {
|
||||
// return this.repository.save(passcodeInterno).then((_) => {
|
||||
// return { code: 1 };
|
||||
// });
|
||||
// });
|
||||
if (passcodeInterno.abrio != (estatus === 1))
|
||||
passcodeInterno.abrio = estatus === 1;
|
||||
return this.prestamoService
|
||||
.entregar(operador, modulo, passcodeInterno.prestamo.id_prestamo)
|
||||
.then((_) => this.repository.save(passcodeInterno))
|
||||
.then((_) => ({ code: 1 }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,16 +101,16 @@ 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;
|
||||
});
|
||||
}
|
||||
// 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;
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user