Answers for "fastify validation"

0

fastify validation

import Joi from 'joi'
import { Schema } from '../interfaces/fastify.interface'

export const schemaValidator = (type: string, schemaObject: Record<string, any>): Schema => {
  const response = Joi.object().keys({ ...schemaObject })

  const payloadType: Record<string, any> = {}
  payloadType[type] = response

  const validation: Schema = {
    schema: { ...payloadType },
    validatorCompiler: () => (data) => response.validate(data)
  }

  return validation
}
Posted by: Guest on September-08-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language