no mas repetidos
This commit is contained in:
@@ -22,6 +22,9 @@ export class Prestamo {
|
||||
@Column({ type: Boolean, nullable: false, default: false })
|
||||
cancelado_operador: boolean;
|
||||
|
||||
@Column({ type: Boolean, nullable: false, default: false })
|
||||
cancelado_repeticion: boolean;
|
||||
|
||||
@Column({ type: Boolean, nullable: false, default: false })
|
||||
cancelado_usuario: boolean;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import { TipoCarrito } from '../../../institucion-tipo-carrito/entity/tipo-carri
|
||||
.addSelect('p.id_operador_regreso', 'id_operador_regreso')
|
||||
.addSelect('p.id_usuario', 'id_usuario')
|
||||
.addSelect('e.equipo', 'equipo')
|
||||
.addSelect('e.u', 'u')
|
||||
.addSelect('e.id_carrito', 'id_carrito')
|
||||
.addSelect('e.id_status', 'id_status')
|
||||
.addSelect('e.numero_inventario', 'numero_inventario')
|
||||
@@ -105,4 +106,7 @@ export class InformacionPrestamoView {
|
||||
|
||||
@ViewColumn()
|
||||
tipo_carrito: string;
|
||||
|
||||
@ViewColumn()
|
||||
u: number;
|
||||
}
|
||||
|
||||
@@ -258,13 +258,37 @@ export class PrestamoService {
|
||||
async desactivarPrestamos() {
|
||||
const ahora = moment();
|
||||
|
||||
// Busco todos los préstamos activos y que esten apartadoss
|
||||
// Busco todos los préstamos activos y cuyos equipos no esten asignados
|
||||
// al usuario del préstamo
|
||||
return this.informacionPrestamoView
|
||||
.find({ where: { activo: 1, id_status: 2 } })
|
||||
.then(async (infoPrestamo) => {
|
||||
.createQueryBuilder('p')
|
||||
.where('activo = 1 AND id_usuario != u')
|
||||
.getMany()
|
||||
.then(async (infoPrestamos) => {
|
||||
// Recorro el array
|
||||
for (let i = 0; i < infoPrestamo.length; i++) {
|
||||
const prestamo = this.viewToPrestamo(infoPrestamo[i]);
|
||||
for (let i = 0; i < infoPrestamos.length; i++) {
|
||||
const prestamo = this.viewToPrestamo(infoPrestamos[i]);
|
||||
|
||||
prestamo.activo = false;
|
||||
prestamo.cancelado_repeticion = true;
|
||||
// Guardo los cambios del préstamo
|
||||
await this.repository.save(prestamo).then((_) => {
|
||||
// Actualizo las interfaces del los usuarios
|
||||
this.appGateway.actualizarOperador(
|
||||
prestamo.equipo.carrito.modulo.institucion.id_institucion,
|
||||
);
|
||||
this.appGateway.actualizarUsuario(prestamo.usuario.id_usuario);
|
||||
});
|
||||
}
|
||||
// Busco todos los préstamos activos y que esten apartadoss
|
||||
return this.informacionPrestamoView.find({
|
||||
where: { activo: 1, id_status: 2 },
|
||||
});
|
||||
})
|
||||
.then(async (infoPrestamos) => {
|
||||
// Recorro el array
|
||||
for (let i = 0; i < infoPrestamos.length; i++) {
|
||||
const prestamo = this.viewToPrestamo(infoPrestamos[i]);
|
||||
|
||||
// Si la resta ahora - hora_max_recoger es mayor a 0 significa que ya pasó
|
||||
// el tiempo limite para recoger el equipo de cómputo
|
||||
@@ -797,6 +821,10 @@ export class PrestamoService {
|
||||
);
|
||||
if (id_institucion_infraccion && !descripcion)
|
||||
throw new ConflictException('No se mandó la descripción de lo ocurrido.');
|
||||
if (prestamo.usuario.id_usuario !== prestamo.equipo.u)
|
||||
throw new ConflictException(
|
||||
'Este equipo fue asignado 2 veces y este es el préstamo incorrecto, espere unos segundos y se desactivará este préstamo.',
|
||||
);
|
||||
prestamo.activo = false;
|
||||
prestamo.fecha_entrega = ahora.toDate();
|
||||
prestamo.operadorRegreso = operadorRegreso;
|
||||
@@ -975,6 +1003,7 @@ export class PrestamoService {
|
||||
id_equipo: infoPrestamo.id_equipo,
|
||||
equipo: infoPrestamo.equipo,
|
||||
numero_inventario: infoPrestamo.numero_inventario,
|
||||
u: infoPrestamo.u,
|
||||
carrito: {
|
||||
id_carrito: infoPrestamo.id_carrito,
|
||||
carrito: infoPrestamo.carrito,
|
||||
|
||||
Reference in New Issue
Block a user