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,12 +40,24 @@ const UpdateUserService = async ({
"Check-email",
"An user with this email already exists.",
async value => {
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'] });
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
}
),
});