2022-10-31 12:16:34 -06:00
|
|
|
import {
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Put,
|
|
|
|
|
Query,
|
|
|
|
|
Request,
|
|
|
|
|
UseGuards,
|
|
|
|
|
} from '@nestjs/common';
|
2022-11-03 02:48:47 -06:00
|
|
|
import { AuthGuard } from '@nestjs/passport';
|
2022-10-31 12:16:34 -06:00
|
|
|
import {
|
|
|
|
|
ApiBearerAuth,
|
|
|
|
|
ApiBody,
|
|
|
|
|
ApiOperation,
|
|
|
|
|
ApiQuery,
|
|
|
|
|
ApiTags,
|
|
|
|
|
} from '@nestjs/swagger';
|
|
|
|
|
import { Serealize } from '../interceptors/serialize.interceptor';
|
2022-11-03 02:48:47 -06:00
|
|
|
import { PasscodeService } from './passcode.service';
|
2022-10-31 12:16:34 -06:00
|
|
|
import { ValidarUsuarioService } from '../validar-usuario/validar-usuario.service';
|
2022-11-03 02:48:47 -06:00
|
|
|
import { Modulo } from '../modulo/entity/modulo.entity';
|
|
|
|
|
import { Operador } from '../operador/entity/operador.entity';
|
2022-10-31 12:16:34 -06:00
|
|
|
import { DevolucionDto } from './dto/input/devolucion.dto';
|
|
|
|
|
import { NotificacionDto } from './dto/input/notificacion.dto';
|
|
|
|
|
import { PrestamoDto } from './dto/input/prestamo.dto';
|
2022-11-03 02:48:47 -06:00
|
|
|
import { CodeOutputDto } from './dto/output/code.dto';
|
2022-10-31 12:16:34 -06:00
|
|
|
import { PasscodeOutputDto } from './dto/output/passcode.dto';
|
|
|
|
|
|
|
|
|
|
@Controller('passcode')
|
|
|
|
|
@ApiTags('passcode')
|
|
|
|
|
export class PasscodeController {
|
|
|
|
|
constructor(
|
|
|
|
|
private passcodeService: PasscodeService,
|
|
|
|
|
private validarUsuarioService: ValidarUsuarioService,
|
|
|
|
|
) {}
|
|
|
|
|
|
2023-01-04 16:55:36 -06:00
|
|
|
@Serealize(CodeOutputDto)
|
|
|
|
|
@Put('devolucion')
|
2022-10-31 12:16:34 -06:00
|
|
|
@UseGuards(AuthGuard('jwt'))
|
2023-01-04 16:55:36 -06:00
|
|
|
@ApiOperation({ description: 'Regresar equipo de cómputo al locker.' })
|
2022-10-31 12:16:34 -06:00
|
|
|
@ApiBearerAuth('jwt')
|
2023-01-04 16:55:36 -06:00
|
|
|
@ApiBody({
|
|
|
|
|
description: 'Variables que necesita el endpoint.',
|
|
|
|
|
examples: { ejemplo: { value: { passcode: '123456789012' } } },
|
2022-10-31 12:16:34 -06:00
|
|
|
})
|
2023-01-04 16:55:36 -06:00
|
|
|
devolucion(@Request() req, @Body() body: DevolucionDto) {
|
2022-10-31 12:16:34 -06:00
|
|
|
const operador: Operador = req.user.operador;
|
2023-01-04 16:55:36 -06:00
|
|
|
const modulo: Modulo = req.user.modulo;
|
2022-10-31 12:16:34 -06:00
|
|
|
|
2022-11-03 02:48:47 -06:00
|
|
|
this.validarUsuarioService.validarSoloOperador(operador);
|
2023-01-04 16:55:36 -06:00
|
|
|
return this.passcodeService.devolverEquipo(operador, modulo, body.passcode);
|
2022-10-31 12:16:34 -06:00
|
|
|
}
|
|
|
|
|
|
2022-11-03 02:48:47 -06:00
|
|
|
@Serealize(CodeOutputDto)
|
2022-10-31 12:16:34 -06:00
|
|
|
@Put('notificacion')
|
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
2023-01-04 16:55:36 -06:00
|
|
|
@ApiOperation({ description: 'Entregar equipo de computo de un lokcer.' })
|
2022-10-31 12:16:34 -06:00
|
|
|
@ApiBearerAuth('jwt')
|
|
|
|
|
@ApiBody({
|
2023-01-04 16:55:36 -06:00
|
|
|
description: 'Variables que necesita el endpoint.',
|
|
|
|
|
examples: { ejemplo: { value: { passcode: "123456789012", estatus: 1 } } },
|
2022-10-31 12:16:34 -06:00
|
|
|
})
|
|
|
|
|
autoprestamo(@Request() req, @Body() body: NotificacionDto) {
|
|
|
|
|
const operador: Operador = req.user.operador;
|
2022-11-03 02:48:47 -06:00
|
|
|
const modulo: Modulo = req.user.modulo;
|
2022-10-31 12:16:34 -06:00
|
|
|
|
2022-11-03 02:48:47 -06:00
|
|
|
this.validarUsuarioService.validarSoloOperador(operador);
|
2022-10-31 12:16:34 -06:00
|
|
|
return this.passcodeService.entregarEquipo(
|
2022-11-03 02:48:47 -06:00
|
|
|
operador,
|
|
|
|
|
modulo,
|
2022-10-31 12:16:34 -06:00
|
|
|
body.passcode,
|
|
|
|
|
body.estatus,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 16:55:36 -06:00
|
|
|
@Serealize(PasscodeOutputDto)
|
|
|
|
|
@Get('prestamo')
|
2022-10-31 12:16:34 -06:00
|
|
|
@UseGuards(AuthGuard('jwt'))
|
2023-01-04 16:55:36 -06:00
|
|
|
@ApiOperation({
|
|
|
|
|
description: 'Verificar la existencia y validez del passcode.',
|
|
|
|
|
})
|
2022-10-31 12:16:34 -06:00
|
|
|
@ApiBearerAuth('jwt')
|
2023-01-04 16:55:36 -06:00
|
|
|
@ApiQuery({
|
|
|
|
|
description: 'Id del lokcer. Un locker hace referencia a un carrito.',
|
|
|
|
|
name: 'id_locker',
|
|
|
|
|
type: 'string',
|
2022-10-31 12:16:34 -06:00
|
|
|
})
|
2023-01-04 16:55:36 -06:00
|
|
|
@ApiQuery({
|
|
|
|
|
description: 'Passcode del préstamo',
|
|
|
|
|
name: 'passcode',
|
|
|
|
|
type: 'string',
|
|
|
|
|
})
|
|
|
|
|
prestamo(@Request() req, @Query() query: PrestamoDto) {
|
2022-10-31 12:16:34 -06:00
|
|
|
const operador: Operador = req.user.operador;
|
|
|
|
|
|
2022-11-03 02:48:47 -06:00
|
|
|
this.validarUsuarioService.validarSoloOperador(operador);
|
2023-01-04 16:55:36 -06:00
|
|
|
return this.passcodeService.findByPasscode(
|
|
|
|
|
query.passcode,
|
|
|
|
|
false,
|
|
|
|
|
query.id_locker,
|
|
|
|
|
);
|
2022-10-31 12:16:34 -06:00
|
|
|
}
|
|
|
|
|
}
|