Files: 870e2cb73a3e01c6b5810eaa4f9e264b5b974d03 / position / sync / chooseOneResults.js
674 bytesRaw
1 | var isArray = require('isarray') |
2 | var isPosition = require('../../isPosition') |
3 | var Position = require('../../position/sync/position') |
4 | |
5 | module.exports = function ({positions, poll}) { //postions must be of the correct type ie checked by the caller. |
6 | return positions.reduce(function (results, position) { |
7 | var { choice } = Position(position).positionDetails |
8 | |
9 | if (choice >= poll.pollDetails.choices.length) { |
10 | results.errors.invalidPositions.push(position) |
11 | return results |
12 | } |
13 | |
14 | if (!isArray(results[choice])) { |
15 | results[choice] = [] |
16 | } |
17 | results[choice].push(position.value.author) |
18 | |
19 | return results |
20 | }, {errors: {invalidPositions: []}}) |
21 | } |
22 |
Built with git-ssb-web