Commit 17445d27af23c12c79234b9d06909eb97e55ad50
Merge pull request #8 from ssbc/isChooseOnePoll
add poll.sync.isChooseOnePollPiet Geursen authored on 3/6/2018, 2:05:23 AM
GitHub committed on 3/6/2018, 2:05:23 AM
Parent: a3426ae4bc96b37cfb2795e1acb2b31d2b3da6ea
Parent: e91df8e00ca174250db3f719cc4bbf9a3b54b07c
Files changed
package-lock.json | changed |
package.json | changed |
poll/schema/chooseOnePoll.js | added |
poll/sync/isPoll.js | changed |
poll/sync/isChooseOnePoll.js | added |
package-lock.json | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | 1 | { |
2 | - "name": "ssb-loomio", | |
2 | + "name": "scuttle-poll", | |
3 | 3 | "version": "1.0.0", |
4 | 4 | "lockfileVersion": 1, |
5 | 5 | "requires": true, |
6 | 6 | "dependencies": { |
@@ -302,8 +302,18 @@ | ||
302 | 302 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz", |
303 | 303 | "integrity": "sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=", |
304 | 304 | "dev": true |
305 | 305 | }, |
306 | + "lodash.clonedeep": { | |
307 | + "version": "4.5.0", | |
308 | + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", | |
309 | + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" | |
310 | + }, | |
311 | + "lodash.merge": { | |
312 | + "version": "4.6.1", | |
313 | + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.1.tgz", | |
314 | + "integrity": "sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ==" | |
315 | + }, | |
306 | 316 | "minimatch": { |
307 | 317 | "version": "3.0.4", |
308 | 318 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", |
309 | 319 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", |
package.json | ||
---|---|---|
@@ -29,8 +29,9 @@ | ||
29 | 29 | }, |
30 | 30 | "dependencies": { |
31 | 31 | "is-my-json-valid": "^2.17.1", |
32 | 32 | "libnested": "^1.2.1", |
33 | + "lodash.clonedeep": "^4.5.0", | |
33 | 34 | "ssb-msg-schemas": "^6.3.0", |
34 | 35 | "ssb-ref": "^2.9.0" |
35 | 36 | } |
36 | 37 | } |
poll/schema/chooseOnePoll.js | ||
---|---|---|
@@ -1,0 +1,9 @@ | ||
1 | +const pollSchema = require('./poll') | |
2 | +const cloneDeep = require('lodash.clonedeep') | |
3 | + | |
4 | +const chooseOneSchema = cloneDeep(pollSchema) | |
5 | + | |
6 | +// collapse the details down to be ONLY chooseOne | |
7 | +chooseOneSchema.properties.pollDetails = { $ref: '#/definitions/pollDetails/chooseOne' } | |
8 | + | |
9 | +module.exports = chooseOneSchema |
poll/sync/isPoll.js | ||
---|---|---|
@@ -1,16 +1,16 @@ | ||
1 | -const validator = require('is-my-json-valid') | |
1 | +const Validator = require('is-my-json-valid') | |
2 | 2 | const schema = require('../schema/poll') |
3 | -const isPollContent = validator(schema, {verbose: true}) | |
3 | +const validator = Validator(schema, {verbose: true}) | |
4 | 4 | const getMsgContent = require('../../lib/getMsgContent') |
5 | 5 | |
6 | 6 | // server is not used here. Closure pattern is just for consistency of use with other functions. |
7 | 7 | module.exports = function (server) { |
8 | 8 | return function isPoll (obj) { |
9 | - const result = isPollContent(getMsgContent(obj)) | |
9 | + const result = validator(getMsgContent(obj)) | |
10 | 10 | |
11 | 11 | // exposes error messages provided by is-my-json-valid |
12 | - isPoll.errors = isPollContent.errors | |
12 | + isPoll.errors = validator.errors | |
13 | 13 | |
14 | 14 | return result |
15 | 15 | } |
16 | 16 | } |
poll/sync/isChooseOnePoll.js | ||
---|---|---|
@@ -1,0 +1,16 @@ | ||
1 | +const Validator = require('is-my-json-valid') | |
2 | +const schema = require('../schema/chooseOnePoll') | |
3 | +const validator = Validator(schema, {verbose: true}) | |
4 | +const getMsgContent = require('../../lib/getMsgContent') | |
5 | + | |
6 | +// server is not used here. Closure pattern is just for consistency of use with other functions. | |
7 | +module.exports = function (server) { | |
8 | + return function isChooseOnePoll (obj) { | |
9 | + const result = validator(getMsgContent(obj)) | |
10 | + | |
11 | + // exposes error messages provided by is-my-json-valid | |
12 | + isChooseOnePoll.errors = validator.errors | |
13 | + | |
14 | + return result | |
15 | + } | |
16 | +} |
Built with git-ssb-web