multa listo

This commit is contained in:
xXpuma99Xx 2022-06-14 21:43:07 -05:00
parent 426ca54328
commit bc0fa5e3af
6 changed files with 43 additions and 23 deletions

View File

@ -27,7 +27,7 @@ export class Multa {
@Column({ type: Date, nullable: false }) @Column({ type: Date, nullable: false })
fecha_inicio: Date; fecha_inicio: Date;
@Column({ type: Boolean, nullable: false }) @Column({ type: Boolean, nullable: false, default: false })
retraso: boolean; retraso: boolean;
@ManyToOne( @ManyToOne(
@ -42,6 +42,7 @@ export class Multa {
@JoinColumn({ name: 'id_operador' }) @JoinColumn({ name: 'id_operador' })
opeardorMulta: Operador; opeardorMulta: Operador;
@OneToOne(() => Prestamo) @ManyToOne(() => Prestamo, (prestamo) => prestamo.multa)
@JoinColumn({ name: 'id_prestamo' })
prestamo: Prestamo; prestamo: Prestamo;
} }

View File

@ -45,12 +45,17 @@ export class MultaService {
const data: { const data: {
descripcion: string; descripcion: string;
fecha_inicio: Date; fecha_inicio: Date;
operador: Operador; opeardorMulta: Operador;
prestamo: Prestamo; prestamo: Prestamo;
fecha_fin?: Date; fecha_fin?: Date;
institucionInfraccion?: InstitucionInfraccion; institucionInfraccion?: InstitucionInfraccion;
retraso?: boolean; retraso?: boolean;
} = { descripcion, fecha_inicio: ahora.toDate(), operador, prestamo }; } = {
descripcion,
fecha_inicio: ahora.toDate(),
opeardorMulta: operador,
prestamo,
};
const institucionInfraccion = id_institucion_infraccion const institucionInfraccion = id_institucion_infraccion
? await this.institucionInfraccionService.findById( ? await this.institucionInfraccionService.findById(
id_institucion_infraccion, id_institucion_infraccion,
@ -61,22 +66,28 @@ export class MultaService {
throw new ConflictException( throw new ConflictException(
'No se mandó ningún motivo para multar a este alumno.', 'No se mandó ningún motivo para multar a este alumno.',
); );
return this.repository.findOne({ prestamo }).then((existeMulta) => { return this.repository
if (existeMulta) .findOne({ prestamo })
throw new ConflictException( .then((existeMulta) => {
'Ya existe una multa asignada a este prestamo.', if (existeMulta)
); throw new ConflictException(
if (retraso) { 'Ya existe una multa asignada a este prestamo.',
data.retraso = true; );
ahora.add(retraso * operador.institucion.dias_multa_retraso, 'd'); if (retraso) {
} data.retraso = true;
if (institucionInfraccion) { ahora.add(retraso * operador.institucion.dias_multa_retraso, 'd');
data.institucionInfraccion = institucionInfraccion; }
ahora.add(institucionInfraccion.dias_multa, 'd'); if (institucionInfraccion) {
} data.institucionInfraccion = institucionInfraccion;
data.fecha_fin = ahora.toDate(); ahora.add(institucionInfraccion.dias_multa, 'd');
return this.repository.save(this.repository.create(data)); }
}); 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: { async findAll(filtros: {

View File

@ -5,7 +5,7 @@ export class RegresarNumeroInventarioDto {
id_operador: number; id_operador: number;
@IsString() @IsString()
numero_inventairo: string; numero_inventario: string;
@IsInt() @IsInt()
@IsOptional() @IsOptional()

View File

@ -3,9 +3,11 @@ import {
Entity, Entity,
JoinColumn, JoinColumn,
ManyToOne, ManyToOne,
OneToMany,
PrimaryGeneratedColumn, PrimaryGeneratedColumn,
} from 'typeorm'; } from 'typeorm';
import { Equipo } from '../../equipo/entity/equipo.entity'; import { Equipo } from '../../equipo/entity/equipo.entity';
import { Multa } from '../../multa/entity/multa.entity';
import { Operador } from '../../operador/entity/operador.entity'; import { Operador } from '../../operador/entity/operador.entity';
import { Usuario } from '../../usuario/entity/usuario.entity'; import { Usuario } from '../../usuario/entity/usuario.entity';
@ -61,4 +63,7 @@ export class Prestamo {
@ManyToOne(() => Usuario, (usuario) => usuario.prestamos, { eager: true }) @ManyToOne(() => Usuario, (usuario) => usuario.prestamos, { eager: true })
@JoinColumn({ name: 'id_usuario' }) @JoinColumn({ name: 'id_usuario' })
usuario: Usuario; usuario: Usuario;
@OneToMany(() => Multa, (multa) => multa.prestamo)
multa: Multa;
} }

View File

@ -367,7 +367,7 @@ export class PrestamoController {
regresar(@Body() body: RegresarNumeroInventarioDto) { regresar(@Body() body: RegresarNumeroInventarioDto) {
return this.prestamoService.regresarNumeroInventario( return this.prestamoService.regresarNumeroInventario(
body.id_operador, body.id_operador,
body.numero_inventairo, body.numero_inventario,
body.descripcion, body.descripcion,
body.id_institucion_infraccion, body.id_institucion_infraccion,
); );

View File

@ -163,6 +163,10 @@ export class PrestamoService {
// if (ahora < horaMin) // if (ahora < horaMin)
// throw new Error('Aún es muy temprano para realizar un préstamo.'); // 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 return this.repository
.findOne({ activo: true, usuario }) .findOne({ activo: true, usuario })
.then((existePrestamo) => { .then((existePrestamo) => {
@ -408,7 +412,6 @@ export class PrestamoService {
throw new ConflictException('Aun no se entrega el equipo al usuario.'); throw new ConflictException('Aun no se entrega el equipo al usuario.');
if (id_institucion_infraccion && !descripcion) if (id_institucion_infraccion && !descripcion)
throw new ConflictException('No se mandó la descripción de lo ocurrido.'); throw new ConflictException('No se mandó la descripción de lo ocurrido.');
id_institucion_infraccion && !descripcion;
prestamo.activo = false; prestamo.activo = false;
prestamo.fecha_entrega = ahora.toDate(); prestamo.fecha_entrega = ahora.toDate();
prestamo.operadorRegreso = operadorRegreso; prestamo.operadorRegreso = operadorRegreso;