Created
January 11, 2013 23:09
-
-
Save crtr0/4514741 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
| flushVotes = function() { | |
| var votesToSave = _und.values(votesCache); | |
| votesCache = {}; | |
| if (votesToSave.length > 0) { | |
| db.bulk({docs: votesToSave}, function(err, body) { | |
| if (err) { | |
| console.log("Failed to save votes, popping them back on the cache"); | |
| votesToSave.forEach(function(v) { | |
| votesCache[v._id] = v; | |
| }); | |
| } | |
| else { | |
| // loop through the response to detect votes that were rejected as duplicates | |
| for (var i in votesToSave) { | |
| if (body[i].error) { | |
| // send the person an SMS to alert them that you can only vote once | |
| console.log('Notifying of duplicate vote: ', votesToSave[i]) | |
| client.sendSms({To: votesToSave[i].phonenumber, From: votesToSave[i].event_phonenumber, Body: 'Sorry, you are only allowed to vote once.'}); | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment