Commit c11e72244cf922e07314cd51643afc5722c6225a
Merge branch 'master' of github.com:ssbc/scuttle-poll into poll-refactor
mix irving committed on 3/1/2018, 12:54:16 AMParent: 3c2e645f7b5dccfbc0afd288ee28c0465837a6ec
Parent: 8818456f68cdf8d623639cc4bc69b81a61f90869
Files changed
schema/position.js | changed |
schema/positionTypes/chooseOne.js | deleted |
schema/positionDetails/chooseOne.js | added |
schema/position.js | ||
---|---|---|
@@ -4,9 +4,9 @@ | ||
4 | 4 … | // |
5 | 5 … | // well for a chooseOne: |
6 | 6 … | // { |
7 | 7 … | // pollId: msgId, |
8 | -// choice: 'apple', //what if this is a key? Or a key and index number? I wonder if this is an argument for making each choice a separate message? | |
8 … | +// choice: 0, // index of the choice | |
9 | 9 … | // reason: "I don't like doctorbs", |
10 | 10 … | // } |
11 | 11 … | // When do the various validations happen? |
12 | 12 … | // - when we're counting votes. We need to check it's a valid position for the type of poll |
schema/positionTypes/chooseOne.js | ||
---|---|---|
@@ -1,40 +1,0 @@ | ||
1 | -const Validate = require('is-my-json-valid') | |
2 | - | |
3 | -const typeString = 'chooseOne' | |
4 | -const typeStringPattern = `^${typeString}$` | |
5 | -const typeStringRegex = new RegExp(typeStringPattern) | |
6 | - | |
7 | -function isValidTypeString (string) { | |
8 | - return typeStringRegex.test(string) | |
9 | -} | |
10 | - | |
11 | -function create ({choice, reason}) { | |
12 | - return { | |
13 | - choice, | |
14 | - type: typeString, | |
15 | - reason | |
16 | - } | |
17 | -} | |
18 | - | |
19 | -var schema = { | |
20 | - type: 'object', | |
21 | - required: ['type', 'choice'], | |
22 | - properties: { | |
23 | - type: { | |
24 | - type: 'string', | |
25 | - pattern: typeStringPattern | |
26 | - }, | |
27 | - choice: { | |
28 | - type: 'string' | |
29 | - } | |
30 | - } | |
31 | -} | |
32 | - | |
33 | -const validate = Validate(schema, { verbose: true }) | |
34 | - | |
35 | -module.exports = { | |
36 | - isValidTypeString, | |
37 | - schema, | |
38 | - validate, | |
39 | - create | |
40 | -} |
schema/positionDetails/chooseOne.js | |||
---|---|---|---|
@@ -1,0 +1,41 @@ | |||
1 … | +const Validate = require('is-my-json-valid') | ||
2 … | + | ||
3 … | +const typeString = 'chooseOne' | ||
4 … | +const typeStringPattern = `^${typeString}$` | ||
5 … | +const typeStringRegex = new RegExp(typeStringPattern) | ||
6 … | + | ||
7 … | +function isValidTypeString (string) { | ||
8 … | + return typeStringRegex.test(string) | ||
9 … | +} | ||
10 … | + | ||
11 … | +function create ({choice, reason}) { | ||
12 … | + return { | ||
13 … | + choice, | ||
14 … | + type: typeString, | ||
15 … | + reason | ||
16 … | + } | ||
17 … | +} | ||
18 … | + | ||
19 … | +var schema = { | ||
20 … | + type: 'object', | ||
21 … | + required: ['type', 'choice'], | ||
22 … | + properties: { | ||
23 … | + type: { | ||
24 … | + type: 'string', | ||
25 … | + pattern: typeStringPattern | ||
26 … | + }, | ||
27 … | + choice: { | ||
28 … | + type: 'integer', | ||
29 … | + minimum: 0 | ||
30 … | + } | ||
31 … | + } | ||
32 … | +} | ||
33 … | + | ||
34 … | +const validate = Validate(schema, { verbose: true }) | ||
35 … | + | ||
36 … | +module.exports = { | ||
37 … | + isValidTypeString, | ||
38 … | + schema, | ||
39 … | + validate, | ||
40 … | + create | ||
41 … | +} |
Built with git-ssb-web