Errores arreglados
This commit is contained in:
+24
-13
@@ -1,9 +1,12 @@
|
||||
import { BadRequestException, Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable, UnauthorizedException, InternalServerErrorException } from '@nestjs/common';
|
||||
import { UsuariosService } from 'src/usuarios/usuarios.service';
|
||||
import * as argon2 from 'argon2';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { CreateUsuarioDto } from 'src/usuarios/dto/create-usuario.dto';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Usuario } from 'src/usuarios/entities/usuario.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
@@ -11,22 +14,30 @@ export class AuthService {
|
||||
private readonly usuarioService:UsuariosService,
|
||||
private readonly jwtService:JwtService
|
||||
){}
|
||||
//Pendiente
|
||||
//Pendiente tipoUsuario
|
||||
async registro({nombre, contraseña,tipoUsuario}: CreateUsuarioDto){
|
||||
const usuario= await this.usuarioService.findOneByName(nombre)
|
||||
|
||||
const usuario = await this.usuarioService.findOneByName(nombre);
|
||||
if(usuario){
|
||||
throw new BadRequestException("Nombre de usuario ya existente");
|
||||
}
|
||||
const hashedContraseña= await argon2.hash(contraseña) ;
|
||||
|
||||
await this.usuarioService.create({
|
||||
nombre,
|
||||
contraseña:hashedContraseña,
|
||||
tipoUsuario,
|
||||
});
|
||||
|
||||
return{
|
||||
message:"Usuario registrado exitosamente " };
|
||||
|
||||
try{
|
||||
const hashedContraseña = await argon2.hash(contraseña);
|
||||
|
||||
await this.usuarioService.create({
|
||||
nombre,
|
||||
contraseña: hashedContraseña,
|
||||
tipoUsuario,
|
||||
});
|
||||
|
||||
return {
|
||||
message: "Usuario registrado exitosamente"
|
||||
};
|
||||
}catch(error){
|
||||
|
||||
throw new InternalServerErrorException('Error al crear el usuario');
|
||||
}
|
||||
}
|
||||
|
||||
async login({nombre, contraseña}:LoginDto){
|
||||
|
||||
Reference in New Issue
Block a user