Skip to content

Instantly share code, notes, and snippets.

@jimmycann
Last active January 7, 2017 04:38
Show Gist options
  • Save jimmycann/3323e3b99fe8d9ea980c799c8a78cd13 to your computer and use it in GitHub Desktop.
Save jimmycann/3323e3b99fe8d9ea980c799c8a78cd13 to your computer and use it in GitHub Desktop.
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