Merge branch 'saavedra' of https://repositorio.acatlan.unam.mx/CIDWA/pcpuma_unam_api into dev
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ import { Socket, Server } from 'socket.io';
|
||||
@WebSocketGateway({
|
||||
cors: {
|
||||
origin: [
|
||||
// 'http://localhost:3176',
|
||||
'http://localhost:3176',
|
||||
// 'http://localhost:3186',
|
||||
// 'http://132.248.80.196:3155',
|
||||
// 'http://132.248.80.196:3185',
|
||||
|
||||
+1
-4
@@ -2,10 +2,7 @@ import {
|
||||
IsInt
|
||||
} from 'class-validator';
|
||||
|
||||
export class RegresarAutoprestamoDto {
|
||||
@IsInt()
|
||||
id_operador: number;
|
||||
|
||||
export class DevolucionDto {
|
||||
@IsInt()
|
||||
passcode: number;
|
||||
}
|
||||
+2
-5
@@ -1,12 +1,9 @@
|
||||
import { IsInt } from 'class-validator';
|
||||
|
||||
export class AutoprestamoDto {
|
||||
export class NotificacionDto {
|
||||
@IsInt()
|
||||
passcode: number;
|
||||
|
||||
@IsInt()
|
||||
id_locker: number;
|
||||
|
||||
@IsInt()
|
||||
id_operador: number;
|
||||
estatus: number;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class PrestamoDto {
|
||||
// verificar si es entero o string
|
||||
@IsString()
|
||||
passcode: string;
|
||||
|
||||
@IsString()
|
||||
id_locker: string;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import { Expose } from 'class-transformer';
|
||||
|
||||
export class DevolucionOutputDto {
|
||||
@Expose()
|
||||
code;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
import { Expose } from 'class-transformer';
|
||||
|
||||
export class NotificacionOutputDto {
|
||||
@Expose()
|
||||
code;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Expose } from 'class-transformer';
|
||||
|
||||
export class PasscodeOutputDto {
|
||||
@Expose()
|
||||
code;
|
||||
|
||||
@Expose()
|
||||
passcode;
|
||||
|
||||
@Expose()
|
||||
id_locker;
|
||||
|
||||
@Expose()
|
||||
door;
|
||||
}
|
||||
@@ -15,6 +15,9 @@ import {
|
||||
@Column({ type: String, nullable: false })
|
||||
passcode: string;
|
||||
|
||||
@Column({ type: Boolean, nullable: true, default: false })
|
||||
abrio: boolean
|
||||
|
||||
|
||||
@OneToOne(() => Prestamo, (Prestamo) => Prestamo.id_prestamo, {
|
||||
eager: true,
|
||||
|
||||
@@ -1,4 +1,115 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
import { Body,Controller, ForbiddenException,Get, Query,Request, Put, UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
ApiBearerAuth,
|
||||
ApiBody,
|
||||
ApiOperation,
|
||||
ApiQuery,
|
||||
ApiTags,
|
||||
} from '@nestjs/swagger';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { Serealize } from '../interceptors/serialize.interceptor';
|
||||
import { DevolucionDto } from './dto/input/devolucion.dto'
|
||||
import { DevolucionOutputDto } from './dto/output/devolucion.dto';
|
||||
import { PasscodeService } from './passcode.service'
|
||||
import { NotificacionDto } from './dto/input/notificacion.dto';
|
||||
import { NotificacionOutputDto } from './dto/output/notificacion.dto';
|
||||
import { Operador } from '../operador/entity/operador.entity';
|
||||
import { PrestamoDto } from './dto/input/prestamo.dto';
|
||||
import { PasscodeOutputDto } from './dto/output/passcode.dto';
|
||||
|
||||
|
||||
|
||||
@Controller('passcode')
|
||||
export class PasscodeController {}
|
||||
@ApiTags('passcode')
|
||||
export class PasscodeController {
|
||||
constructor(private passcodeService: PasscodeService) {}
|
||||
@Serealize(PasscodeOutputDto)
|
||||
@Get('prestamo')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({ description: 'Endpoint que verifica la existencia y validez del passcode.' })
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiQuery({
|
||||
description: 'Passcode del préstamo',
|
||||
name: 'passcode',
|
||||
type: 'string',
|
||||
})
|
||||
@ApiQuery({
|
||||
description: 'id_locker, un locker hace referencia a un carrito.',
|
||||
name: 'id_locker',
|
||||
type: 'string',
|
||||
})
|
||||
prestamo(@Request() req, @Query() query: PrestamoDto) {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
if (
|
||||
!operador ||
|
||||
(operador.tipoUsuario.id_tipo_usuario != 3 &&
|
||||
operador.tipoUsuario.id_tipo_usuario != 4)
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
|
||||
|
||||
return this.passcodeService.findByPasscode(query.passcode, false,query.id_locker);
|
||||
}
|
||||
|
||||
@Serealize(NotificacionOutputDto)
|
||||
@Put('notificacion')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
description: 'Endpoint que actualiza el status del equipo a "En uso" por medio del autoprestamo.',
|
||||
})
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiBody({
|
||||
description: 'Ambas variables son obligatorias.',
|
||||
examples: { ejemplo: { value: { passcode: 123456789012, estatus: 1 } } },
|
||||
})
|
||||
autoprestamo(@Request() req, @Body() body: NotificacionDto) {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
if (
|
||||
!operador ||
|
||||
(operador.tipoUsuario.id_tipo_usuario != 3 &&
|
||||
operador.tipoUsuario.id_tipo_usuario != 4)
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
|
||||
return this.passcodeService.entregarEquipo(body.passcode, body.estatus, operador);
|
||||
}
|
||||
|
||||
@Serealize(DevolucionOutputDto)
|
||||
@Put('devolucion')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({ description: 'Endpoint que da por terminado un préstamo.' })
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiBody({
|
||||
description: 'Solo necesitamos el passcode.',
|
||||
examples: {
|
||||
ejemplo: {
|
||||
value: {
|
||||
passcode: 123456789012,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
devolucion(
|
||||
@Request() req,
|
||||
@Body() body: DevolucionDto,
|
||||
) {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
if (
|
||||
!operador ||
|
||||
(operador.tipoUsuario.id_tipo_usuario != 3 &&
|
||||
operador.tipoUsuario.id_tipo_usuario != 4)
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
|
||||
return this.passcodeService.devolverEquipo(body.passcode, operador);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { PasscodeController } from './passcode.controller';
|
||||
import { PasscodeService } from './passcode.service';
|
||||
import { Passcode } from './entity/passcode.entity'
|
||||
import { PrestamoModule } from '../prestamo/prestamo.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
forwardRef(()=>PrestamoModule),
|
||||
TypeOrmModule.forFeature([Passcode]),
|
||||
],
|
||||
controllers: [PasscodeController],
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { BadRequestException, forwardRef, Injectable, Inject } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { createQueryBuilder, Repository } from 'typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Passcode} from './entity/passcode.entity'
|
||||
import { Prestamo } from '../prestamo/entity/prestamo.entity';
|
||||
import { PrestamoService } from '../prestamo/prestamo.service';
|
||||
|
||||
@Injectable()
|
||||
export class PasscodeService {
|
||||
constructor(
|
||||
@InjectRepository(Passcode) private repository: Repository<Passcode>,
|
||||
){}
|
||||
@Inject(forwardRef(() => PrestamoService))
|
||||
private prestamoService: PrestamoService,
|
||||
){}
|
||||
|
||||
crearPasscode(id_tipo_carrito, id_prestamo){
|
||||
crearPasscode(id_carrito, id_prestamo){
|
||||
const prestamo = {
|
||||
1: "00000",
|
||||
2: "0000",
|
||||
@@ -19,9 +21,7 @@ export class PasscodeService {
|
||||
5: "0",
|
||||
}
|
||||
|
||||
const passcode = "30" + prestamo[id_prestamo.length] + id_prestamo + Math.floor(Math.random() * 99999).toString()
|
||||
// const passcode = id_tipo_carrito + prestamo[id_prestamo.length] + id_prestamo + Math.floor(Math.random() * 99999).toString()
|
||||
// console.log(passcode)
|
||||
const passcode = id_carrito + prestamo[id_prestamo.length] + id_prestamo + Math.floor((Math.random() * 99999) + 10000).toString()
|
||||
this.repository.save(
|
||||
this.repository.create({
|
||||
passcode,
|
||||
@@ -29,5 +29,67 @@ export class PasscodeService {
|
||||
}),
|
||||
)
|
||||
return passcode
|
||||
}
|
||||
}
|
||||
|
||||
async devolverEquipo(passcode, operador){
|
||||
passcode += ''
|
||||
const passcodeInterno = await this.findByPasscode(passcode, true)
|
||||
|
||||
return this.prestamoService.regresarIdPrestamo(
|
||||
operador.id_operador,
|
||||
passcodeInterno.prestamo.id_prestamo
|
||||
).then((_)=> {
|
||||
return {code: 1}
|
||||
})
|
||||
}
|
||||
|
||||
async entregarEquipo(passcode, estatus, operador){
|
||||
const passcodeInterno = await this.findByPasscode(passcode, false)
|
||||
if(estatus){
|
||||
if(passcodeInterno.abrio != estatus)
|
||||
passcodeInterno.abrio = estatus===1? true : false
|
||||
return this.prestamoService.entregar(passcodeInterno.prestamo.id_prestamo, operador.id_operador).then((_) => {
|
||||
return this.repository.save(passcodeInterno).then((_) =>{
|
||||
return {code: 1}
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
findByPasscode(passcode: string, abrio ?: boolean, id_locker ?: string){
|
||||
let door = ""
|
||||
return this.repository.findOne({where: {passcode, abrio}})
|
||||
.then(async(passcode) => {
|
||||
if(!passcode){
|
||||
throw new BadRequestException({
|
||||
message: `Este passcode no existe`, code: 6
|
||||
});
|
||||
}
|
||||
if(id_locker){
|
||||
await this.prestamoService.findById(passcode.prestamo.id_prestamo).then((prestamo)=>{
|
||||
if(prestamo.equipo.carrito.id_carrito != parseInt(id_locker)){
|
||||
throw new BadRequestException({
|
||||
message: `El id_locker no corresponde`, code: 4
|
||||
});
|
||||
}
|
||||
door = prestamo.equipo.equipo.substring(1,3)
|
||||
|
||||
})
|
||||
return {...passcode, code: 1, id_locker, door: parseInt(door)}
|
||||
}
|
||||
return passcode
|
||||
})
|
||||
}
|
||||
|
||||
findPasscode(id_prestamo: number){
|
||||
return this.repository.findOne({where: {prestamo: {id_prestamo}}})
|
||||
.then(async(passcode) => {
|
||||
if(!passcode)
|
||||
throw new BadRequestException({
|
||||
message: `Este passcode no existe`, code: 6
|
||||
})
|
||||
return passcode.passcode
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@ 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 { PasscodeDto } from '../dto/passcode.dto';
|
||||
import { AutoprestamoDto} from './dto/input/autoprestamo.dto'
|
||||
import { ActivosDto } from './dto/input/activos.dto';
|
||||
import { CancelarUsuarioDto } from './dto/input/cancelar-usuario.dto';
|
||||
import { CancelarOperadorDto } from './dto/input/cancelar-operador.dto';
|
||||
@@ -35,7 +33,6 @@ 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 { RegresarAutoprestamoDto } from './dto/input/regresar-autoprestamo.dto';
|
||||
import { ActivosOutputDto } from './dto/output/activos.dto';
|
||||
import { EntregaOutputDto } from './dto/output/entrega.dto';
|
||||
import { PrestamoOutputDto } from './dto/output/prestamo.dto';
|
||||
@@ -121,34 +118,6 @@ export class PrestamoController {
|
||||
return this.prestamoService.findAll(query);
|
||||
}
|
||||
|
||||
@Serealize(EntregaOutputDto)
|
||||
@Put('autoprestamo')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
description: 'Endpoint que actualiza el status del equipo a "En uso" por medio del autoprestamo.',
|
||||
})
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiBody({
|
||||
description: 'Ambas variables son obligatorias.',
|
||||
examples: { ejemplo: { value: { passcode: 123456789012, id_locker: 30 } } },
|
||||
})
|
||||
autoprestamo(@Request() req, @Body() body: AutoprestamoDto) {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
if (
|
||||
!operador ||
|
||||
(operador.tipoUsuario.id_tipo_usuario != 3 &&
|
||||
operador.tipoUsuario.id_tipo_usuario != 4)
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
const passcode = body.passcode + ''
|
||||
let id_prestamo = passcode.substring(2,8)
|
||||
|
||||
return this.prestamoService.entregar(parseInt(id_prestamo), body.id_operador);
|
||||
}
|
||||
|
||||
@Put('cancelar-operador')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({
|
||||
@@ -389,10 +358,10 @@ export class PrestamoController {
|
||||
const usuarioOperador: Operador | Usuario =
|
||||
req.user.operador || req.user.usuario;
|
||||
|
||||
if ('id_usuario' in usuarioOperador)
|
||||
if ('id_usuario' in usuarioOperador)
|
||||
this.validarUsuarioService.validarUsuario(usuarioOperador);
|
||||
else this.validarUsuarioService.validarAdminOperador(usuarioOperador);
|
||||
return this.prestamoService.findById(parseInt(query.id_prestamo));
|
||||
else this.validarUsuarioService.validarAdminOperador(usuarioOperador);
|
||||
return this.prestamoService.findByIdController(parseInt(query.id_prestamo));
|
||||
}
|
||||
|
||||
@Serealize(PrestamoOutputDto)
|
||||
@@ -412,7 +381,9 @@ export class PrestamoController {
|
||||
const usuario: Usuario = req.user.usuario;
|
||||
|
||||
this.validarUsuarioService.validarUsuario(usuario);
|
||||
return this.prestamoService.findByIdUsuario(parseInt(query.id_usuario));
|
||||
return this.prestamoService.findByIdUsuario(parseInt(query.id_usuario)).catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
|
||||
@Serealize(PrestamoEquipoOutputDto)
|
||||
@@ -446,63 +417,6 @@ export class PrestamoController {
|
||||
);
|
||||
}
|
||||
|
||||
// prestamoPasscode(
|
||||
// @Request() req,
|
||||
// @Query() query: PasscodeDto,
|
||||
// ) {
|
||||
// const operador: Operador = req.user.operador;
|
||||
|
||||
// if (
|
||||
// !operador ||
|
||||
// (operador.tipoUsuario.id_tipo_usuario != 1)
|
||||
// )
|
||||
// throw new ForbiddenException(
|
||||
// 'No tienes los permisos necesarios para realizar esta acción.',
|
||||
// );
|
||||
// //revisar el tipo de dato del id_locker o id_carrito
|
||||
// return this.prestamoService.findByNumeroInventario(
|
||||
// parseInt(query.passcode),
|
||||
// query.id_locker,
|
||||
// );
|
||||
// }
|
||||
|
||||
@Put('regresar-autoprestamo')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({ description: 'Endpoint que desactiva un autopréstamo.' })
|
||||
@ApiBearerAuth('jwt')
|
||||
@ApiBody({
|
||||
description: 'Solo necesitamos el passcode.',
|
||||
examples: {
|
||||
ejemplo: {
|
||||
value: {
|
||||
passcode: 123456789012,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
regresarAutoprestamo(
|
||||
@Request() req,
|
||||
@Body() body: RegresarAutoprestamoDto,
|
||||
) {
|
||||
const operador: Operador = req.user.operador;
|
||||
|
||||
if (
|
||||
!operador ||
|
||||
(operador.tipoUsuario.id_tipo_usuario != 3 &&
|
||||
operador.tipoUsuario.id_tipo_usuario != 4)
|
||||
)
|
||||
throw new ForbiddenException(
|
||||
'No tienes los permisos necesarios para realizar esta acción.',
|
||||
);
|
||||
const passcode = body.passcode + ''
|
||||
const id_prestamo = passcode.substring(2,8)
|
||||
|
||||
return this.prestamoService.regresarIdPrestamo(
|
||||
body.id_operador,
|
||||
parseInt(id_prestamo)
|
||||
);
|
||||
}
|
||||
|
||||
@Put('regresar-id-prestamo')
|
||||
@UseGuards(AuthGuard('jwt'))
|
||||
@ApiOperation({ description: 'Endpoint que desactiva un préstamo.' })
|
||||
|
||||
@@ -12,9 +12,9 @@ import { InstitucionProgramaModule } from '../institucion-programa/institucion-p
|
||||
import { InstitucionTipoCarritoModule } from '../institucion-tipo-carrito/institucion-tipo-carrito.module';
|
||||
import { InstitucionTipoEntradaModule } from '../institucion-tipo-entrada/institucion-tipo-entrada.module';
|
||||
import { OperadorModule } from '../operador/operador.module';
|
||||
import { PasscodeModule } from '../passcode/passcode.module';
|
||||
import { ModuloModule } from '../modulo/modulo.module';
|
||||
import { MultaModule } from '../multa/multa.module';
|
||||
import { PasscodeModule } from '../passcode/passcode.module';
|
||||
import { TipoUsuarioModule } from '../tipo-usuario/tipo-usuario.module';
|
||||
import { UsuarioModule } from '../usuario/usuario.module';
|
||||
import { ValidarUsuarioModule } from '../validar-usuario/validar-usuario.module';
|
||||
@@ -30,7 +30,7 @@ import { ValidarUsuarioModule } from '../validar-usuario/validar-usuario.module'
|
||||
ModuloModule,
|
||||
forwardRef(() => MultaModule),
|
||||
OperadorModule,
|
||||
PasscodeModule,
|
||||
forwardRef(() => PasscodeModule),
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
TypeOrmModule.forFeature([Prestamo]),
|
||||
TipoUsuarioModule,
|
||||
|
||||
@@ -31,6 +31,7 @@ import { OperadorService } from '../operador/operador.service';
|
||||
import { TipoUsuarioService } from '../tipo-usuario/tipo-usuario.service';
|
||||
import { UsuarioService } from '../usuario/usuario.service';
|
||||
import { PasscodeService } from '../passcode/passcode.service';
|
||||
import { Passcode } from 'src/passcode/entity/passcode.entity';
|
||||
|
||||
@Injectable()
|
||||
export class PrestamoService {
|
||||
@@ -47,6 +48,7 @@ export class PrestamoService {
|
||||
@Inject(forwardRef(() => MultaService))
|
||||
private multaService: MultaService,
|
||||
private operadorService: OperadorService,
|
||||
@Inject(forwardRef(() => PasscodeService))
|
||||
private passcodeService : PasscodeService,
|
||||
private tipoUsuarioService: TipoUsuarioService,
|
||||
private usuarioService: UsuarioService,
|
||||
@@ -205,10 +207,10 @@ export class PrestamoService {
|
||||
),
|
||||
)
|
||||
.then((prestamo) => {
|
||||
// if(){
|
||||
let passcode = ""
|
||||
if(id_tipo_carrito === 4 || id_tipo_carrito === 5)
|
||||
passcode = this.passcodeService.crearPasscode(prestamo.equipo.carrito.id_carrito.toString(), prestamo.id_prestamo.toString())
|
||||
|
||||
// }
|
||||
const passcode = this.passcodeService.crearPasscode(id_tipo_carrito.toString(), prestamo.id_prestamo.toString())
|
||||
this.appGateway.actualizarOperador(modulo.institucion.id_institucion);
|
||||
return {...prestamo, passcode};
|
||||
});
|
||||
@@ -262,10 +264,8 @@ export class PrestamoService {
|
||||
: null;
|
||||
|
||||
this.validacionBasicaPrestamo(prestamo, operadorEntrega);
|
||||
if (prestamo.equipo.status.id_status === 3)
|
||||
throw new ConflictException(
|
||||
'Ya se entregó el equipo de cómputo al usuario.',
|
||||
);
|
||||
if (prestamo.equipo.status.id_status === 3)
|
||||
throw new ConflictException('Ya se entregó el equipo de cómputo al usuario.');
|
||||
prestamo.hora_inicio = ahora.toDate();
|
||||
prestamo.hora_fin =
|
||||
ahora > horaMax
|
||||
@@ -500,12 +500,46 @@ export class PrestamoService {
|
||||
id_prestamo,
|
||||
})
|
||||
.getOne()
|
||||
.then((prestamo) => {
|
||||
.then(async (prestamo) => {
|
||||
if (!prestamo) throw new NotFoundException('No existe este préstamo.');
|
||||
return prestamo;
|
||||
});
|
||||
}
|
||||
|
||||
findByIdController(id_prestamo: number) {
|
||||
return this.repository
|
||||
.createQueryBuilder('p')
|
||||
.innerJoinAndSelect('p.equipo', 'e')
|
||||
.innerJoinAndSelect('p.usuario', 'u')
|
||||
.innerJoinAndSelect('e.carrito', 'c')
|
||||
.innerJoinAndSelect('e.programas', 'ps')
|
||||
.innerJoinAndSelect('e.status', 's')
|
||||
.innerJoinAndSelect('e.tiposEntradas', 'tes')
|
||||
.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,
|
||||
})
|
||||
.getOne()
|
||||
.then(async (prestamo) => {
|
||||
if (!prestamo) throw new NotFoundException('No existe este préstamo.');
|
||||
if(prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 4 || prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 5)
|
||||
{
|
||||
const passcode = await this.passcodeService.findPasscode(prestamo.id_prestamo)
|
||||
return {...prestamo, passcode}
|
||||
}
|
||||
return prestamo;
|
||||
});
|
||||
}
|
||||
|
||||
findByIdUsuario(id_usuario: number) {
|
||||
return this.usuarioService
|
||||
.findById(id_usuario, true, true)
|
||||
@@ -528,15 +562,24 @@ export class PrestamoService {
|
||||
.where('p.activo = 1')
|
||||
.getOne(),
|
||||
)
|
||||
.then((prestamo) => {
|
||||
.then(async (prestamo) => {
|
||||
if (!prestamo)
|
||||
throw new NotFoundException(
|
||||
'Este usuario no tiene un préstamo activo.',
|
||||
);
|
||||
if(prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 4 || prestamo.equipo.carrito.tipoCarrito.id_tipo_carrito === 5)
|
||||
{
|
||||
const passcode = await this.passcodeService.findPasscode(prestamo.id_prestamo)
|
||||
console.log(passcode)
|
||||
return {...prestamo, passcode}
|
||||
}
|
||||
return prestamo;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
async findByNumeroInventario(
|
||||
id_institucion: number | Institucion,
|
||||
numero_inventario: string,
|
||||
@@ -696,22 +739,28 @@ export class PrestamoService {
|
||||
|
||||
validacionBasicaPrestamo(prestamo: Prestamo, operador?: Operador) {
|
||||
if (prestamo.cancelado_usuario)
|
||||
throw new ConflictException(
|
||||
'Este préstamo fue cancelado por el usuario.',
|
||||
throw new ConflictException({
|
||||
|
||||
messsage: 'Este préstamo fue cancelado por el usuario.', code: 3
|
||||
}
|
||||
);
|
||||
if (prestamo.cancelado_operador)
|
||||
throw new ConflictException(
|
||||
'Este préstamo fue cancelado por un operador.',
|
||||
throw new ConflictException({
|
||||
|
||||
message: 'Este préstamo fue cancelado por un operador.', code : 3
|
||||
}
|
||||
);
|
||||
if (!prestamo.activo)
|
||||
throw new ConflictException('Este préstamo ya no se encuentra activo.');
|
||||
throw new ConflictException({message: 'Este préstamo ya no se encuentra activo.', code:5});
|
||||
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.',
|
||||
throw new ConflictException({
|
||||
|
||||
message: 'Este préstamo no pertenece a esta institución.', code: 2
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user