-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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}); |
There was a problem hiding this comment.
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});
}catch(e){ | ||
console.log(e); | ||
} |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
await supertest(app).post("/sign-up").send(body); | ||
const response = await supertest(app).post("/sign-in").send({ email: body.email, password: body.password }); |
There was a problem hiding this comment.
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.
No description provided.