Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparando review #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Preparando review #1

wants to merge 1 commit into from

Conversation

brunatb
Copy link

@brunatb brunatb commented Jun 28, 2021

No description provided.

Copy link
Author

@brunatb brunatb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oi Victor! Aqui tá o feedback do back do projeto MyWallet!
Seu código está consistente, organizado e você mandou muito bem extraindo funções para evitar repetição de código. Seria legal em próximos projetos, tentar melhorar a frequência dos commits.
Deixei aqui embaixo alguns pontos que observei :)

const result = await connection.query(`SELECT * FROM users WHERE email=$1`,[email]);
console.log(result);
if(password.length < 3) return res.status(400).send("A senha deve ter no mínimo 4 caractéres!");
if(!result.rows.length === 0 ) return res.status(409).send("Esse email já está sendo utilizado");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O javaScript lê sempre o código da esquerda para direita, no caso em que result.rows.length fosse igual a 1 teríamos a seguinte comparação: !1 é false, então false === 0 e isso é falso, logo o que está dentro do if não seria executado da maneira que queremos.

INSERT INTO sessions ("userId", token) VALUES ($1,$2)
`, [user.id, token]);

res.send({user:user,token:token});
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quando queremos dar o mesmo nome da variável a uma propriedade de um objeto podemos fazer simplemenste: res.send({user,token});

Comment on lines -71 to -73
}catch(e){
console.log(e);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seria interessante mandar um status caso algo dê errado dentro do try.

}
});

app.post("/user", async (req, res) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essa rota acabou não ficando muito semântica, seria legal colocar um nome que tenha a ver com a inserção de transações.

async function validateToken(authorization){
const token = authorization?.replace('Bearer ', '');

if(!token) return res.sendStatus(401);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não é possível mandar uma response nessa função pois a response não foi passada pra ela.

Comment on lines -54 to -55
await supertest(app).post("/sign-up").send(body);
const response = await supertest(app).post("/sign-in").send({ email: body.email, password: body.password });
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A ideia é que cada rota seja testada independente de outra. Então poderíamos inserir diretamente no banco um usuário com nome, email e senha criptografada com bcrypt e então testar a rota sign-in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant