operadores ya no pueden modificar prestamos de otros modulos
This commit is contained in:
parent
b383da979f
commit
fccc5f11c5
@ -41,6 +41,7 @@ import { PrestamosOutputDto } from './dto/output/prestamos.dto';
|
||||
import { PrestamosEquipoOutputDto } from './dto/output/prestamos-equipo.dto';
|
||||
import { PrestamosUsuarioOutputDto } from './dto/output/prestamos-usuario.dto';
|
||||
import { Usuario } from '../usuario/entity/usuario.entity';
|
||||
import { Modulo } from 'src/modulo/entity/modulo.entity';
|
||||
|
||||
@Controller('prestamo')
|
||||
@ApiTags('prestamo')
|
||||
@ -437,6 +438,7 @@ export class PrestamoController {
|
||||
})
|
||||
regresarIdPrestamo(@Request() req, @Body() body: RegresarIdPrestamoDto) {
|
||||
const operador: Operador = req.user.operador;
|
||||
const modulo: Modulo = req.user.modulo || null;
|
||||
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
return this.prestamoService.regresarIdPrestamo(
|
||||
@ -446,6 +448,7 @@ export class PrestamoController {
|
||||
body.motivo,
|
||||
body.descripcion,
|
||||
body.id_institucion_infraccion,
|
||||
modulo,
|
||||
);
|
||||
}
|
||||
|
||||
@ -472,6 +475,7 @@ export class PrestamoController {
|
||||
@Body() body: RegresarNumeroInventarioDto,
|
||||
) {
|
||||
const operador: Operador = req.user.operador;
|
||||
const modulo: Modulo = req.user.modulo || null;
|
||||
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
return this.prestamoService.regresarNumeroInventario(
|
||||
@ -481,6 +485,7 @@ export class PrestamoController {
|
||||
body.motivo,
|
||||
body.descripcion,
|
||||
body.id_institucion_infraccion,
|
||||
modulo,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -248,7 +248,11 @@ export class PrestamoService {
|
||||
});
|
||||
}
|
||||
|
||||
async entregar(operadorEntrega: Operador, id_prestamo: number) {
|
||||
async entregar(
|
||||
operadorEntrega: Operador,
|
||||
id_prestamo: number,
|
||||
modulo?: Modulo,
|
||||
) {
|
||||
const ahora = moment();
|
||||
const ahoraStr = ahora.format('YYYY-MM-DD');
|
||||
const prestamo = await this.findInfoPrestamoById(id_prestamo);
|
||||
@ -265,7 +269,7 @@ export class PrestamoService {
|
||||
: null;
|
||||
|
||||
this.validacionBasicaPrestamo(prestamo);
|
||||
this.validacionOperadorPrestamo(prestamo, operadorEntrega);
|
||||
this.validacionOperadorPrestamo(prestamo, operadorEntrega, modulo);
|
||||
if (prestamo.equipo.status.id_status === 3)
|
||||
throw new ConflictException(
|
||||
'Ya se entregó el equipo de cómputo al usuario.',
|
||||
@ -745,6 +749,7 @@ export class PrestamoService {
|
||||
motivo?: string,
|
||||
descripcion?: string,
|
||||
id_institucion_infraccion?: number,
|
||||
modulo?: Modulo,
|
||||
) {
|
||||
const ahora = moment();
|
||||
const tardanza = Math.trunc(ahora.diff(moment(prestamo.hora_fin)) / 60000);
|
||||
@ -753,7 +758,7 @@ export class PrestamoService {
|
||||
);
|
||||
|
||||
this.validacionBasicaPrestamo(prestamo);
|
||||
this.validacionOperadorPrestamo(prestamo, operadorRegreso);
|
||||
this.validacionOperadorPrestamo(prestamo, operadorRegreso, modulo);
|
||||
if (prestamo.equipo.status.id_status === 2)
|
||||
throw new ConflictException(
|
||||
'Aún no se ha entregado el equipo de cómputo al usuario.',
|
||||
@ -818,6 +823,7 @@ export class PrestamoService {
|
||||
motivo: string,
|
||||
descripcion?: string,
|
||||
id_institucion_infraccion?: number,
|
||||
modulo?: Modulo,
|
||||
) {
|
||||
return this.findInfoPrestamoById(id_prestamo).then((prestamo) =>
|
||||
this.regresar(
|
||||
@ -827,6 +833,7 @@ export class PrestamoService {
|
||||
motivo,
|
||||
descripcion,
|
||||
id_institucion_infraccion,
|
||||
modulo,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -838,6 +845,7 @@ export class PrestamoService {
|
||||
motivo: string,
|
||||
descripcion?: string,
|
||||
id_institucion_infraccion?: number,
|
||||
modulo?: Modulo,
|
||||
) {
|
||||
return this.findInfoPrestamoByNumeroInventario(
|
||||
operador.institucion,
|
||||
@ -850,6 +858,7 @@ export class PrestamoService {
|
||||
motivo,
|
||||
descripcion,
|
||||
id_institucion_infraccion,
|
||||
modulo,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -891,7 +900,12 @@ export class PrestamoService {
|
||||
);
|
||||
}
|
||||
|
||||
validacionOperadorPrestamo(prestamo: Prestamo, operador: Operador) {
|
||||
validacionOperadorPrestamo(
|
||||
prestamo: Prestamo,
|
||||
operador: Operador,
|
||||
modulo?: Modulo,
|
||||
) {
|
||||
// Valido que el prestamo pertenezca a la institución
|
||||
if (
|
||||
operador.institucion.id_institucion !=
|
||||
prestamo.equipo.carrito.modulo.institucion.id_institucion
|
||||
@ -899,6 +913,9 @@ export class PrestamoService {
|
||||
throw new ConflictException(
|
||||
'Este préstamo no pertenece a esta institución.',
|
||||
);
|
||||
// Valido que el prestamo pertenezca al módulo del operador
|
||||
if (modulo && prestamo.equipo.carrito.modulo.id_modulo != modulo.id_modulo)
|
||||
throw new ConflictException('Este préstamo no pertenece a tu módulo.');
|
||||
}
|
||||
|
||||
private viewToPrestamo(infoPrestamo: InformacionPrestamoView) {
|
||||
|
Loading…
Reference in New Issue
Block a user