Files
pcpuma_unam_api/src/auth/auth.controller.ts
T

66 lines
2.2 KiB
TypeScript
Raw Normal View History

import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
2022-05-30 15:22:31 -05:00
import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
2022-06-14 00:47:47 -05:00
import { Serealize } from '../interceptors/serialize.interceptor';
import { TurnstileGuard } from '../guards/turnstile.guard';
2022-04-21 20:33:05 -05:00
import { AuthService } from './auth.service';
2022-06-14 00:47:47 -05:00
import { LoginAdminDto } from './dto/input/login-admin.dto';
import { LoginOperadorDto } from './dto/input/login-operador.dto';
import { LoginUsuarioDto } from './dto/input/login-usuario.dto';
2022-08-11 16:38:56 -05:00
import { AuthTokenOutputDto } from './dto/output/token.dto';
2022-04-21 16:31:26 -05:00
@Controller('auth')
2022-04-30 21:18:19 -05:00
@ApiTags('auth')
2022-04-21 20:33:05 -05:00
export class AuthController {
constructor(private authService: AuthService) {}
2022-08-11 16:38:56 -05:00
@Serealize(AuthTokenOutputDto)
@UseGuards(TurnstileGuard)
2022-05-02 12:45:12 -05:00
@Post('login-admin')
2022-12-19 07:09:53 -06:00
@ApiOperation({ description: 'Login del admin.' })
2022-05-30 15:22:31 -05:00
@ApiBody({
2022-12-19 07:09:53 -06:00
description: 'Variables que necesita el endpoint.',
2022-12-19 11:00:27 -06:00
examples: { ejemplo: { value: { operador: '', password: '' } } },
2022-05-30 15:22:31 -05:00
})
2022-06-14 00:47:47 -05:00
loginAdmin(@Body() body: LoginAdminDto) {
2022-05-02 12:45:12 -05:00
return this.authService.loginAdmin(body.operador, body.password);
}
2022-08-11 16:38:56 -05:00
@Serealize(AuthTokenOutputDto)
@UseGuards(TurnstileGuard)
2022-05-02 12:45:12 -05:00
@Post('login-operador')
2022-12-19 07:09:53 -06:00
@ApiOperation({ description: 'Login del operador.' })
2022-05-30 15:22:31 -05:00
@ApiBody({
2022-12-19 07:09:53 -06:00
description: 'Variables que necesita el endpoint.',
2022-05-30 15:22:31 -05:00
examples: {
2022-12-19 07:09:53 -06:00
ejemplo: { value: { id_modulo: 1, operador: '', password: '' } },
2022-05-30 15:22:31 -05:00
},
})
2022-06-14 00:47:47 -05:00
loginOperador(@Body() body: LoginOperadorDto) {
2022-04-21 21:52:40 -05:00
return this.authService.loginOperador(
2022-05-02 12:45:12 -05:00
body.id_modulo,
2022-04-21 21:52:40 -05:00
body.operador,
body.password,
);
2022-04-21 20:33:05 -05:00
}
2022-08-11 16:38:56 -05:00
@Serealize(AuthTokenOutputDto)
@UseGuards(TurnstileGuard)
2022-05-02 12:45:12 -05:00
@Post('login-usuario')
2022-12-19 07:09:53 -06:00
@ApiOperation({ description: 'Login del usuario.' })
2022-05-30 15:22:31 -05:00
@ApiBody({
2022-12-19 07:09:53 -06:00
description: 'Variables que necesita el endpoint.',
2022-07-24 22:35:00 -05:00
examples: { ejemplo: { value: { password: '', usuario: '' } } },
2022-05-30 15:22:31 -05:00
})
2022-06-14 00:47:47 -05:00
loginUsuario(@Body() body: LoginUsuarioDto) {
2022-04-21 20:33:05 -05:00
return this.authService.loginUsuario(body.usuario, body.password);
}
@Get('validar-token')
@UseGuards(AuthGuard('jwt'))
2022-12-20 07:18:37 -06:00
@ApiOperation({ description: 'Validamos que el un token sea válido.' })
validarToken() {
2022-10-15 23:51:56 -05:00
return { valido: true };
}
2022-04-21 20:33:05 -05:00
}