This commit is contained in:
Andres2908
2022-09-06 23:22:38 -05:00
parent 476a8f62d0
commit 906b036bd4
5 changed files with 110 additions and 36 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ import { Socket, Server } from 'socket.io';
@WebSocketGateway({
cors: {
origin: [
// 'http://localhost:3176',
'http://localhost:3176',
// 'http://localhost:3186',
// 'http://132.248.80.196:3155',
// 'http://132.248.80.196:3185',
+2 -1
View File
@@ -20,6 +20,7 @@ import { PasscodeOutputDto } from './dto/output/passcode.dto';
@Controller('passcode')
@ApiTags('passcode')
export class PasscodeController {
constructor(private passcodeService: PasscodeService) {}
@Serealize(PasscodeOutputDto)
@@ -76,7 +77,7 @@ export class PasscodeController {
'No tienes los permisos necesarios para realizar esta acción.',
);
return this.passcodeService.entregarEquipo(body.passcode);
return this.passcodeService.entregarEquipo(body.passcode, body.estatus);
}
@Serealize(DevolucionOutputDto)
+41 -15
View File
@@ -10,7 +10,6 @@ export class PasscodeService {
@InjectRepository(Passcode) private repository: Repository<Passcode>,
@Inject(forwardRef(() => PrestamoService))
private prestamoService: PrestamoService,
){}
crearPasscode(id_tipo_carrito, id_prestamo){
@@ -22,9 +21,8 @@ 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() * 99999).toString()
// console.log(passcode)
// 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()
this.repository.save(
this.repository.create({
passcode,
@@ -34,20 +32,31 @@ export class PasscodeService {
return passcode
}
entregarEquipo(passcode){
passcode += ''
let id_prestamo = passcode.substring(2,8)
return this.prestamoService.entregar(parseInt(id_prestamo), 5);
}
devolverEquipo(passcode){
passcode += ''
const id_prestamo = passcode.substring(2,8)
const id_prestamo = passcode.substring(2,7)
return this.prestamoService.regresarIdPrestamo(
5,
parseInt(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}
}
})
}
findByPasscode(passcode: string, id_locker: string){
@@ -55,15 +64,32 @@ export class PasscodeService {
return this.repository.findOne({where: {passcode}})
.then(async(passcode) => {
if(!passcode)
throw new BadRequestException(
`Este passcode no existe`,
);
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)}
})
}
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
})
}
}
+1 -1
View File
@@ -411,7 +411,7 @@ export class PrestamoController {
throw new ForbiddenException(
'No tienes los permisos necesarios para realizar esta acción.',
);
return this.prestamoService.findById(parseInt(query.id_prestamo));
return this.prestamoService.findByIdController(parseInt(query.id_prestamo));
}
@Serealize(PrestamoOutputDto)
+65 -18
View File
@@ -31,6 +31,7 @@ import { OperadorService } from '../operador/operador.service';
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
import { UsuarioService } from '../usuario/usuario.service';
import { PasscodeService } from '../passcode/passcode.service';
import { Passcode } from 'src/passcode/entity/passcode.entity';
@Injectable()
export class PrestamoService {
@@ -206,11 +207,10 @@ export class PrestamoService {
),
)
.then((prestamo) => {
// if(id_tipo_carrito === 4 || id_tipo_carrito === 5){
// const passcode = this.passcodeService.crearPasscode(id_tipo_carrito.toString(), prestamo.id_prestamo.toString())
// this.appGateway.actualizarOperador(modulo.institucion.id_institucion);
// }
const passcode = this.passcodeService.crearPasscode(id_tipo_carrito.toString(), prestamo.id_prestamo.toString())
let passcode = ""
if(id_tipo_carrito === 4 || id_tipo_carrito === 5)
passcode = this.passcodeService.crearPasscode(id_tipo_carrito.toString(), prestamo.id_prestamo.toString())
this.appGateway.actualizarOperador(modulo.institucion.id_institucion);
return {...prestamo, passcode};
});
@@ -264,10 +264,8 @@ export class PrestamoService {
: null;
this.validacionBasicaPrestamo(prestamo, operadorEntrega);
if (prestamo.equipo.status.id_status === 3)
throw new ConflictException(
'Ya se entregó el equipo de cómputo al usuario.',
);
if (prestamo.equipo.status.id_status === 3)
throw new ConflictException('Ya se entregó el equipo de cómputo al usuario.');
prestamo.hora_inicio = ahora.toDate();
prestamo.hora_fin =
ahora > horaMax
@@ -484,12 +482,46 @@ export class PrestamoService {
id_prestamo,
})
.getOne()
.then((prestamo) => {
.then(async (prestamo) => {
if (!prestamo) throw new NotFoundException('No existe este préstamo.');
return prestamo;
});
}
findByIdController(id_prestamo: number) {
return this.repository
.createQueryBuilder('p')
.innerJoinAndSelect('p.equipo', 'e')
.innerJoinAndSelect('p.usuario', 'u')
.innerJoinAndSelect('e.carrito', 'c')
.innerJoinAndSelect('e.programas', 'ps')
.innerJoinAndSelect('e.status', 's')
.innerJoinAndSelect('e.tiposEntradas', 'tes')
.innerJoinAndSelect('u.instituciones', 'is')
.innerJoinAndSelect('c.modulo', 'm')
.innerJoinAndSelect('c.tipoCarrito', 'tc')
.innerJoinAndSelect('ps.programa', 'pr')
.innerJoinAndSelect('tes.tipoEntrada', 'te')
.innerJoinAndSelect('is.institucionCarrera', 'ic')
.innerJoinAndSelect('ic.carrera', 'ca')
.innerJoinAndSelect('ic.institucion', 'in')
.innerJoinAndSelect('ca.nivel', 'n')
.innerJoinAndSelect('m.institucion', 'i')
.where('p.id_prestamo = :id_prestamo', {
id_prestamo,
})
.getOne()
.then(async (prestamo) => {
if (!prestamo) throw new NotFoundException('No existe este préstamo.');
if(prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 4 || prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 5)
{
const passcode = await this.passcodeService.findPasscode(prestamo.id_prestamo)
return {...prestamo, passcode}
}
return prestamo;
});
}
findByIdUsuario(id_usuario: number) {
return this.usuarioService
.findById(id_usuario, true, true)
@@ -512,15 +544,24 @@ export class PrestamoService {
.where('p.activo = 1')
.getOne(),
)
.then((prestamo) => {
.then(async (prestamo) => {
if (!prestamo)
throw new NotFoundException(
'Este usuario no tiene un préstamo activo.',
);
if(prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 4 || prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 5)
{
const passcode = await this.passcodeService.findPasscode(prestamo.id_prestamo)
console.log(passcode)
return {...prestamo, passcode}
}
return prestamo;
});
}
async findByNumeroInventario(
id_institucion: number | Institucion,
numero_inventario: string,
@@ -681,22 +722,28 @@ export class PrestamoService {
validacionBasicaPrestamo(prestamo: Prestamo, operador?: Operador) {
if (prestamo.cancelado_usuario)
throw new ConflictException(
'Este préstamo fue cancelado por el usuario.',
throw new ConflictException({
messsage: 'Este préstamo fue cancelado por el usuario.', code: 3
}
);
if (prestamo.cancelado_operador)
throw new ConflictException(
'Este préstamo fue cancelado por un operador.',
throw new ConflictException({
message: 'Este préstamo fue cancelado por un operador.', code : 3
}
);
if (!prestamo.activo)
throw new ConflictException('Este préstamo ya no se encuentra activo.');
throw new ConflictException({message: 'Este préstamo ya no se encuentra activo.', code:5});
if (
operador &&
operador.institucion.id_institucion !=
prestamo.equipo.carrito.modulo.institucion.id_institucion
) {
throw new ConflictException(
'Este préstamo no pertenece a esta institución.',
throw new ConflictException({
message: 'Este préstamo no pertenece a esta institución.', code: 2
}
);
}
}