Skip to content

Commit

Permalink
(#137) altera nomes e legibilidade
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriqueAmorim20 committed Oct 20, 2023
1 parent 628f11f commit 59b1af8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 4 additions & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ DB_USERNAME=postgres
DB_PASS=postgres
DB_DATABASE=gerocuidado-usuario-db
DB_PORT=5001
#SALTROUND
SALTROUND=10

#BCRYPT
HASH_SALT=10

5 changes: 3 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ DB_USERNAME=postgres
DB_PASS=postgres
DB_DATABASE=gerocuidado-usuario-db-test
DB_PORT=5001
#SALTROUND
SALTROUND=10

#BCRYPT
HASH_SALT=10
19 changes: 9 additions & 10 deletions src/usuario/usuario.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,20 @@ export class UsuarioService {

async create(body: CreateUsuarioDto): Promise<Usuario> {
const usuario = new Usuario(body);
await this.verificaEmailNoBanco(usuario.email);
usuario.senha = await this.criptografaSenha(usuario.senha);
await this.checkEmail(usuario.email);
usuario.senha = await this.hashPassword(usuario.senha);
return this._repository.save(usuario);
}

async criptografaSenha(senha: string): Promise<string> {
const saltRounds = this._configService.get('SALTROUND');
return bcrypt.hash(senha, Number(saltRounds));
async hashPassword(senha: string): Promise<string> {
const salt = this._configService.get('HASH_SALT');
return bcrypt.hash(senha, Number(salt));
}

async verificaEmailNoBanco(email: string) {
const emailCadastrado = await this._repository.findOne({
where: { email: email },
});
if (emailCadastrado) {
async checkEmail(email: string) {
const userFound = await this._repository.findOne({ where: { email } });

if (userFound) {
throw new BadRequestException('Este email já está cadastrado!');
}
}
Expand Down

0 comments on commit 59b1af8

Please sign in to comment.