git ssb

0+

Piet / ssb-loomio



Tree: 870e2cb73a3e01c6b5810eaa4f9e264b5b974d03

Files: 870e2cb73a3e01c6b5810eaa4f9e264b5b974d03 / position / sync / chooseOneResults.js

674 bytesRaw
1var isArray = require('isarray')
2var isPosition = require('../../isPosition')
3var Position = require('../../position/sync/position')
4
5module.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