git ssb

0+

Piet / ssb-loomio



Tree: 3c9734dbc87863e2373fcdfa511441b061e7a813

Files: 3c9734dbc87863e2373fcdfa511441b061e7a813 / position / schema / details / chooseOne.js

755 bytesRaw
1const Validate = require('is-my-json-valid')
2
3const { chooseOnePositionType } = require('../../../types')
4const typeStringPattern = `^${chooseOnePositionType}$`
5const typeStringRegex = new RegExp(typeStringPattern)
6
7function isValidTypeString (string) {
8 return typeStringRegex.test(string)
9}
10
11function create ({choice, reason}) {
12 return {
13 choice,
14 type: chooseOnePositionType,
15 reason
16 }
17}
18
19var 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
34const validate = Validate(schema, { verbose: true })
35
36module.exports = {
37 isValidTypeString,
38 schema,
39 validate,
40 create
41}
42

Built with git-ssb-web