- Added email availability checker in API

This commit is contained in:
Alexis
2020-12-19 18:15:39 +01:00
parent eba2669176
commit 20f946a945
2 changed files with 47 additions and 4 deletions

View File

@@ -38,7 +38,7 @@ router.get('/', async (req, res) => {
})
// GET ONE FORM UUID ------------------
// GET ONE FROM UUID ------------------
const getUserByUUID = (uuid) => {
return Users.getOneByUUID(uuid)
.catch(err => {
@@ -63,6 +63,31 @@ router.get('/:uuid/', async (req, res) => {
})
// CHECK IF MAIL IS AVAILABLE ------------------
const checkIfEmailAvailable = (mail) => {
return Users.checkIfEmailAvailable(mail)
.catch(err => {
console.log(err)
throw err
})
}
router.get('/available/:mail/', async (req, res) => {
checkIfEmailAvailable(req.params.mail)
.then(v => {
res.setHeader('Content-Type', 'application/json;charset=utf-8')
res.end(JSON.stringify(v))
})
.catch(err => {
res.status(err.code).send(JSON.stringify(
{
"error": err.message,
"code": err.code
})
)
})
})
// LOG A USER ------------------
const logUser = (mail, password) => {
return Users.logUser(mail, password)