backend-validation-express
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -9,3 +9,3 @@ import { NextFunction, Request, Response } from "express"; | ||
} | ||
declare const Validator: (validationSchema: IValidationSchema) => (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined; | ||
export default Validator; | ||
declare const validator: (validationSchema: IValidationSchema) => (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined; | ||
export default { validator, Joi }; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Validator = (validationSchema) => { | ||
exports.Joi = exports.validator = void 0; | ||
const joi_1 = __importDefault(require("joi")); | ||
exports.Joi = joi_1.default; | ||
// validation middleware | ||
const validator = (validationSchema) => { | ||
return (req, res, next) => { | ||
var _a; | ||
try { | ||
let errorMessages = {}; | ||
const errorMessages = {}; | ||
let errorExist = false; | ||
@@ -33,3 +40,3 @@ (_a = Object.keys(validationSchema)) === null || _a === void 0 ? void 0 : _a.map((key) => { | ||
wrap: { | ||
label: "", | ||
label: '', | ||
}, | ||
@@ -40,3 +47,3 @@ }, | ||
errorExist = true; | ||
let messages = {}; | ||
const messages = {}; | ||
(_a = error.details) === null || _a === void 0 ? void 0 : _a.map((err) => { | ||
@@ -51,3 +58,3 @@ messages[err.path[0]] = err.message; | ||
if (errorExist) { | ||
return res.status(422).send({ success: false, errors: errorMessages, message: "Validation Error!" }); | ||
return res.status(422).send({ success: false, errors: errorMessages, message: 'Validation Error!' }); | ||
} | ||
@@ -61,2 +68,2 @@ next(); | ||
}; | ||
exports.default = Validator; | ||
exports.validator = validator; |
{ | ||
"name": "backend-validation-express", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Request data validation middleware using Joi for express in backend", | ||
@@ -10,3 +10,3 @@ "main": "lib/index.js", | ||
"format": "prettier --write \"src/**/*.ts\" ", | ||
"lint": "tslint -p tsconfig.json", | ||
"lint": "tsc", | ||
"prepare": "npm run build", | ||
@@ -13,0 +13,0 @@ "prepublishOnly": "npm run lint", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4506
75