multa listo
This commit is contained in:
+29
-18
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user