is not empty
This commit is contained in:
@@ -65,7 +65,7 @@ export class AuthController {
|
||||
})
|
||||
@ApiBody({
|
||||
description: 'Todas las variables son obligatorias.',
|
||||
examples: { ejemplo: { value: { usuario: '', password: '' } } },
|
||||
examples: { ejemplo: { value: { password: '', usuario: '' } } },
|
||||
})
|
||||
loginUsuario(@Body() body: LoginUsuarioDto) {
|
||||
return this.authService.loginUsuario(body.usuario, body.password);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { AuthController } from './auth.controller';
|
||||
@@ -15,12 +15,10 @@ import { UsuarioModule } from '../usuario/usuario.module';
|
||||
BcryptModule,
|
||||
JwtModule.registerAsync({
|
||||
inject: [ConfigService],
|
||||
useFactory: (configService: ConfigService) => {
|
||||
return {
|
||||
secret: configService.get<string>('AUTH_SECRETKEY'),
|
||||
signOptions: { expiresIn: '2h' },
|
||||
};
|
||||
},
|
||||
useFactory: (configService: ConfigService) => ({
|
||||
secret: configService.get<string>('AUTH_SECRETKEY'),
|
||||
signOptions: { expiresIn: '2h' },
|
||||
}),
|
||||
}),
|
||||
ModuloModule,
|
||||
OperadorModule,
|
||||
|
||||
@@ -44,6 +44,13 @@ export class AuthService {
|
||||
.findByOperador(modulo.institucion, operador, false)
|
||||
.then((operador) => {
|
||||
this.validarLogin(operador, password);
|
||||
if (
|
||||
operador.institucion.id_institucion !==
|
||||
modulo.institucion.id_institucion
|
||||
)
|
||||
throw new ConflictException(
|
||||
'Este módulo no pertenece a tu institución, selecciona uno válido.',
|
||||
);
|
||||
|
||||
const payload: JwtPayload = {
|
||||
id_modulo: modulo.id_modulo,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { IsString } from 'class-validator';
|
||||
import { IsNotEmpty, IsString, MaxLength } from 'class-validator';
|
||||
|
||||
export class LoginAdminDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(40)
|
||||
operador: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
password: string;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { IsInt, IsString } from 'class-validator';
|
||||
import { IsInt, IsNotEmpty, IsString, MaxLength } from 'class-validator';
|
||||
|
||||
export class LoginOperadorDto {
|
||||
@IsInt()
|
||||
id_modulo: number;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(40)
|
||||
operador: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
password: string;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { IsString } from 'class-validator';
|
||||
import { IsNotEmpty, IsString, MaxLength } from 'class-validator';
|
||||
|
||||
export class LoginUsuarioDto {
|
||||
@IsString()
|
||||
password: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(10)
|
||||
usuario: string;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export class JwtPayload {
|
||||
id_tipo_usuario: number;
|
||||
|
||||
id_modulo?: number;
|
||||
|
||||
id_operador?: number;
|
||||
|
||||
id_tipo_usuario: number;
|
||||
|
||||
id_usuario?: number;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@ import { Expose, Type } from 'class-transformer';
|
||||
import { OperadorOutputDto } from '../../../operador/dto/output/operador.dto';
|
||||
|
||||
export class AuthOperadorOutputDto {
|
||||
@Expose()
|
||||
token;
|
||||
|
||||
@Expose()
|
||||
@Type(() => OperadorOutputDto)
|
||||
operador;
|
||||
|
||||
@Expose()
|
||||
token;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user