Using User Interface

This commit is contained in:
Belen Curcio
2016-11-17 11:18:17 -03:00
parent a8f28f64b7
commit da1539422b
2 changed files with 26 additions and 17 deletions
+17
View File
@@ -426,3 +426,20 @@ UserService.search = (value) => {
]
});
};
/**
* Finds users by email and returns the count. The result should be 1 or 0 (bool) indicating email availability
* @param {String} email to search by
* @return {Promise}
*/
UserService.availabilityCheck = (email) => {
return UserModel.count({
profiles: {
$elemMatch: {
id: email,
provider: 'local'
}
}
});
};
+9 -17
View File
@@ -69,25 +69,17 @@ router.post('/availability', (req, res, next) => {
const {email} = req.body;
if (email) {
return User.count({
profiles: {
$elemMatch: {
id: email,
provider: 'local'
return User.availabilityCheck(email)
.then(count => {
if (count) {
return res.json({status: 'unavailable'});
}
}
})
.then(count => {
if (count) {
return res.json({status: 'unavailable'});
}
return res.json({status: 'available'});
})
.catch(err => {
next(err);
});
return res.json({status: 'available'});
})
.catch(err => {
next(err);
});
}
return res.status(404).send('Wrong parameters');
});