lat lon validation
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const { body, validationResult } = require("express-validator");
|
||||
const { body, query, validationResult } = require("express-validator");
|
||||
const DOMPurify = require("dompurify");
|
||||
const { JSDOM } = require("jsdom");
|
||||
|
||||
@@ -316,6 +316,35 @@ const validateFeedback = [
|
||||
handleValidationErrors,
|
||||
];
|
||||
|
||||
// Coordinate validation for query parameters (e.g., location search)
|
||||
const validateCoordinatesQuery = [
|
||||
query("lat")
|
||||
.optional()
|
||||
.isFloat({ min: -90, max: 90 })
|
||||
.withMessage("Latitude must be between -90 and 90"),
|
||||
query("lng")
|
||||
.optional()
|
||||
.isFloat({ min: -180, max: 180 })
|
||||
.withMessage("Longitude must be between -180 and 180"),
|
||||
query("radius")
|
||||
.optional()
|
||||
.isFloat({ min: 0.1, max: 100 })
|
||||
.withMessage("Radius must be between 0.1 and 100 miles"),
|
||||
handleValidationErrors,
|
||||
];
|
||||
|
||||
// Coordinate validation for body parameters (e.g., user addresses, forum posts)
|
||||
const validateCoordinatesBody = [
|
||||
body("latitude")
|
||||
.optional()
|
||||
.isFloat({ min: -90, max: 90 })
|
||||
.withMessage("Latitude must be between -90 and 90"),
|
||||
body("longitude")
|
||||
.optional()
|
||||
.isFloat({ min: -180, max: 180 })
|
||||
.withMessage("Longitude must be between -180 and 180"),
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
sanitizeInput,
|
||||
handleValidationErrors,
|
||||
@@ -328,4 +357,6 @@ module.exports = {
|
||||
validateResetPassword,
|
||||
validateVerifyResetToken,
|
||||
validateFeedback,
|
||||
validateCoordinatesQuery,
|
||||
validateCoordinatesBody,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user