multa listo
This commit is contained in:
parent
426ca54328
commit
bc0fa5e3af
@ -27,7 +27,7 @@ export class Multa {
|
||||
@Column({ type: Date, nullable: false })
|
||||
fecha_inicio: Date;
|
||||
|
||||
@Column({ type: Boolean, nullable: false })
|
||||
@Column({ type: Boolean, nullable: false, default: false })
|
||||
retraso: boolean;
|
||||
|
||||
@ManyToOne(
|
||||
@ -42,6 +42,7 @@ export class Multa {
|
||||
@JoinColumn({ name: 'id_operador' })
|
||||
opeardorMulta: Operador;
|
||||
|
||||
@OneToOne(() => Prestamo)
|
||||
@ManyToOne(() => Prestamo, (prestamo) => prestamo.multa)
|
||||
@JoinColumn({ name: 'id_prestamo' })
|
||||
prestamo: Prestamo;
|
||||
}
|
||||
|
@ -45,12 +45,17 @@ export class MultaService {
|
||||
const data: {
|
||||
descripcion: string;
|
||||
fecha_inicio: Date;
|
||||
operador: Operador;
|
||||
opeardorMulta: Operador;
|
||||
prestamo: Prestamo;
|
||||
fecha_fin?: Date;
|
||||
institucionInfraccion?: InstitucionInfraccion;
|
||||
retraso?: boolean;
|
||||
} = { descripcion, fecha_inicio: ahora.toDate(), operador, prestamo };
|
||||
} = {
|
||||
descripcion,
|
||||
fecha_inicio: ahora.toDate(),
|
||||
opeardorMulta: operador,
|
||||
prestamo,
|
||||
};
|
||||
const institucionInfraccion = id_institucion_infraccion
|
||||
? await this.institucionInfraccionService.findById(
|
||||
id_institucion_infraccion,
|
||||
@ -61,22 +66,28 @@ export class MultaService {
|
||||
throw new ConflictException(
|
||||
'No se mandó ningún motivo para multar a este alumno.',
|
||||
);
|
||||
return this.repository.findOne({ prestamo }).then((existeMulta) => {
|
||||
if (existeMulta)
|
||||
throw new ConflictException(
|
||||
'Ya existe una multa asignada a este prestamo.',
|
||||
);
|
||||
if (retraso) {
|
||||
data.retraso = true;
|
||||
ahora.add(retraso * operador.institucion.dias_multa_retraso, 'd');
|
||||
}
|
||||
if (institucionInfraccion) {
|
||||
data.institucionInfraccion = institucionInfraccion;
|
||||
ahora.add(institucionInfraccion.dias_multa, 'd');
|
||||
}
|
||||
data.fecha_fin = ahora.toDate();
|
||||
return this.repository.save(this.repository.create(data));
|
||||
});
|
||||
return this.repository
|
||||
.findOne({ prestamo })
|
||||
.then((existeMulta) => {
|
||||
if (existeMulta)
|
||||
throw new ConflictException(
|
||||
'Ya existe una multa asignada a este prestamo.',
|
||||
);
|
||||
if (retraso) {
|
||||
data.retraso = true;
|
||||
ahora.add(retraso * operador.institucion.dias_multa_retraso, 'd');
|
||||
}
|
||||
if (institucionInfraccion) {
|
||||
data.institucionInfraccion = institucionInfraccion;
|
||||
ahora.add(institucionInfraccion.dias_multa, 'd');
|
||||
}
|
||||
data.fecha_fin = ahora.toDate();
|
||||
return this.repository.save(this.repository.create(data));
|
||||
})
|
||||
.then((_) => {
|
||||
prestamo.usuario.multa = true;
|
||||
return this.usuarioService.update(prestamo.usuario);
|
||||
});
|
||||
}
|
||||
|
||||
async findAll(filtros: {
|
||||
|
@ -5,7 +5,7 @@ export class RegresarNumeroInventarioDto {
|
||||
id_operador: number;
|
||||
|
||||
@IsString()
|
||||
numero_inventairo: string;
|
||||
numero_inventario: string;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
|
@ -3,9 +3,11 @@ import {
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { Equipo } from '../../equipo/entity/equipo.entity';
|
||||
import { Multa } from '../../multa/entity/multa.entity';
|
||||
import { Operador } from '../../operador/entity/operador.entity';
|
||||
import { Usuario } from '../../usuario/entity/usuario.entity';
|
||||
|
||||
@ -61,4 +63,7 @@ export class Prestamo {
|
||||
@ManyToOne(() => Usuario, (usuario) => usuario.prestamos, { eager: true })
|
||||
@JoinColumn({ name: 'id_usuario' })
|
||||
usuario: Usuario;
|
||||
|
||||
@OneToMany(() => Multa, (multa) => multa.prestamo)
|
||||
multa: Multa;
|
||||
}
|
||||
|
@ -367,7 +367,7 @@ export class PrestamoController {
|
||||
regresar(@Body() body: RegresarNumeroInventarioDto) {
|
||||
return this.prestamoService.regresarNumeroInventario(
|
||||
body.id_operador,
|
||||
body.numero_inventairo,
|
||||
body.numero_inventario,
|
||||
body.descripcion,
|
||||
body.id_institucion_infraccion,
|
||||
);
|
||||
|
@ -163,6 +163,10 @@ export class PrestamoService {
|
||||
// if (ahora < horaMin)
|
||||
// throw new Error('Aún es muy temprano para realizar un préstamo.');
|
||||
// }
|
||||
if (usuario.multa)
|
||||
throw new ConflictException(
|
||||
'Este usuario tiene una multa activa. No puede pedir equipos de cómputo.',
|
||||
);
|
||||
return this.repository
|
||||
.findOne({ activo: true, usuario })
|
||||
.then((existePrestamo) => {
|
||||
@ -408,7 +412,6 @@ export class PrestamoService {
|
||||
throw new ConflictException('Aun no se entrega el equipo al usuario.');
|
||||
if (id_institucion_infraccion && !descripcion)
|
||||
throw new ConflictException('No se mandó la descripción de lo ocurrido.');
|
||||
id_institucion_infraccion && !descripcion;
|
||||
prestamo.activo = false;
|
||||
prestamo.fecha_entrega = ahora.toDate();
|
||||
prestamo.operadorRegreso = operadorRegreso;
|
||||
|
Loading…
Reference in New Issue
Block a user