UNPKG

@truepic/queryql

Version:

Easily add filtering, sorting, and pagination to your REST API through your old friend: the query string!

32 lines (23 loc) 620 B
const Joi = require('joi') const joiValidationErrorConverter = require('../services/joi_validation_error_converter') class ParserValidator { constructor(defineSchema, queryKey, query) { this.schema = defineSchema(Joi) this.queryKey = queryKey this.query = query } buildError(error) { return joiValidationErrorConverter(error, this.queryKey) } validate() { if (!this.schema) { return this.query } const { value, error } = this.schema.validate(this.query) if (error) { throw this.buildError(error) } return value } } module.exports = ParserValidator