2022-04-04 20:02:54 -05:00
|
|
|
import { Injectable } from '@nestjs/common';
|
2022-04-04 20:53:32 -05:00
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
2022-04-17 22:11:55 -05:00
|
|
|
import { Repository } from 'typeorm';
|
2022-04-23 22:45:57 -05:00
|
|
|
import * as moment from 'moment';
|
|
|
|
|
import { InstitucionInfraccion } from '../institucion-infraccion/entity/institucion-infraccion.entity';
|
2022-04-17 22:11:55 -05:00
|
|
|
import { Multa } from './entity/multa.entity';
|
2022-04-23 22:45:57 -05:00
|
|
|
import { Prestamo } from '../prestamo/entity/prestamo.entity';
|
2022-04-24 12:00:56 -05:00
|
|
|
import { EquipoService } from '../equipo/equipo.service';
|
2022-06-02 10:42:53 -05:00
|
|
|
import { InstitucionService } from '../institucion/institucion.service';
|
2022-04-24 12:00:56 -05:00
|
|
|
import { InstitucionInfraccionService } from '../institucion-infraccion/institucion-infraccion.service';
|
|
|
|
|
import { OperadorService } from '../operador/operador.service';
|
|
|
|
|
import { PrestamoService } from '../prestamo/prestamo.service';
|
|
|
|
|
import { UsuarioService } from '../usuario/usuario.service';
|
2022-04-04 20:02:54 -05:00
|
|
|
|
|
|
|
|
@Injectable()
|
2022-04-04 20:53:32 -05:00
|
|
|
export class MultaService {
|
2022-04-23 22:45:57 -05:00
|
|
|
constructor(
|
|
|
|
|
@InjectRepository(Multa) private repository: Repository<Multa>,
|
|
|
|
|
private equipoService: EquipoService,
|
2022-06-02 10:42:53 -05:00
|
|
|
private institucionService: InstitucionService,
|
|
|
|
|
private institucionInfraccionService: InstitucionInfraccionService,
|
2022-04-23 22:45:57 -05:00
|
|
|
private operadorService: OperadorService,
|
|
|
|
|
private prestamoService: PrestamoService,
|
|
|
|
|
private usuarioService: UsuarioService,
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
async create(
|
|
|
|
|
id_institucion_infraccion: number,
|
|
|
|
|
id_prestamo: number,
|
|
|
|
|
id_operador: number,
|
|
|
|
|
retraso: boolean,
|
|
|
|
|
) {
|
|
|
|
|
const prestamo = await this.prestamoService.findById(id_prestamo);
|
|
|
|
|
const operador = await this.operadorService.findById(id_operador);
|
|
|
|
|
const institucionInfraccion = id_institucion_infraccion
|
2022-06-02 10:42:53 -05:00
|
|
|
? await this.institucionInfraccionService.findById(
|
2022-04-23 22:45:57 -05:00
|
|
|
id_institucion_infraccion,
|
|
|
|
|
)
|
|
|
|
|
: null;
|
|
|
|
|
const data: {
|
|
|
|
|
prestamo: Prestamo;
|
|
|
|
|
institucionInfraccion?: InstitucionInfraccion;
|
|
|
|
|
retraso?: boolean;
|
|
|
|
|
} = { prestamo };
|
|
|
|
|
|
|
|
|
|
// const nuevo
|
|
|
|
|
// this.repository.create({
|
|
|
|
|
// institucionInfraccion,
|
|
|
|
|
// prestamo,
|
|
|
|
|
// fecha_inicio: new Date(),
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
if (retraso) data.retraso = retraso;
|
|
|
|
|
if (institucionInfraccion) data.institucionInfraccion;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 10:42:53 -05:00
|
|
|
findAllByIdInstitucion(id_institucion: number, pagina: number) {
|
|
|
|
|
return this.institucionService
|
|
|
|
|
.findById(id_institucion)
|
|
|
|
|
.then((institucion) =>
|
|
|
|
|
this.repository.findAndCount({
|
|
|
|
|
where: {},
|
|
|
|
|
skip: (pagina - 1) * 25,
|
|
|
|
|
take: 25,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
findAllByIdEquipo(id_equipo: number, pagina: number) {
|
|
|
|
|
return this.equipoService.findById(id_equipo).then((equipo) =>
|
|
|
|
|
this.repository.findAndCount({
|
|
|
|
|
where: { prestamo: { equipo } },
|
|
|
|
|
skip: (pagina - 1) * 25,
|
|
|
|
|
take: 25,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-04-23 22:45:57 -05:00
|
|
|
|
2022-06-02 10:42:53 -05:00
|
|
|
findAllByIdUsuario(id_usuario: number, pagina: number) {
|
|
|
|
|
return this.usuarioService.findById(id_usuario).then((usuario) =>
|
|
|
|
|
this.repository.findAndCount({
|
|
|
|
|
where: { prestamo: { usuario } },
|
|
|
|
|
skip: (pagina - 1) * 25,
|
|
|
|
|
take: 25,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
2022-04-04 20:53:32 -05:00
|
|
|
}
|