git ssb

0+

Piet / ssb-loomio



Tree: 6cee7ba74d78d7a794627b917b1eef6f217416ff

Files: 6cee7ba74d78d7a794627b917b1eef6f217416ff / position / sync / chooseOneResults.js

737 bytesRaw
1var isArray = require('isarray')
2var isPosition = require('../../isPosition')
3var Position = require('../../position/sync/position')
4
5//Expects a po
6
7module.exports = function ({positions, poll}) { //postions must be of the correct type ie checked by the caller.
8 return positions.reduce(function (results, position) {
9 var { positionDetails: {choice} } = Position(position)
10
11 if (choice >= poll.pollDetails.choices.length || position.value.timestamp > poll.closesAt) {
12 results.errors.invalidPositions.push(position)
13 return results
14 }
15
16 if (!isArray(results[choice])) {
17 results[choice] = []
18 }
19 results[choice].push(position.value.author)
20
21 return results
22 }, {errors: {invalidPositions: []}})
23}
24

Built with git-ssb-web