-1
In the back-end of the application in Ode, I want to do an e-mail check when some other user already has the same email registered. Already works well when using with the POST method, however, when doing an update with PUT, the current routine identifies the user’s own email to be changed as duplicate (because it is already registered in the database), did not want this and does not make sense, I would like in the update, not be considered the email of the user I am changing, but yes, check if there is any other user with equivalent email.
I tried the following code:
chekEmailDuplicate = (req, res) => {
User.findOne({//Tenta localizar algum usuário
where: {//onde
id: !req.body.id,
email: req.body.email
}
}).then(user => {
if (user) {
res.status(400).send("Fail -> Email is already in use!");
return;
}
}
As we can see in the code above, in:
id: !req.body.id
I tried something like considering the different id of the user in modification, but it DOES NOT work, the application accepts email duplicity in the same way! No POST is a wonder, but with PUT will not.
Someone who knows Node or already knows how to solve could help me? Thanks in advance!
Solved by myself in the answer below!
– João Paulo Silva