correção da atualização do email

pull/21/head
adriano 2023-04-12 14:45:50 -03:00
parent 57b32a99e7
commit a2471fd08d
1 changed files with 20 additions and 8 deletions

View File

@ -40,11 +40,23 @@ const UpdateUserService = async ({
"Check-email", "Check-email",
"An user with this email already exists.", "An user with this email already exists.",
async value => { async value => {
if (!value) return false; if (!value) return false;
const emailExists = await User.findOne({
where: { email: value } const emailExists = await User.findOne({ where: { email: value }, raw: true, attributes: ['email', 'id'] });
});
return !emailExists; console.log('emailExists.email: ', emailExists?.email)
console.log('User.email: ', user.email)
console.log('emailExists.id: ', emailExists?.id)
console.log('User.id: ', user.id)
if (emailExists && user.id != emailExists?.id) {
console.error('The email already exists in another user profile!')
return !emailExists;
}
return true
} }
), ),