From 31540d4d4b040e1165b700f3aba951d75f989bee Mon Sep 17 00:00:00 2001 From: Pau Date: Fri, 9 May 2025 02:12:49 +0200 Subject: [PATCH] fixed custom validator for json fields --- src/validators/expressValidator/customValidators.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/validators/expressValidator/customValidators.js b/src/validators/expressValidator/customValidators.js index b2f745c..6ccfeef 100644 --- a/src/validators/expressValidator/customValidators.js +++ b/src/validators/expressValidator/customValidators.js @@ -10,11 +10,16 @@ const longitudeRange = (field, { min = -180, max = 180 } = {}) => .isFloat({ min, max }) .withMessage(`|${field}| must be a number between ${min} and ${max}`) - const latitudeRange = (field, { min = -90, max = 90 } = {}) => +const latitudeRange = (field, { min = -90, max = 90 } = {}) => check(field) .isFloat({ min, max }) .withMessage(`|${field}| must be a number between ${min} and ${max}`) +const json = (field) => + check(field) + .isJSON() + .withMessage(`|${field}| must be a valid JSON string`); + export { integer, integerRange, @@ -22,5 +27,6 @@ export { varChar, bigInt, latitudeRange, - longitudeRange + longitudeRange, + json } \ No newline at end of file