Created
August 27, 2014 15:31
-
-
Save joncodo/2898b17d3374ed1e0ceb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| '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