JSFiddle - React, Tailwind, and code Playground
JavaScript
function validateInput(data, additionalValid) {
let { errors } = additionalValid(data);
const { login, email } = data;
return Promise.all([
User.findOne({ login }, (err, user) => {
if (err) return err;
if (user) {
if (user.login === login) {
console.log(user.login);
errors.login = 'There is user with such username';
}
}
}),
User.findOne({ email }, (err, user) => {
if (err) return err;
if (user) {
if (user.email === email) {
console.log(user.email);
errors.email = 'There is user with such email';
}
}
})
]).then(() => {
return {
errors,
isValid: Object.keys(errors).length === 0
};
});
}