Last active
January 7, 2017 04:38
-
-
Save jimmycann/3323e3b99fe8d9ea980c799c8a78cd13 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signup: function (req, res) { | |
User.findOne({ | |
where: { | |
username: req.body.username | |
} | |
}).then(function (user){ | |
if (user) { | |
sails.log.silly(user); | |
return res.json(409, { 'error': 'Sorry, that username is already taken' }); | |
} | |
}).then(() => UserService.create(req.body)) | |
}).catch(function (error) { | |
if (process.env.NODE_ENV == 'development'){ | |
return res.json(500, { 'error': err }); | |
} else { | |
return res.json(500, { 'error': 'Error in user creation' }); | |
} | |
}) | |
} | |
} | |
// Inside the UserSevice | |
create: function(data) { | |
return new Promise((resolve, reject) => { | |
User.create({ | |
username: data.username, | |
password: data.password | |
}).then((result) => { | |
resolve(result) | |
}).catch((err) => { | |
reject(err) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment