get by id usuario, numero inventario, id prestamo
This commit is contained in:
@@ -12,9 +12,6 @@ export class PrestamoActivosDto {
|
||||
@IsNumberString()
|
||||
pagina: string;
|
||||
|
||||
@IsNumberString()
|
||||
id_modulo: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
carrito?: string;
|
||||
@@ -23,6 +20,14 @@ export class PrestamoActivosDto {
|
||||
@IsOptional()
|
||||
equipo?: string;
|
||||
|
||||
@IsNumberString()
|
||||
@IsOptional()
|
||||
id_institucion?: string;
|
||||
|
||||
@IsNumberString()
|
||||
@IsOptional()
|
||||
id_modulo?: string;
|
||||
|
||||
@IsNumberString()
|
||||
@IsOptional()
|
||||
id_prestamo?: string;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { IsNumberString } from 'class-validator';
|
||||
|
||||
export class PrestamoIdPrestamoDto {
|
||||
@IsNumberString()
|
||||
id_prestamo: string;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { IsNumberString } from 'class-validator';
|
||||
|
||||
export class PrestamoIdUsuarioDto {
|
||||
@IsNumberString()
|
||||
id_usuario: string;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { IsNumberString, IsString } from 'class-validator';
|
||||
|
||||
export class PrestamoNumeroInventarioDto {
|
||||
@IsNumberString()
|
||||
id_institucion: string;
|
||||
|
||||
@IsString()
|
||||
numero_inventario: string;
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
||||
import { PrestamoService } from './prestamo.service';
|
||||
import { PrestamoPedirDto } from './dto/prestamo-pedir.dto';
|
||||
import { PrestamoActivosDto } from './dto/prestamo-activos.dto';
|
||||
import { PrestamoIdUsuarioDto } from './dto/prestamo-id-usuario.dto';
|
||||
import { PrestamoIdPrestamoDto } from './dto/prestamo-id-prestamo.dto';
|
||||
import { PrestamoNumeroInventarioDto } from './dto/prestamo-numero-inventario.dto';
|
||||
|
||||
@Controller('prestamo')
|
||||
@ApiTags('prestamo')
|
||||
@@ -44,13 +47,47 @@ export class PrestamoController {
|
||||
}
|
||||
|
||||
@Get('prestamo-id-prestamo')
|
||||
prestamoIdPrestamo() {}
|
||||
@ApiOperation({ description: 'Endpoint que retorna un préstamo por su id.' })
|
||||
@ApiQuery({ description: '', name: '', type: '' })
|
||||
prestamoIdPrestamo(@Query() query: PrestamoIdPrestamoDto) {
|
||||
return this.prestamoService.findById(parseInt(query.id_prestamo));
|
||||
}
|
||||
|
||||
@Get('prestamo-id-usuario')
|
||||
prestamoIdUsuario() {}
|
||||
@ApiOperation({
|
||||
description:
|
||||
'Endpoint que retorna un préstamo activo por el id del usuario.',
|
||||
})
|
||||
@ApiQuery({
|
||||
description: 'Id del usuario.',
|
||||
name: 'id_usuario',
|
||||
type: 'string',
|
||||
})
|
||||
prestamoIdUsuario(@Query() query: PrestamoIdUsuarioDto) {
|
||||
return this.prestamoService.findByIdUsuario(parseInt(query.id_usuario));
|
||||
}
|
||||
|
||||
@Get('prestamo-numero-inventario')
|
||||
prestamoNumeroInventario() {}
|
||||
@ApiOperation({
|
||||
description:
|
||||
'Endpoint que retorna un préstamo activo por el número de inventario de un equipo.',
|
||||
})
|
||||
@ApiQuery({
|
||||
description: 'Id de la institución.',
|
||||
name: 'id_institucion',
|
||||
type: 'string',
|
||||
})
|
||||
@ApiQuery({
|
||||
description: 'El número de inventario del equipo.',
|
||||
name: 'numero_inventario',
|
||||
type: 'string',
|
||||
})
|
||||
prestamoNumeroInventario(@Query() query: PrestamoNumeroInventarioDto) {
|
||||
return this.prestamoService.findByNumeroInventario(
|
||||
parseInt(query.id_institucion),
|
||||
query.numero_inventario,
|
||||
);
|
||||
}
|
||||
|
||||
@Put('regresar')
|
||||
regresar() {}
|
||||
|
||||
@@ -115,7 +115,7 @@ export class PrestamoService {
|
||||
equipo?: string;
|
||||
fechaFin?: string;
|
||||
fechaInicio?: string;
|
||||
id_carrera?: string;
|
||||
// id_carrera?: string;
|
||||
id_institucion?: string;
|
||||
id_modulo?: string;
|
||||
id_operador_entrega?: string;
|
||||
@@ -156,16 +156,21 @@ export class PrestamoService {
|
||||
usuario: {
|
||||
usuario?: FindOperator<string>;
|
||||
tipoUsuario?: TipoUsuario;
|
||||
institucionCarrera: { carrera?: Carrera };
|
||||
// institucionCarrera: { carrera?: Carrera };
|
||||
};
|
||||
operadorEntrega?: Operador;
|
||||
operadorRegreso?: Operador;
|
||||
} = { equipo: { carrito: {} }, usuario: { institucionCarrera: {} } };
|
||||
const carrera = filtros.id_carrera
|
||||
? await this.institucionCarreraService.findCarreraByIdCarrera(
|
||||
parseInt(filtros.id_carrera),
|
||||
)
|
||||
: null;
|
||||
} = {
|
||||
equipo: { carrito: {} },
|
||||
usuario: {
|
||||
// institucionCarrera: {}
|
||||
},
|
||||
};
|
||||
// const carrera = filtros.id_carrera
|
||||
// ? await this.institucionCarreraService.findCarreraByIdCarrera(
|
||||
// parseInt(filtros.id_carrera),
|
||||
// )
|
||||
// : null;
|
||||
const institucion = filtros.id_institucion
|
||||
? await this.institucionService.findById(parseInt(filtros.id_institucion))
|
||||
: null;
|
||||
@@ -206,7 +211,7 @@ export class PrestamoService {
|
||||
if (filtros.equipo) busqueda.id_prestamo = parseInt(filtros.id_prestamo);
|
||||
if (filtros.usuario)
|
||||
busqueda.usuario.usuario = Like(`%${filtros.usuario}%`);
|
||||
if (carrera) busqueda.usuario.institucionCarrera.carrera = carrera;
|
||||
// if (carrera) busqueda.usuario.institucionCarrera.carrera = carrera;
|
||||
if (institucion) busqueda.equipo.carrito.modulo = { institucion };
|
||||
if (modulo) busqueda.equipo.carrito.modulo = modulo;
|
||||
if (operadorEntrega) busqueda.operadorEntrega = operadorEntrega;
|
||||
@@ -230,4 +235,35 @@ export class PrestamoService {
|
||||
return prestamo;
|
||||
});
|
||||
}
|
||||
|
||||
findByIdUsuario(id_usuario: number) {
|
||||
return this.usuarioService
|
||||
.findById(id_usuario, true, true)
|
||||
.then((usuario) => this.repository.findOne({ usuario, activo: true }))
|
||||
.then((prestamo) => {
|
||||
if (!prestamo)
|
||||
throw new NotFoundException(
|
||||
'Este usuario no tiene un prestamo activo.',
|
||||
);
|
||||
return prestamo;
|
||||
});
|
||||
}
|
||||
|
||||
async findByNumeroInventario(
|
||||
id_institucion: number,
|
||||
numero_inventario: string,
|
||||
) {
|
||||
const institucion = await this.institucionService.findById(id_institucion);
|
||||
|
||||
return this.equipoService
|
||||
.findByNumeroInventario(institucion, numero_inventario)
|
||||
.then((equipo) => this.repository.findOne({ equipo, activo: true }))
|
||||
.then((prestamo) => {
|
||||
if (!prestamo)
|
||||
throw new NotFoundException(
|
||||
'No existe este un préstamo activo con este equipo de cómputo.',
|
||||
);
|
||||
return prestamo;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user