passcode controller and service
This commit is contained in:
@@ -168,7 +168,6 @@ import { Usuario } from './usuario/entity/usuario.entity';
|
||||
TipoUsuarioModule,
|
||||
UploadFileModule,
|
||||
UsuarioModule,
|
||||
PasscodeModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
+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,8 @@ import {
|
||||
@Column({ type: String, nullable: false })
|
||||
passcode: string;
|
||||
|
||||
@Column({ type: Boolean, nullable: true })
|
||||
abrio: boolean
|
||||
|
||||
@OneToOne(() => Prestamo, (Prestamo) => Prestamo.id_prestamo, {
|
||||
eager: true,
|
||||
|
||||
@@ -1,4 +1,114 @@
|
||||
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 {}
|
||||
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, 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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,14 +1,17 @@
|
||||
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){
|
||||
const prestamo = {
|
||||
@@ -29,5 +32,38 @@ export class PasscodeService {
|
||||
}),
|
||||
)
|
||||
return passcode
|
||||
}
|
||||
}
|
||||
|
||||
entregarEquipo(passcode){
|
||||
passcode += ''
|
||||
let id_prestamo = passcode.substring(2,8)
|
||||
return this.prestamoService.entregar(parseInt(id_prestamo), 5);
|
||||
}
|
||||
|
||||
devolverEquipo(passcode){
|
||||
passcode += ''
|
||||
const id_prestamo = passcode.substring(2,8)
|
||||
|
||||
return this.prestamoService.regresarIdPrestamo(
|
||||
5,
|
||||
parseInt(id_prestamo)
|
||||
);
|
||||
}
|
||||
|
||||
findByPasscode(passcode: string, id_locker: string){
|
||||
let door = ""
|
||||
return this.repository.findOne({where: {passcode}})
|
||||
.then(async(passcode) => {
|
||||
if(!passcode)
|
||||
throw new BadRequestException(
|
||||
`Este passcode no existe`,
|
||||
);
|
||||
|
||||
await this.prestamoService.findById(passcode.prestamo.id_prestamo).then((prestamo)=>{
|
||||
door = prestamo.equipo.equipo.substring(1,3)
|
||||
|
||||
})
|
||||
return {...passcode, code: 1, id_locker, door: parseInt(door)}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
@@ -125,34 +122,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({
|
||||
@@ -506,63 +475,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,11 +12,12 @@ 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';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
EquipoModule,
|
||||
@@ -28,7 +29,7 @@ import { UsuarioModule } from '../usuario/usuario.module';
|
||||
ModuloModule,
|
||||
forwardRef(() => MultaModule),
|
||||
OperadorModule,
|
||||
PasscodeModule,
|
||||
forwardRef(() => PasscodeModule),
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
TypeOrmModule.forFeature([Prestamo]),
|
||||
TipoUsuarioModule,
|
||||
|
||||
@@ -47,6 +47,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,8 +206,9 @@ export class PrestamoService {
|
||||
),
|
||||
)
|
||||
.then((prestamo) => {
|
||||
// if(){
|
||||
|
||||
// if(id_tipo_carrito === 4 || id_tipo_carrito === 5){
|
||||
// const passcode = this.passcodeService.crearPasscode(id_tipo_carrito.toString(), prestamo.id_prestamo.toString())
|
||||
// this.appGateway.actualizarOperador(modulo.institucion.id_institucion);
|
||||
// }
|
||||
const passcode = this.passcodeService.crearPasscode(id_tipo_carrito.toString(), prestamo.id_prestamo.toString())
|
||||
this.appGateway.actualizarOperador(modulo.institucion.id_institucion);
|
||||
|
||||
Reference in New Issue
Block a user