git ssb

0+

Piet / ssb-loomio



Tree: b05294a4fda9b4144ba8446e80a727b175dfdcfe

Files: b05294a4fda9b4144ba8446e80a727b175dfdcfe / position / sync / chooseOneResults.js

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

Built with git-ssb-web