porfin todos los modulos revisados y listos
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { IsNumberString } from 'class-validator';
|
||||
|
||||
export class MultasUsuarioDto {
|
||||
export class IdUsuarioPaginaDto {
|
||||
@IsNumberString()
|
||||
id_usuario: string;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { IsNumberString, IsString } from 'class-validator';
|
||||
|
||||
export class EquipoDto {
|
||||
@IsNumberString()
|
||||
id_institucion: string;
|
||||
|
||||
@IsString()
|
||||
numero_inventario: string;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { AuthGuard } from '@nestjs/passport';
|
||||
import { ApiBody, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { EquipoService } from './equipo.service';
|
||||
import { EquipoDto } from './dto/input/equipo.dto';
|
||||
import { NumeroInventarioDto } from '../dto/numero-inventario.dto';
|
||||
import { EquiposDto } from './dto/input/equipos.dto';
|
||||
import { UpdateEquipoDto } from './dto/input/update.dto';
|
||||
import { EquipoOutputDto } from './dto/output/equipo.dto';
|
||||
@@ -31,7 +31,7 @@ export class EquipoController {
|
||||
name: 'numero_inventario',
|
||||
type: 'string',
|
||||
})
|
||||
equipo(@Query() query: EquipoDto) {
|
||||
equipo(@Query() query: NumeroInventarioDto) {
|
||||
return this.equipoService.findByNumeroInventario(
|
||||
parseInt(query.id_institucion),
|
||||
query.numero_inventario,
|
||||
|
||||
@@ -7,7 +7,7 @@ import { IdEquipoPaginaDto } from '../dto/id-equipo-pagina.dto';
|
||||
import { MultarDto } from './dto/input/multar.dto';
|
||||
import { MultasDto } from './dto/input/multas.dto';
|
||||
import { QuitarMultarDto } from './dto/input/quitar.dto';
|
||||
import { MultasUsuarioDto } from './dto/input/multas-usuario.dto';
|
||||
import { IdUsuarioPaginaDto } from '../dto/id-usuario-pagina.dto';
|
||||
import { MultasOutputDto } from './dto/output/multas.dto';
|
||||
import { MultasEquipoOutputDto } from './dto/output/multas-equipo.dto';
|
||||
import { MultasMinOutputDto } from './dto/output/multas-min.dto';
|
||||
@@ -107,7 +107,7 @@ export class MultaController {
|
||||
name: 'pagina',
|
||||
type: 'string',
|
||||
})
|
||||
multasUsuario(@Query() query: MultasUsuarioDto) {
|
||||
multasUsuario(@Query() query: IdUsuarioPaginaDto) {
|
||||
return this.multaService.findAllByIdUsuario(
|
||||
parseInt(query.id_usuario),
|
||||
parseInt(query.pagina),
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { IsNumberString } from 'class-validator';
|
||||
|
||||
export class HistorialEquipoDto {
|
||||
@IsNumberString()
|
||||
id_equipo: string;
|
||||
|
||||
@IsNumberString()
|
||||
pagina: string;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import { IsNumberString } from 'class-validator';
|
||||
|
||||
export class HistorialUsuarioDto {
|
||||
@IsNumberString()
|
||||
pagina: string;
|
||||
|
||||
@IsNumberString()
|
||||
id_usuario: string;
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
import { IsNumberString } from 'class-validator';
|
||||
|
||||
export class IdUsuarioDto {
|
||||
@IsNumberString()
|
||||
id_usuario: string;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsInt, IsNumberString, IsOptional, IsString } from 'class-validator';
|
||||
import { IsInt, IsOptional } from 'class-validator';
|
||||
|
||||
export class PedirDto {
|
||||
@IsInt()
|
||||
@@ -12,9 +12,9 @@ export class PedirDto {
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
id_tipo_entrada?: number;
|
||||
id_programa?: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
id_programa?: number;
|
||||
id_tipo_entrada?: number;
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@ export class RegresarIdPrestamoDto {
|
||||
@IsInt()
|
||||
id_prestamo: number;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
id_institucion_infraccion?: number;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
descripcion?: string;
|
||||
|
||||
@IsInt()
|
||||
@IsOptional()
|
||||
id_institucion_infraccion?: number;
|
||||
}
|
||||
|
||||
@@ -2,20 +2,20 @@ import { Body, Controller, Get, Post, Put, Query } from '@nestjs/common';
|
||||
import { ApiBody, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { PrestamoService } from './prestamo.service';
|
||||
|
||||
import { IdEquipoPaginaDto } from '../dto/id-equipo-pagina.dto';
|
||||
import { IdUsuarioDto } from '../dto/id-usuario.dto';
|
||||
import { IdUsuarioPaginaDto } from '../dto/id-usuario-pagina.dto';
|
||||
import { NumeroInventarioDto } from '../dto/numero-inventario.dto';
|
||||
import { ActivosDto } from './dto/input/activos.dto';
|
||||
import { CancelarUsuarioDto } from './dto/input/cancelar-usuario.dto';
|
||||
import { CancelarOperadorDto } from './dto/input/cancelar-operador.dto';
|
||||
import { HistorialDto } from './dto/input/historial.dto';
|
||||
import { HistorialEquipoDto } from './dto/input/historial-equipo.dto';
|
||||
import { HistorialUsuarioDto } from './dto/input/historial-usuario.dto';
|
||||
import { IdPrestamoDto } from './dto/input/id-prestamo.dto';
|
||||
import { IdUsuarioDto } from './dto/input/id-usuario.dto';
|
||||
import { NumeroInventarioDto } from './dto/input/numero-inventario.dto';
|
||||
import { PedirDto } from './dto/input/pedir.dto';
|
||||
import { EntregarDto } from './dto/input/entregar.dto';
|
||||
import { RegresarIdPrestamoDto } from './dto/input/regresar-id-prestamo.dto';
|
||||
import { RegresarNumeroInventarioDto } from './dto/input/regresar-numero-inventario.dto';
|
||||
|
||||
import { PrestamoOutputDto } from './dto/output/prestamo.dto';
|
||||
import { PrestamoEquipoOutputDto } from './dto/output/prestamo-equipo.dto';
|
||||
import { PrestamosOutputDto } from './dto/output/prestamos.dto';
|
||||
@@ -97,7 +97,9 @@ export class PrestamoController {
|
||||
})
|
||||
@ApiBody({
|
||||
description: 'Ambas variables son obligatorias.',
|
||||
examples: { ejemplo: { value: { id_prestamo: 1, id_operador: 1 } } },
|
||||
examples: {
|
||||
ejemplo: { value: { id_operador: 1, id_prestamo: 1, motivo: '' } },
|
||||
},
|
||||
})
|
||||
cancelarOperador(@Body() body: CancelarOperadorDto) {
|
||||
return this.prestamoService.cancelarOperador(
|
||||
@@ -125,7 +127,7 @@ export class PrestamoController {
|
||||
})
|
||||
@ApiBody({
|
||||
description: 'Ambas variables son obligatorias.',
|
||||
examples: { ejemplo: { value: { id_prestamo: 1, id_operador: 4 } } },
|
||||
examples: { ejemplo: { value: { id_operador: 4, id_prestamo: 1 } } },
|
||||
})
|
||||
entregar(@Body() body: EntregarDto) {
|
||||
return this.prestamoService.entregar(body.id_prestamo, body.id_operador);
|
||||
@@ -212,17 +214,17 @@ export class PrestamoController {
|
||||
description:
|
||||
'Endpoint que retorna 25 prestamos de un usuario dependiendo de la página en la que se encuentra el operador y sus filtros.',
|
||||
})
|
||||
@ApiQuery({
|
||||
description: 'Página en la que se encuentra el usuario.',
|
||||
name: 'pagina',
|
||||
type: 'string',
|
||||
})
|
||||
@ApiQuery({
|
||||
description: 'Id del equipo.',
|
||||
name: 'id_equipo',
|
||||
type: 'string',
|
||||
})
|
||||
historialEquipo(@Query() query: HistorialEquipoDto) {
|
||||
@ApiQuery({
|
||||
description: 'Página en la que se encuentra el usuario.',
|
||||
name: 'pagina',
|
||||
type: 'string',
|
||||
})
|
||||
historialEquipo(@Query() query: IdEquipoPaginaDto) {
|
||||
return this.prestamoService.findAllByIdEquipo(
|
||||
parseInt(query.id_equipo),
|
||||
parseInt(query.pagina),
|
||||
@@ -235,17 +237,17 @@ export class PrestamoController {
|
||||
description:
|
||||
'Endpoint que retorna 25 prestamos de un equipo dependiendo de la página en la que se encuentra el operador y sus filtros.',
|
||||
})
|
||||
@ApiQuery({
|
||||
description: 'Página en la que se encuentra el usuario.',
|
||||
name: 'pagina',
|
||||
type: 'string',
|
||||
})
|
||||
@ApiQuery({
|
||||
description: 'Id del usuario.',
|
||||
name: 'id_usuario',
|
||||
type: 'string',
|
||||
})
|
||||
historialUsuario(@Query() query: HistorialUsuarioDto) {
|
||||
@ApiQuery({
|
||||
description: 'Página en la que se encuentra el usuario.',
|
||||
name: 'pagina',
|
||||
type: 'string',
|
||||
})
|
||||
historialUsuario(@Query() query: IdUsuarioPaginaDto) {
|
||||
return this.prestamoService.findAllByIdUsuario(
|
||||
parseInt(query.id_usuario),
|
||||
parseInt(query.pagina),
|
||||
@@ -261,11 +263,11 @@ export class PrestamoController {
|
||||
examples: {
|
||||
ejemplo: {
|
||||
value: {
|
||||
id_usuario: 1,
|
||||
id_modulo: 1,
|
||||
id_tipo_carrito: 1,
|
||||
id_programa: 1,
|
||||
id_tipo_entrada: 1,
|
||||
id_usuario: 1,
|
||||
_id_programa: 1,
|
||||
_id_tipo_entrada: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -283,7 +285,11 @@ export class PrestamoController {
|
||||
@Serealize(PrestamoOutputDto)
|
||||
@Get('prestamo-id-prestamo')
|
||||
@ApiOperation({ description: 'Endpoint que retorna un préstamo por su id.' })
|
||||
@ApiQuery({ description: '', name: '', type: '' })
|
||||
@ApiQuery({
|
||||
description: 'Id del préstamo.',
|
||||
name: 'id_prestamo',
|
||||
type: 'text',
|
||||
})
|
||||
prestamoIdPrestamo(@Query() query: IdPrestamoDto) {
|
||||
return this.prestamoService.findById(parseInt(query.id_prestamo));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { AppGateway } from '../app.gateway';
|
||||
import { PrestamoController } from './prestamo.controller';
|
||||
import { PrestamoService } from './prestamo.service';
|
||||
import { Prestamo } from './entity/prestamo.entity';
|
||||
@@ -14,7 +15,6 @@ import { ModuloModule } from '../modulo/modulo.module';
|
||||
import { MultaModule } from 'src/multa/multa.module';
|
||||
import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
import { UsuarioModule } from '../usuario/usuario.module';
|
||||
import { AppGateway } from '../app.gateway';
|
||||
@Module({
|
||||
imports: [
|
||||
EquipoModule,
|
||||
@@ -26,8 +26,8 @@ import { AppGateway } from '../app.gateway';
|
||||
ModuloModule,
|
||||
forwardRef(() => MultaModule),
|
||||
OperadorModule,
|
||||
TipoUsuarioModule,
|
||||
TypeOrmModule.forFeature([Prestamo]),
|
||||
TipoUsuarioModule,
|
||||
UsuarioModule,
|
||||
],
|
||||
controllers: [PrestamoController],
|
||||
|
||||
@@ -23,11 +23,14 @@ import { MultaService } from '../multa/multa.service';
|
||||
import { OperadorService } from '../operador/operador.service';
|
||||
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
||||
import { UsuarioService } from '../usuario/usuario.service';
|
||||
import { InstitucionUsuario } from 'src/institucion-usuario/entity/institucion-usuario.entity';
|
||||
import { Modulo } from 'src/modulo/entity/modulo.entity';
|
||||
|
||||
@Injectable()
|
||||
export class PrestamoService {
|
||||
constructor(
|
||||
@InjectRepository(Prestamo) private repository: Repository<Prestamo>,
|
||||
private appGateway: AppGateway,
|
||||
private equipoService: EquipoService,
|
||||
private institucionService: InstitucionService,
|
||||
private institucionDiaService: InstitucionDiaService,
|
||||
@@ -40,7 +43,6 @@ export class PrestamoService {
|
||||
private operadorService: OperadorService,
|
||||
private tipoUsuarioService: TipoUsuarioService,
|
||||
private usuarioService: UsuarioService,
|
||||
private appGateway: AppGateway,
|
||||
) {}
|
||||
|
||||
async cancelarOperador(
|
||||
@@ -52,7 +54,7 @@ export class PrestamoService {
|
||||
const operadorRegreso = await this.operadorService.findById(id_operador);
|
||||
const prestamo = await this.findById(id_prestamo);
|
||||
|
||||
this.validacionBasicaPrestamo(prestamo);
|
||||
this.validacionBasicaPrestamo(prestamo, operadorRegreso);
|
||||
prestamo.activo = false;
|
||||
prestamo.fecha_entrega = ahora.toDate();
|
||||
prestamo.cancelado_operador = true;
|
||||
@@ -101,22 +103,13 @@ export class PrestamoService {
|
||||
id_tipo_entrada?: number,
|
||||
) {
|
||||
const ahora = moment();
|
||||
const mensajeNoPoderPedir = 'No puedes pedir equipos de cómputo porque:';
|
||||
const sistema = await this.operadorService.findById(1);
|
||||
const usuario = await this.usuarioService.findById(id_usuario, true, true);
|
||||
const modulo = await this.moduloService.findById(id_modulo);
|
||||
const usuario = await this.usuarioService.findById(id_usuario, true, true);
|
||||
const tipoCarrito =
|
||||
await this.institucionTipoCarritoService.findTipoCarritoById(
|
||||
id_tipo_carrito,
|
||||
);
|
||||
const programa = id_programa
|
||||
? await this.institucionProgramaService.findProgramaById(id_programa)
|
||||
: null;
|
||||
const tipoEntrada = id_tipo_entrada
|
||||
? await this.institucionTipoEntradaService.findTipoEntradaById(
|
||||
id_tipo_entrada,
|
||||
)
|
||||
: null;
|
||||
const institucionDia = await this.institucionDiaService.findInstitucionDia(
|
||||
modulo.institucion,
|
||||
ahora.weekday(),
|
||||
@@ -127,29 +120,22 @@ export class PrestamoService {
|
||||
const horaMin = moment(
|
||||
`${ahora.format('YYYY-MM-DD')} ${institucionDia.hora_inicio}`,
|
||||
);
|
||||
const programa = id_programa
|
||||
? await this.institucionProgramaService.findProgramaById(id_programa)
|
||||
: null;
|
||||
const tipoEntrada = id_tipo_entrada
|
||||
? await this.institucionTipoEntradaService.findTipoEntradaById(
|
||||
id_tipo_entrada,
|
||||
)
|
||||
: null;
|
||||
|
||||
if (!usuario.activo)
|
||||
throw new ConflictException(
|
||||
`${mensajeNoPoderPedir} tu cuenta esta desactivada.`,
|
||||
`${this.mensajeNoPoderPedir()} tu cuenta esta desactivada.`,
|
||||
);
|
||||
this.validarInstitucionUsuario(usuario.instituciones, modulo);
|
||||
if (ahora.weekday() === 0 || ahora.weekday() === 6)
|
||||
throw new ConflictException('No hay servicio los días sábado y domingo.');
|
||||
for (let i = 0; i < usuario.instituciones.length; i++) {
|
||||
const institucion =
|
||||
usuario.instituciones[i].institucionCarrera.institucion;
|
||||
|
||||
if (institucion.id_institucion === modulo.institucion.id_institucion) {
|
||||
if (!usuario.instituciones[i].activo)
|
||||
throw new ConflictException(
|
||||
`${mensajeNoPoderPedir} tu cuenta esta desactivada en esta institución.`,
|
||||
);
|
||||
if (usuario.instituciones[i].multa)
|
||||
throw new ConflictException(
|
||||
`${mensajeNoPoderPedir} tienes una multa activa.`,
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!institucionDia.activo)
|
||||
throw new ConflictException(
|
||||
'El día de hoy no hay servicio de préstamo de equipos.',
|
||||
@@ -255,7 +241,7 @@ export class PrestamoService {
|
||||
const operadorEntrega = await this.operadorService.findById(id_operador);
|
||||
const prestamo = await this.findById(id_prestamo);
|
||||
|
||||
this.validacionBasicaPrestamo(prestamo);
|
||||
this.validacionBasicaPrestamo(prestamo, operadorEntrega);
|
||||
if (prestamo.equipo.status.id_status === 3)
|
||||
throw new ConflictException(
|
||||
'Ya se entregó el equipo de cómputo al usuario.',
|
||||
@@ -296,21 +282,21 @@ export class PrestamoService {
|
||||
}) {
|
||||
const query = this.repository
|
||||
.createQueryBuilder('p')
|
||||
.innerJoinAndSelect('p.usuario', 'u')
|
||||
.innerJoinAndSelect('u.instituciones', 'is')
|
||||
.innerJoinAndSelect('is.institucionCarrera', 'ic')
|
||||
.innerJoinAndSelect('ic.institucion', 'in')
|
||||
.innerJoinAndSelect('ic.carrera', 'ca')
|
||||
.innerJoinAndSelect('ca.nivel', 'n')
|
||||
.innerJoinAndSelect('p.equipo', 'e')
|
||||
.innerJoinAndSelect('e.carrito', 'c')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('m.institucion', 'i')
|
||||
.innerJoinAndSelect('c.tipoCarrito', 'tc')
|
||||
.innerJoinAndSelect('p.operadorEntrega', 'oe')
|
||||
.innerJoinAndSelect('oe.tipoUsuario', 'tuoe')
|
||||
.innerJoinAndSelect('p.operadorRegreso', 'or')
|
||||
.innerJoinAndSelect('p.usuario', 'u')
|
||||
.innerJoinAndSelect('e.carrito', 'c')
|
||||
.innerJoinAndSelect('oe.tipoUsuario', 'tuoe')
|
||||
.innerJoinAndSelect('or.tipoUsuario', 'tuor')
|
||||
.innerJoinAndSelect('u.instituciones', 'is')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('c.tipoCarrito', 'tc')
|
||||
.innerJoinAndSelect('is.institucionCarrera', 'ic')
|
||||
.innerJoinAndSelect('m.institucion', 'i')
|
||||
.innerJoinAndSelect('ic.carrera', 'ca')
|
||||
.innerJoinAndSelect('ic.institucion', 'in')
|
||||
.innerJoinAndSelect('ca.nivel', 'n')
|
||||
.orderBy('i.institucion')
|
||||
.addOrderBy('m.modulo')
|
||||
.addOrderBy('tc.tipo_carrito')
|
||||
@@ -325,16 +311,6 @@ export class PrestamoService {
|
||||
const modulo = filtros.id_modulo
|
||||
? await this.moduloService.findById(parseInt(filtros.id_modulo))
|
||||
: null;
|
||||
const tipoCarrito = filtros.id_tipo_carrito
|
||||
? await this.institucionTipoCarritoService.findTipoCarritoById(
|
||||
parseInt(filtros.id_tipo_carrito),
|
||||
)
|
||||
: null;
|
||||
const tipoUsuario = filtros.id_tipo_usuario
|
||||
? await this.tipoUsuarioService.findById(
|
||||
parseInt(filtros.id_tipo_usuario),
|
||||
)
|
||||
: null;
|
||||
const operadorEntrega = filtros.id_operador_entrega
|
||||
? await this.operadorService.findById(
|
||||
parseInt(filtros.id_operador_entrega),
|
||||
@@ -345,6 +321,16 @@ export class PrestamoService {
|
||||
parseInt(filtros.id_operador_regreso),
|
||||
)
|
||||
: null;
|
||||
const tipoCarrito = filtros.id_tipo_carrito
|
||||
? await this.institucionTipoCarritoService.findTipoCarritoById(
|
||||
parseInt(filtros.id_tipo_carrito),
|
||||
)
|
||||
: null;
|
||||
const tipoUsuario = filtros.id_tipo_usuario
|
||||
? await this.tipoUsuarioService.findById(
|
||||
parseInt(filtros.id_tipo_usuario),
|
||||
)
|
||||
: null;
|
||||
|
||||
if (filtros.activo) {
|
||||
if (typeof filtros.activo === 'boolean') {
|
||||
@@ -405,19 +391,19 @@ export class PrestamoService {
|
||||
.then((usuario) =>
|
||||
this.repository
|
||||
.createQueryBuilder('p')
|
||||
.innerJoinAndSelect('p.equipo', 'e')
|
||||
.innerJoinAndSelect('p.operadorEntrega', 'oe')
|
||||
.innerJoinAndSelect('p.operadorRegreso', 'or')
|
||||
.innerJoinAndSelect('p.usuario', 'u', 'u.id_usuario = :id_usuario', {
|
||||
id_usuario: usuario.id_usuario,
|
||||
})
|
||||
.innerJoinAndSelect('p.equipo', 'e')
|
||||
.innerJoinAndSelect('e.status', 's')
|
||||
.innerJoinAndSelect('e.carrito', 'c')
|
||||
.innerJoinAndSelect('e.status', 's')
|
||||
.innerJoinAndSelect('oe.tipoUsuario', 'tuoe')
|
||||
.innerJoinAndSelect('or.tipoUsuario', 'tuor')
|
||||
.innerJoinAndSelect('c.tipoCarrito', 'tc')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('m.institucion', 'i')
|
||||
.innerJoinAndSelect('p.operadorEntrega', 'oe')
|
||||
.innerJoinAndSelect('oe.tipoUsuario', 'tuoe')
|
||||
.innerJoinAndSelect('p.operadorRegreso', 'or')
|
||||
.innerJoinAndSelect('or.tipoUsuario', 'tuor')
|
||||
.skip((pagina - 1) * 25)
|
||||
.take(25)
|
||||
.getManyAndCount(),
|
||||
@@ -428,24 +414,24 @@ export class PrestamoService {
|
||||
return this.equipoService.findById(id_equipo).then((equipo) =>
|
||||
this.repository
|
||||
.createQueryBuilder('p')
|
||||
.innerJoinAndSelect('p.usuario', 'u')
|
||||
.innerJoinAndSelect('u.instituciones', 'is')
|
||||
.innerJoinAndSelect('is.institucionCarrera', 'ic')
|
||||
.innerJoinAndSelect('ic.institucion', 'in')
|
||||
.innerJoinAndSelect('ic.carrera', 'ca')
|
||||
.innerJoinAndSelect('ca.nivel', 'n')
|
||||
.innerJoinAndSelect('p.equipo', 'e', 'e.id_equipo = :id_equipo', {
|
||||
id_equipo: equipo.id_equipo,
|
||||
})
|
||||
.innerJoinAndSelect('e.status', 's')
|
||||
.innerJoinAndSelect('e.carrito', 'c')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('m.institucion', 'i')
|
||||
.innerJoinAndSelect('c.tipoCarrito', 'tc')
|
||||
.innerJoinAndSelect('p.operadorEntrega', 'oe')
|
||||
.innerJoinAndSelect('oe.tipoUsuario', 'tuoe')
|
||||
.innerJoinAndSelect('p.operadorRegreso', 'or')
|
||||
.innerJoinAndSelect('p.usuario', 'u')
|
||||
.innerJoinAndSelect('e.carrito', 'c')
|
||||
.innerJoinAndSelect('e.status', 's')
|
||||
.innerJoinAndSelect('oe.tipoUsuario', 'tuoe')
|
||||
.innerJoinAndSelect('or.tipoUsuario', 'tuor')
|
||||
.innerJoinAndSelect('u.instituciones', 'is')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('c.tipoCarrito', 'tc')
|
||||
.innerJoinAndSelect('is.institucionCarrera', 'ic')
|
||||
.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)
|
||||
@@ -456,22 +442,22 @@ export class PrestamoService {
|
||||
findById(id_prestamo: number) {
|
||||
return this.repository
|
||||
.createQueryBuilder('p')
|
||||
.innerJoinAndSelect('p.usuario', 'u')
|
||||
.innerJoinAndSelect('u.instituciones', 'is')
|
||||
.innerJoinAndSelect('is.institucionCarrera', 'ic')
|
||||
.innerJoinAndSelect('ic.institucion', 'in')
|
||||
.innerJoinAndSelect('ic.carrera', 'ca')
|
||||
.innerJoinAndSelect('ca.nivel', 'n')
|
||||
.innerJoinAndSelect('p.equipo', 'e')
|
||||
.innerJoinAndSelect('p.usuario', 'u')
|
||||
.innerJoinAndSelect('e.carrito', 'c')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('m.institucion', 'i')
|
||||
.innerJoinAndSelect('e.programas', 'ps')
|
||||
.innerJoinAndSelect('e.status', 's')
|
||||
.innerJoinAndSelect('e.tiposEntradas', 'tes')
|
||||
.innerJoinAndSelect('tes.tipoEntrada', 'te')
|
||||
.innerJoinAndSelect('e.programas', 'ps')
|
||||
.innerJoinAndSelect('ps.programa', 'pr')
|
||||
.innerJoinAndSelect('u.instituciones', 'is')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('c.tipoCarrito', 'tc')
|
||||
.innerJoinAndSelect('ps.programa', 'pr')
|
||||
.innerJoinAndSelect('tes.tipoEntrada', 'te')
|
||||
.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,
|
||||
})
|
||||
@@ -488,19 +474,19 @@ export class PrestamoService {
|
||||
.then((usuario) =>
|
||||
this.repository
|
||||
.createQueryBuilder('p')
|
||||
.innerJoinAndSelect('p.equipo', 'e')
|
||||
.innerJoinAndSelect('p.usuario', 'u', 'u.id_usuario = :id_usuario', {
|
||||
id_usuario: usuario.id_usuario,
|
||||
})
|
||||
.innerJoinAndSelect('p.equipo', 'e')
|
||||
.innerJoinAndSelect('e.carrito', 'c')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('m.institucion', 'i')
|
||||
.innerJoinAndSelect('e.programas', 'ps')
|
||||
.innerJoinAndSelect('e.status', 's')
|
||||
.innerJoinAndSelect('e.tiposEntradas', 'tes')
|
||||
.innerJoinAndSelect('tes.tipoEntrada', 'te')
|
||||
.innerJoinAndSelect('e.programas', 'ps')
|
||||
.innerJoinAndSelect('ps.programa', 'pr')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('c.tipoCarrito', 'tc')
|
||||
.innerJoinAndSelect('ps.programa', 'pr')
|
||||
.innerJoinAndSelect('tes.tipoEntrada', 'te')
|
||||
.innerJoinAndSelect('m.institucion', 'i')
|
||||
.where('p.activo = 1')
|
||||
.getOne(),
|
||||
)
|
||||
@@ -527,20 +513,20 @@ export class PrestamoService {
|
||||
.then((equipo) =>
|
||||
this.repository
|
||||
.createQueryBuilder('p')
|
||||
.innerJoinAndSelect('p.usuario', 'u')
|
||||
.innerJoinAndSelect('u.instituciones', 'is')
|
||||
.innerJoinAndSelect('is.institucionCarrera', 'ic')
|
||||
.innerJoinAndSelect('ic.institucion', 'in')
|
||||
.innerJoinAndSelect('ic.carrera', 'ca')
|
||||
.innerJoinAndSelect('ca.nivel', 'n')
|
||||
.innerJoinAndSelect('p.equipo', 'e', 'e.id_equipo = :id_equipo', {
|
||||
id_equipo: equipo.id_equipo,
|
||||
})
|
||||
.innerJoinAndSelect('e.status', 's')
|
||||
.innerJoinAndSelect('p.usuario', 'u')
|
||||
.innerJoinAndSelect('e.carrito', 'c')
|
||||
.innerJoinAndSelect('e.status', 's')
|
||||
.innerJoinAndSelect('u.instituciones', 'is')
|
||||
.innerJoinAndSelect('c.modulo', 'm')
|
||||
.innerJoinAndSelect('m.institucion', 'i')
|
||||
.innerJoinAndSelect('c.tipoCarrito', 'tc')
|
||||
.innerJoinAndSelect('is.institucionCarrera', 'ic')
|
||||
.innerJoinAndSelect('m.institucion', 'i')
|
||||
.innerJoinAndSelect('ic.carrera', 'ca')
|
||||
.innerJoinAndSelect('ic.institucion', 'in')
|
||||
.innerJoinAndSelect('ca.nivel', 'n')
|
||||
.where('p.activo = 1')
|
||||
.getOne(),
|
||||
)
|
||||
@@ -553,6 +539,10 @@ export class PrestamoService {
|
||||
});
|
||||
}
|
||||
|
||||
mensajeNoPoderPedir() {
|
||||
return 'No puedes pedir equipos de cómputo porque:';
|
||||
}
|
||||
|
||||
async regresar(
|
||||
prestamo: Prestamo,
|
||||
operadorRegreso: Operador,
|
||||
@@ -565,7 +555,7 @@ export class PrestamoService {
|
||||
tardanza / operadorRegreso.institucion.tiempo_entrega,
|
||||
);
|
||||
|
||||
this.validacionBasicaPrestamo(prestamo);
|
||||
this.validacionBasicaPrestamo(prestamo, operadorRegreso);
|
||||
if (prestamo.equipo.status.id_status === 2)
|
||||
throw new ConflictException(
|
||||
'Aún no se ha entregado el equipo de cómputo al usuario.',
|
||||
@@ -649,7 +639,7 @@ export class PrestamoService {
|
||||
);
|
||||
}
|
||||
|
||||
validacionBasicaPrestamo(prestamo: Prestamo) {
|
||||
validacionBasicaPrestamo(prestamo: Prestamo, operador?: Operador) {
|
||||
if (prestamo.cancelado_usuario)
|
||||
throw new ConflictException(
|
||||
'Este préstamo fue cancelado por el usuario.',
|
||||
@@ -660,5 +650,38 @@ export class PrestamoService {
|
||||
);
|
||||
if (!prestamo.activo)
|
||||
throw new ConflictException('Este préstamo ya no se encuentra activo.');
|
||||
if (
|
||||
operador &&
|
||||
operador.institucion.id_institucion !=
|
||||
prestamo.equipo.carrito.modulo.institucion.id_institucion
|
||||
) {
|
||||
throw new ConflictException(
|
||||
'Este préstamo no pertenece a esta institución.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
validarInstitucionUsuario(
|
||||
instituciones: InstitucionUsuario[],
|
||||
modulo: Modulo,
|
||||
) {
|
||||
for (let i = 0; i < instituciones.length; i++) {
|
||||
const institucion = instituciones[i].institucionCarrera.institucion;
|
||||
|
||||
if (institucion.id_institucion === modulo.institucion.id_institucion) {
|
||||
if (!instituciones[i].activo)
|
||||
throw new ConflictException(
|
||||
`${this.mensajeNoPoderPedir()} tu cuenta esta desactivada en esta institución.`,
|
||||
);
|
||||
if (instituciones[i].multa)
|
||||
throw new ConflictException(
|
||||
`${this.mensajeNoPoderPedir()} tienes una multa activa.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new ConflictException(
|
||||
`${this.mensajeNoPoderPedir()} no perteneces a esta institución.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,17 +11,6 @@ import { TipoUsuarioOutputDto } from './dto/output/tipo-usuario.dto';
|
||||
export class TipoUsuarioController {
|
||||
constructor(private tipoUsuarioService: TipoUsuarioService) {}
|
||||
|
||||
@Serealize(TipoUsuarioOutputDto)
|
||||
@Get('admin')
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
description:
|
||||
'Endpoint que retorna todos los tipos de usuario que debe ver un admin.',
|
||||
})
|
||||
admin() {
|
||||
return this.tipoUsuarioService.findAll('admin');
|
||||
}
|
||||
|
||||
@Post()
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({ description: 'Endpoint que crea un nuevo tipo de usuario.' })
|
||||
@@ -53,15 +42,4 @@ export class TipoUsuarioController {
|
||||
operador() {
|
||||
return this.tipoUsuarioService.findAll('operador');
|
||||
}
|
||||
|
||||
@Serealize(TipoUsuarioOutputDto)
|
||||
@Get('super-admin')
|
||||
// @UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
description:
|
||||
'Endpoint que retorna todos los tipos de usuario que debe ver un super admin.',
|
||||
})
|
||||
superAdmin() {
|
||||
return this.tipoUsuarioService.findAll('super admin');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +32,8 @@ export class TipoUsuarioService {
|
||||
.where('tu.id_tipo_usuario != 1 AND tu.id_tipo_usuario != 2')
|
||||
.orderBy('tu.tipo_usuario');
|
||||
|
||||
if (informacion === 'super admin' || informacion === 'admin')
|
||||
query.andWhere('tu.id_tipo_usuario < 5');
|
||||
if (informacion === 'admin') query.andWhere('tu.id_tipo_usuario != 3');
|
||||
if (informacion === 'operador') query.andWhere('tu.id_tipo_usuario > 4');
|
||||
if (informacion && informacion === 'operador')
|
||||
query.andWhere('tu.id_tipo_usuario > 4');
|
||||
return query.getMany();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IsString } from 'class-validator';
|
||||
import { IsNumberString, IsString } from 'class-validator';
|
||||
|
||||
export class DgpInputDto {
|
||||
@IsString()
|
||||
@IsNumberString()
|
||||
id_institucion: string;
|
||||
|
||||
@IsString()
|
||||
|
||||
@@ -126,11 +126,11 @@ export class UsuarioService {
|
||||
}) {
|
||||
const query = this.repository
|
||||
.createQueryBuilder('u')
|
||||
.innerJoinAndSelect('u.tipoUsuario', 'tu')
|
||||
.innerJoinAndSelect('u.instituciones', 'is')
|
||||
.innerJoinAndSelect('u.tipoUsuario', 'tu')
|
||||
.innerJoinAndSelect('is.institucionCarrera', 'ic')
|
||||
.innerJoinAndSelect('ic.institucion', 'i')
|
||||
.innerJoinAndSelect('ic.carrera', 'c')
|
||||
.innerJoinAndSelect('ic.institucion', 'i')
|
||||
.innerJoinAndSelect('c.nivel', 'n')
|
||||
.take(25)
|
||||
.skip((parseInt(filtros.pagina) - 1) * 25)
|
||||
@@ -250,25 +250,28 @@ export class UsuarioService {
|
||||
|
||||
registrar(id_institucion_usuario: number, telefono: string, correo?: string) {
|
||||
const password = this.generarPassword();
|
||||
let message =
|
||||
'Se creó correctamente tu cuenta, ingresa a tu correo institucional y consulta tu contraseña para acceder a este servicio.';
|
||||
|
||||
return this.institucionUsuarioService
|
||||
.findById(id_institucion_usuario)
|
||||
.then((institucionUsuario) => {
|
||||
const usuario = institucionUsuario.usuario;
|
||||
const institucion = institucionUsuario.institucionCarrera.institucion;
|
||||
const usuario = institucionUsuario.usuario;
|
||||
|
||||
if (usuario.password)
|
||||
throw new ConflictException(
|
||||
'Ya fue registrado este número de cuenta.',
|
||||
);
|
||||
if (!institucion.email_institucional && !correo)
|
||||
throw new ConflictException(
|
||||
'No se envió un correo electrónico para el regístro.',
|
||||
);
|
||||
else if (!institucion.email_institucional && correo)
|
||||
usuario.correo = correo;
|
||||
else if (institucion.email_institucional)
|
||||
usuario.correo = `${usuario.usuario}${institucion.dominio}`;
|
||||
if (!institucion.email_institucional) {
|
||||
if (!correo)
|
||||
throw new ConflictException(
|
||||
'No se envió un correo electrónico para el regístro.',
|
||||
);
|
||||
else usuario.correo = correo;
|
||||
message =
|
||||
'Se creó correctamente tu cuenta, ingresa a tu correo y consulta tu contraseña para acceder a este servicio.';
|
||||
} else usuario.correo = `${usuario.usuario}${institucion.dominio}`;
|
||||
usuario.telefono = telefono;
|
||||
usuario.password = this.bcryptService.encriptar(password);
|
||||
return this.repository.save(usuario);
|
||||
@@ -280,10 +283,7 @@ export class UsuarioService {
|
||||
html: this.correoPassword(password),
|
||||
}),
|
||||
)
|
||||
.then((_) => ({
|
||||
message:
|
||||
'Se creó correctamente tu cuenta, ingresa a tu correo institucional y consulta tu contraseña para acceder a este servicio.',
|
||||
}));
|
||||
.then((_) => ({ message }));
|
||||
}
|
||||
|
||||
update(attrs: Partial<Usuario>, validarPassword = true) {
|
||||
|
||||
Reference in New Issue
Block a user