prueba
This commit is contained in:
@@ -15,8 +15,9 @@ import {
|
||||
@Column({ type: String, nullable: false })
|
||||
passcode: string;
|
||||
|
||||
@Column({ type: Boolean, nullable: true })
|
||||
@Column({ type: Boolean, nullable: true, default: false })
|
||||
abrio: boolean
|
||||
|
||||
|
||||
@OneToOne(() => Prestamo, (Prestamo) => Prestamo.id_prestamo, {
|
||||
eager: true,
|
||||
|
||||
@@ -77,7 +77,7 @@ export class PasscodeController {
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
|
||||
return this.passcodeService.entregarEquipo(body.passcode, body.estatus);
|
||||
return this.passcodeService.entregarEquipo(body.passcode, body.estatus, operador);
|
||||
}
|
||||
|
||||
@Serealize(DevolucionOutputDto)
|
||||
@@ -110,6 +110,6 @@ export class PasscodeController {
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
|
||||
return this.passcodeService.devolverEquipo(body.passcode);
|
||||
return this.passcodeService.devolverEquipo(body.passcode, operador);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export class PasscodeService {
|
||||
private prestamoService: PrestamoService,
|
||||
){}
|
||||
|
||||
crearPasscode(id_tipo_carrito, id_prestamo){
|
||||
crearPasscode(id_carrito, id_prestamo){
|
||||
const prestamo = {
|
||||
1: "00000",
|
||||
2: "0000",
|
||||
@@ -21,8 +21,7 @@ export class PasscodeService {
|
||||
5: "0",
|
||||
}
|
||||
|
||||
// const passcode = "30" + prestamo[id_prestamo.length] + id_prestamo + Math.floor(Math.random() * 99999).toString()
|
||||
const passcode = id_tipo_carrito + prestamo[id_prestamo.length] + id_prestamo + Math.floor((Math.random() * 999999) + 100000).toString()
|
||||
const passcode = id_carrito + prestamo[id_prestamo.length] + id_prestamo + Math.floor((Math.random() * 99999) + 10000).toString()
|
||||
this.repository.save(
|
||||
this.repository.create({
|
||||
passcode,
|
||||
@@ -32,53 +31,54 @@ export class PasscodeService {
|
||||
return passcode
|
||||
}
|
||||
|
||||
devolverEquipo(passcode){
|
||||
async devolverEquipo(passcode, operador){
|
||||
passcode += ''
|
||||
const id_prestamo = passcode.substring(2,7)
|
||||
const passcodeInterno = await this.findByPasscode(passcode)
|
||||
|
||||
return this.prestamoService.regresarIdPrestamo(
|
||||
5,
|
||||
parseInt(id_prestamo)
|
||||
operador.id_operador,
|
||||
passcodeInterno.prestamo.id_prestamo
|
||||
).then((_)=> {
|
||||
return {code: 1}
|
||||
})
|
||||
}
|
||||
|
||||
entregarEquipo(passcode, estatus){
|
||||
passcode += ''
|
||||
let id_prestamo = passcode.substring(2,7)
|
||||
return this.prestamoService.entregar(parseInt(id_prestamo), 5).then((prestamo)=>{
|
||||
if(prestamo){
|
||||
// return this.repository.createQueryBuilder()
|
||||
// .update()
|
||||
// .set({abrio: estatus})
|
||||
// .where("id_prestamo = :id_prestamo",{id_prestamo: prestamo.id_prestamo})
|
||||
// .execute()
|
||||
return {code: 1}
|
||||
}
|
||||
})
|
||||
async entregarEquipo(passcode, estatus, operador){
|
||||
const passcodeInterno = await this.findByPasscode(passcode)
|
||||
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}
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
findByPasscode(passcode: string, id_locker: string){
|
||||
findByPasscode(passcode: string, id_locker ?: string){
|
||||
let door = ""
|
||||
return this.repository.findOne({where: {passcode}})
|
||||
return this.repository.findOne({where: {passcode, abrio: false}})
|
||||
.then(async(passcode) => {
|
||||
if(!passcode)
|
||||
throw new BadRequestException({
|
||||
message: `Este passcode no existe`, code: 6
|
||||
});
|
||||
|
||||
await this.prestamoService.findById(passcode.prestamo.id_prestamo).then((prestamo)=>{
|
||||
if(prestamo.equipo.carrito.id_carrito != parseInt(id_locker)){
|
||||
console.log(prestamo.equipo.carrito.id_carrito)
|
||||
throw new BadRequestException({
|
||||
message: `El id_locker no corresponde`, code: 6
|
||||
});
|
||||
}
|
||||
door = prestamo.equipo.equipo.substring(1,3)
|
||||
|
||||
})
|
||||
return {...passcode, code: 1, id_locker, door: parseInt(door)}
|
||||
if(!passcode){
|
||||
throw new BadRequestException({
|
||||
message: `Este passcode no existe`, code: 6
|
||||
});
|
||||
}
|
||||
if(id_locker){
|
||||
await this.prestamoService.findById(passcode.prestamo.id_prestamo).then((prestamo)=>{
|
||||
if(prestamo.equipo.carrito.id_carrito != parseInt(id_locker)){
|
||||
throw new BadRequestException({
|
||||
message: `El id_locker no corresponde`, code: 4
|
||||
});
|
||||
}
|
||||
door = prestamo.equipo.equipo.substring(1,3)
|
||||
|
||||
})
|
||||
return {...passcode, code: 1, id_locker, door: parseInt(door)}
|
||||
}
|
||||
return passcode
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -381,7 +381,9 @@ export class PrestamoController {
|
||||
const usuario: Usuario = req.user.usuario;
|
||||
|
||||
this.validarUsuarioService.validarUsuario(usuario);
|
||||
return this.prestamoService.findByIdUsuario(parseInt(query.id_usuario));
|
||||
return this.prestamoService.findByIdUsuario(parseInt(query.id_usuario)).catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
|
||||
@Serealize(PrestamoEquipoOutputDto)
|
||||
|
||||
@@ -209,7 +209,7 @@ export class PrestamoService {
|
||||
.then((prestamo) => {
|
||||
let passcode = ""
|
||||
if(id_tipo_carrito === 4 || id_tipo_carrito === 5)
|
||||
passcode = this.passcodeService.crearPasscode(id_tipo_carrito.toString(), prestamo.id_prestamo.toString())
|
||||
passcode = this.passcodeService.crearPasscode(prestamo.equipo.carrito.id_carrito.toString(), prestamo.id_prestamo.toString())
|
||||
|
||||
this.appGateway.actualizarOperador(modulo.institucion.id_institucion);
|
||||
return {...prestamo, passcode};
|
||||
|
||||
Reference in New Issue
Block a user