UNPKG

reservease.consumer

Version:

This package allows you to create an amqplib consumer and producer.

24 lines (23 loc) 820 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JoiValidation = void 0; const InternalApiResponse_1 = require("./InternalApiResponse"); class JoiValidation { constructor(schema) { this.Schema = schema; } async Validate(data) { try { const value = await this.Schema.validateAsync(data); return new InternalApiResponse_1.InternalApiResponse(true, value); } catch (err) { const errorData = null; return new InternalApiResponse_1.InternalApiResponse(false, errorData, this.FormatJoiError(err)); } } FormatJoiError(error) { return `Validation error: ${error.details.map((x) => x.message).join(', ')}`; } } exports.JoiValidation = JoiValidation;