inicio passcode
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Put,
|
||||
Query,
|
||||
Request,
|
||||
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 { ValidarUsuarioService } from '../validar-usuario/validar-usuario.service';
|
||||
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')
|
||||
@ApiTags('passcode')
|
||||
export class PasscodeController {
|
||||
constructor(
|
||||
private passcodeService: PasscodeService,
|
||||
private validarUsuarioService: ValidarUsuarioService,
|
||||
) {}
|
||||
|
||||
@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;
|
||||
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
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;
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
|
||||
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;
|
||||
|
||||
this.validarUsuarioService.validarAdminOperador(operador);
|
||||
return this.passcodeService.devolverEquipo(body.passcode, operador);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user