UNPKG

checkfront

Version:

Node module for the Checkfront API http://api.checkfront.com/

24 lines (19 loc) 504 B
const Ajv = require('ajv'); const getBooking = require('./getBooking'); function getAjvValidator(schema) { const ajv = new Ajv(); const validator = ajv.compile(schema); return { ajv, validator }; } const ajvValidators = { list: getAjvValidator(getBooking), }; function validate(schema, data) { const { ajv, validator } = ajvValidators[schema]; const valid = validator(data); if (valid) { return; } throw new Error(ajv.errorsText(validator.errors)); } module.exports = validate;