git ssb

0+

Piet / ssb-loomio



Tree: 9bf2bbbd3ecdc8c850b63aad19ada17d6bf593c7

Files: 9bf2bbbd3ecdc8c850b63aad19ada17d6bf593c7 / position / async / buildChooseOne.js

949 bytesRaw
1const getContent = require('ssb-msg-content')
2const { isPoll, isPosition } = require('ssb-poll-schema')
3const buildPosition = require('./buildPosition')
4const { CHOOSE_ONE, ERROR_POSITION_TYPE } = require('../../types')
5
6module.exports = function (server) {
7 const Position = buildPosition(server)
8
9 return function ChooseOne ({ poll, choice, reason, mentions }, cb) {
10 if (!isPoll(poll)) return cb(new Error('ChooseOne position factory requires a valid poll'))
11 if (choice >= getContent(poll).details.choices.length) return cb(new Error({type: ERROR_POSITION_TYPE, message: 'choice outside valid choices range'}))
12
13 const opts = {
14 poll,
15 details: {
16 type: CHOOSE_ONE,
17 choice
18 },
19 reason,
20 mentions
21 }
22
23 Position(opts, (err, position) => {
24 if (err) return cb(err)
25 if (!isPosition.chooseOne(position)) return cb(isPosition.chooseOne.errors)
26
27 cb(null, position)
28 })
29 }
30}
31

Built with git-ssb-web