-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
169 additions
and
197 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
exports.update = (req, res, next) -> | ||
matchid = req.params.id | ||
teamid = req.param 'teamid', '' | ||
playerid = req.param 'playerid', '' | ||
result = req.param 'result', '' | ||
callback = (err) -> | ||
res.send | ||
success: false | ||
error: err | ||
|
||
if not matchid or not teamid or not playerid or not result | ||
res.send | ||
success: false | ||
error: 'Ids empty' | ||
else if result isnt 'win' and result isnt 'lose' | ||
res.send | ||
success: false | ||
error: 'Invalid result' | ||
else | ||
matchsvc = require '../services/match' | ||
utils = require '../services/utils' | ||
|
||
utils.execute( matchsvc.addVote, matchid, playerid, teamid, result ) | ||
.then (err, args..., cb = ->) -> | ||
return callback(err) if err | ||
|
||
matchsvc.getById matchid, cb | ||
.then (err, @am, cb = -> ) => | ||
return callback(err) if err | ||
return callback('match not found') if not @am? | ||
|
||
@totalplayers = @am?.teams?.map( (team) -> team?.members?.length ? 0 ).reduce( (prev, curr) -> | ||
prev + curr | ||
, 0 ) | ||
@totalvotes = @am?.votes?.length ? 0 | ||
@totalDecisions = matchsvc.countDecisions @am | ||
if @totalvotes >= @totalplayers or @totalDecisions > @totalplayers / 2 | ||
matchsvc.finalize @am, cb | ||
res.send | ||
success: true | ||
.then (err) => | ||
console.log err | ||
|
||
|
||
|
||
|
||
|
||
|
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.