diff --git a/app/schemas.js b/app/schemas.js new file mode 100644 index 0000000..f5fcf71 --- /dev/null +++ b/app/schemas.js @@ -0,0 +1,11 @@ +const Ajv = require('ajv') +const ajv = new Ajv() + +const taskPlanSchema = require('../tasks/schemas/taskPlan') +const taskRecipeSchema = require('../tasks/schemas/taskRecipe') +ajv.addSchema([ + taskRecipeSchema, + taskPlanSchema +]) + +export default ajv diff --git a/tasks/services/plans.js b/tasks/services/plans.js index 0046051..cd2d3d4 100644 --- a/tasks/services/plans.js +++ b/tasks/services/plans.js @@ -1,11 +1,8 @@ const feathersKnex = require('feathers-knex') import { isEmpty, ifElse, is, assoc, prop, map, pipe, __ } from 'ramda' const { iff, validateSchema } = require('feathers-hooks-common') -const Ajv = require('ajv') const taskPlanSchema = require('../schemas/taskPlan') -const taskRecipeSchema = require('../schemas/taskRecipe') -const ajv = new Ajv({$data: true}) -ajv.addSchema([taskRecipeSchema, taskPlanSchema]) +import ajv from '../../app/schemas' import * as taskRecipes from '../../tasks/data/recipes' module.exports = function () { diff --git a/tasks/util/validateTaskPlan.test.js b/tasks/util/validateTaskPlan.test.js index 62fce82..3b515d0 100644 --- a/tasks/util/validateTaskPlan.test.js +++ b/tasks/util/validateTaskPlan.test.js @@ -1,13 +1,9 @@ import test from 'ava' import * as mock from '../data/mock' +import ajv from '../../app/schemas' -const Ajv = require('ajv') const { validateSchema } = require('feathers-hooks-common') const schema = require('../schemas/taskPlan') -const taskRecipeSchema = require('../schemas/taskRecipe') - -let ajv = new Ajv({ $data: true }) -ajv.addSchema([taskRecipeSchema, schema]) let hookBefore diff --git a/tasks/util/validateTaskRecipe.test.js b/tasks/util/validateTaskRecipe.test.js index 2991166..932aeb4 100644 --- a/tasks/util/validateTaskRecipe.test.js +++ b/tasks/util/validateTaskRecipe.test.js @@ -1,7 +1,7 @@ import test from 'ava' import * as mock from '../data/mock' +import ajv from '../../app/schemas' -const ajv = require('ajv') const { validateSchema } = require('feathers-hooks-common') const schema = require('../schemas/taskRecipe')