listo activos
This commit is contained in:
+8
-2
@@ -1,7 +1,13 @@
|
||||
import { IsNumberString, IsOptional, IsString } from 'class-validator';
|
||||
import {
|
||||
IsBoolean,
|
||||
IsNumberString,
|
||||
IsOptional,
|
||||
IsString,
|
||||
} from 'class-validator';
|
||||
|
||||
export class PrestamoActivosDto {
|
||||
activo: true;
|
||||
@IsBoolean()
|
||||
activo = true;
|
||||
|
||||
@IsNumberString()
|
||||
pagina: string;
|
||||
@@ -1,7 +1,8 @@
|
||||
import { Body, Controller, Get, Post, Put } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { PrestamoService } from './prestamo.service';
|
||||
import { PrestamoPedirDto } from './dto/prestamo-pedir.dto';
|
||||
import { PrestamoActivosDto } from './dto/prestamo-activos.dto';
|
||||
|
||||
@Controller('prestamo')
|
||||
@ApiTags('prestamo')
|
||||
@@ -9,7 +10,10 @@ export class PrestamoController {
|
||||
constructor(private prestamoService: PrestamoService) {}
|
||||
|
||||
@Get('activos')
|
||||
activos() {}
|
||||
activos(@Query() query: PrestamoActivosDto) {
|
||||
console.log(query);
|
||||
return this.prestamoService.findAll(query);
|
||||
}
|
||||
|
||||
@Put('cancelar-operador')
|
||||
cancelarOperador() {}
|
||||
|
||||
@@ -125,6 +125,21 @@ export class PrestamoService {
|
||||
id_prestamo?: string;
|
||||
usuario?: string;
|
||||
}) {
|
||||
const join: {
|
||||
e: string;
|
||||
u: string;
|
||||
c: string;
|
||||
m: string;
|
||||
tc: string;
|
||||
oe?: string;
|
||||
or?: string;
|
||||
} = {
|
||||
e: 'p.equipo',
|
||||
u: 'p.usuario',
|
||||
c: 'e.carrito',
|
||||
m: 'c.modulo',
|
||||
tc: 'c.tipoCarrito',
|
||||
};
|
||||
const busqueda: {
|
||||
activo?: boolean;
|
||||
fechaInicio?: Date;
|
||||
@@ -175,9 +190,14 @@ export class PrestamoService {
|
||||
)
|
||||
: null;
|
||||
|
||||
console.log(filtros.activo);
|
||||
if (filtros.activo) {
|
||||
if (typeof filtros.activo === 'boolean') busqueda.activo = filtros.activo;
|
||||
else busqueda.activo = filtros.activo === 'true';
|
||||
} else {
|
||||
console.log('hola');
|
||||
join.oe = 'p.operadorEntrega';
|
||||
join.or = 'p.operadorRegreso';
|
||||
}
|
||||
if (filtros.carrito)
|
||||
busqueda.equipo.carrito.carrito = Like(`%${filtros.carrito}%`);
|
||||
@@ -192,6 +212,10 @@ export class PrestamoService {
|
||||
if (tipoCarrito) busqueda.equipo.carrito.tipoCarrito = tipoCarrito;
|
||||
if (tipoUsuario) busqueda.usuario.tipoUsuario = tipoUsuario;
|
||||
return this.repository.findAndCount({
|
||||
join: {
|
||||
alias: 'p',
|
||||
innerJoinAndSelect: join,
|
||||
},
|
||||
where: busqueda,
|
||||
skip: (parseInt(filtros.pagina) - 1) * 25,
|
||||
take: 25,
|
||||
|
||||
Reference in New Issue
Block a user