Skip to content

Instantly share code, notes, and snippets.

@joncodo
Created August 27, 2014 15:31
Show Gist options
  • Select an option

  • Save joncodo/2898b17d3374ed1e0ceb to your computer and use it in GitHub Desktop.

Select an option

Save joncodo/2898b17d3374ed1e0ceb to your computer and use it in GitHub Desktop.
'submitResult': function () {
var playDetails = req.params.all().play;
var userDetails = req.params.all().user;
var user, play;
Play.find({id: playDetails.id})
.then(function (playResult) {
play = playResult;
return UserService.createOrFindByParams(userDetails, play);
})
.then(function (userResult) {
user = userResult;
return UserService.alreadyPlayed(user);
})
.then(function (alreadyPlayed) {
if(alreadyPlayed){
return res.send({message: 'You have already played'});
}
else if(play == 'win'){
PlayService.claimPrize(user).then(function () {
return res.json({message: 'Your prize has been claimed'});
});
}
else{
return res.json({message: 'You lost sucker!'});
}
})
.catch(function (error) {
return res.send(500, error);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment