From 09b3a0770f0a3a04647df9a8bfcd73d32ca1789c Mon Sep 17 00:00:00 2001 From: xXpuma99Xx <51341582+xXpuma99Xx@users.noreply.github.com> Date: Sun, 4 Sep 2022 22:59:25 -0500 Subject: [PATCH] mas filtros --- src/auth/dto/jwt-payload-admin.ts | 11 ++++++++ src/auth/dto/jwt-payload-operador.ts | 13 +++++++++ src/auth/dto/jwt-payload-usuario.ts | 18 +++++++++++++ .../entity/carrera.entity.ts | 2 +- src/prestamo/dto/input/historial.dto.ts | 9 +++++++ src/prestamo/prestamo.service.ts | 27 +++++++++++++++---- 6 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 src/auth/dto/jwt-payload-admin.ts create mode 100644 src/auth/dto/jwt-payload-operador.ts create mode 100644 src/auth/dto/jwt-payload-usuario.ts diff --git a/src/auth/dto/jwt-payload-admin.ts b/src/auth/dto/jwt-payload-admin.ts new file mode 100644 index 0000000..8551935 --- /dev/null +++ b/src/auth/dto/jwt-payload-admin.ts @@ -0,0 +1,11 @@ +export class JwtPayload { + nombre: string; + + id_operador: number; + + institucion: { id_institucion: number }; + + operador: string; + + tipoUsuario: { id_tipo_usuario: number }; +} diff --git a/src/auth/dto/jwt-payload-operador.ts b/src/auth/dto/jwt-payload-operador.ts new file mode 100644 index 0000000..3c42a95 --- /dev/null +++ b/src/auth/dto/jwt-payload-operador.ts @@ -0,0 +1,13 @@ +export class JwtPayload { + nombre: string; + + id_modulo: number; + + id_operador: number; + + institucion: { id_institucion: number }; + + operador: string; + + tipoUsuario: { id_tipo_usuario: number }; +} diff --git a/src/auth/dto/jwt-payload-usuario.ts b/src/auth/dto/jwt-payload-usuario.ts new file mode 100644 index 0000000..0a6ecbf --- /dev/null +++ b/src/auth/dto/jwt-payload-usuario.ts @@ -0,0 +1,18 @@ +export class JwtPayload { + nombre: string; + + id_usuario: number; + + instituciones: { + id_institucion_usuario: number; + institucionCarrera: { + id_institucion_carrera: number; + institucion: { id_institucion: number }; + carrera: { id_carrera: number }; + }; + }[]; + + tipoUsuario: { id_tipo_usuario: number }; + + usuario: string; +} diff --git a/src/institucion-carrera/entity/carrera.entity.ts b/src/institucion-carrera/entity/carrera.entity.ts index f1f5353..5d9ccad 100644 --- a/src/institucion-carrera/entity/carrera.entity.ts +++ b/src/institucion-carrera/entity/carrera.entity.ts @@ -20,7 +20,7 @@ export class Carrera { @Column({ type: String, nullable: false, length: 10 }) clave: string; - @ManyToOne(() => Nivel, (nivel) => nivel.carreras, { eager: true }) + @ManyToOne(() => Nivel, (nivel) => nivel.carreras) @JoinColumn({ name: 'id_nivel' }) nivel: Nivel; diff --git a/src/prestamo/dto/input/historial.dto.ts b/src/prestamo/dto/input/historial.dto.ts index e9a815f..d799cc8 100644 --- a/src/prestamo/dto/input/historial.dto.ts +++ b/src/prestamo/dto/input/historial.dto.ts @@ -1,4 +1,5 @@ import { + IsBooleanString, IsDateString, IsNotEmpty, IsNumberString, @@ -10,6 +11,14 @@ export class HistorialDto { @IsNumberString() pagina: string; + @IsBooleanString() + @IsOptional() + cancelado_operador?: string; + + @IsBooleanString() + @IsOptional() + cancelado_usuario?: string; + @IsString() @IsNotEmpty() @IsOptional() diff --git a/src/prestamo/prestamo.service.ts b/src/prestamo/prestamo.service.ts index c45670d..00f6898 100644 --- a/src/prestamo/prestamo.service.ts +++ b/src/prestamo/prestamo.service.ts @@ -280,6 +280,8 @@ export class PrestamoService { async findAll(filtros: { pagina: string; activo?: string | boolean; + cancelado_operador?: string; + cancelado_usuario?: string; carrito?: string; equipo?: string; fechaFin?: string; @@ -336,8 +338,10 @@ export class PrestamoService { .innerJoinAndSelect('m.institucion', 'i') .innerJoinAndSelect('ic.carrera', 'ca') .innerJoinAndSelect('ic.institucion', 'in') - .innerJoinAndSelect('ca.nivel', 'n') - .orderBy('p.id_prestamo', 'DESC') + .orderBy( + 'p.id_prestamo', + filtros.activo && typeof filtros.activo === 'boolean' ? 'ASC' : 'DESC', + ) .addOrderBy('i.institucion') .addOrderBy('m.modulo') .addOrderBy('tc.tipo_carrito') @@ -354,6 +358,22 @@ export class PrestamoService { activo: filtros.activo === 'true', }); } + if (filtros.cancelado_operador) + query.andWhere('p.cancelado_operador = :cancelado_operador', { + cancelado_operador: filtros.cancelado_operador === 'true', + }); + if (filtros.cancelado_usuario) + query.andWhere('p.cancelado_usuario = :cancelado_usuario', { + cancelado_usuario: filtros.cancelado_usuario === 'true', + }); + if (filtros.fechaInicio) + query.andWhere('p.fecha_inicio >= :fechaInicio', { + fechaInicio: filtros.fechaInicio, + }); + if (filtros.fechaFin) + query.andWhere('p.fecha_inicio <= :fechaFin', { + fechaFin: filtros.fechaFin, + }); if (filtros.id_prestamo) query.andWhere('p.id_prestamo LIKE :id_prestamo', { id_prestamo: `%${filtros.id_prestamo}%`, @@ -443,7 +463,6 @@ export class PrestamoService { .innerJoinAndSelect('m.institucion', 'i') .innerJoinAndSelect('ic.carrera', 'ca') .innerJoinAndSelect('ic.institucion', 'in') - .innerJoinAndSelect('ca.nivel', 'n') .orderBy('p.id_prestamo', 'DESC') .skip((pagina - 1) * 25) .take(25) @@ -468,7 +487,6 @@ export class PrestamoService { .innerJoinAndSelect('is.institucionCarrera', 'ic') .innerJoinAndSelect('ic.carrera', 'ca') .innerJoinAndSelect('ic.institucion', 'in') - .innerJoinAndSelect('ca.nivel', 'n') .innerJoinAndSelect('m.institucion', 'i') .where('p.id_prestamo = :id_prestamo', { id_prestamo, @@ -538,7 +556,6 @@ export class PrestamoService { .innerJoinAndSelect('m.institucion', 'i') .innerJoinAndSelect('ic.carrera', 'ca') .innerJoinAndSelect('ic.institucion', 'in') - .innerJoinAndSelect('ca.nivel', 'n') .where('p.activo = 1') .getOne(), )