fixed issue regarding coordinate validation and logic for query

This commit is contained in:
Pau 2025-04-17 15:41:10 +02:00
parent dfa1c93450
commit d9f6e3a928
2 changed files with 21 additions and 6 deletions

View File

@ -15,7 +15,7 @@ import {
sendOkResponse,
sendResponseNoContent,
} from '../utils/responses.js'
import { integer, uuid, varChar } from '../validators/expressValidator/customValidators.js'
import { integer, latitudeRange, longitudeRange, uuid, varChar } from '../validators/expressValidator/customValidators.js'
import { integerRange } from '../validators/expressValidator/customValidators.js'
import {payloadExpressValidator} from '../validators/expressValidator/payloadExpressValidator.js'
import { authorizePermission, setToken, authenticateToken, refreshAuthenticate} from '../middlewares/auth.js'
@ -896,7 +896,8 @@ export default(config) => {
varChar('name').optional({ nullable: false, values: 'falsy' }),
varChar('address').optional({ nullable: true, values: 'falsy' }),
varChar('description').optional({ nullable: true, values: 'falsy' }),
uuid('fk_coordinate').optional({ nullable: false, values: 'falsy' }),
latitudeRange('latitude').optional({ nullable: false, values: 'falsy' }),
longitudeRange('longitude').optional({nullable: false, values: 'falsy'})
],
(req, res, next) => payloadExpressValidator(req, res, next, config),
(req, res, next) => getPlaceListController(req, res, next, config),
@ -931,7 +932,8 @@ export default(config) => {
varChar('name').optional({ nullable: false, values: 'falsy' }),
varChar('address').optional({ nullable: true, values: 'falsy' }),
varChar('description').optional({ nullable: true, values: 'falsy' }),
uuid('fk_coordinate').optional({ nullable: false, values: 'falsy' }),
latitudeRange('latitude').optional({ nullable: false, values: 'falsy' }),
longitudeRange('longitude').optional({nullable: false, values: 'falsy'})
],
(req, res, next) => payloadExpressValidator(req, res, next, config),
(req, res, next) => getPlaceByUuidController(req, res, next, config),
@ -964,7 +966,8 @@ export default(config) => {
varChar('name'),
varChar('address').optional({ nullable: true, values: 'falsy' }),
varChar('description').optional({ nullable: true, values: 'falsy' }),
uuid('fk_coordinate')
latitudeRange('latitude'),
longitudeRange('longitude')
],
(req, res, next) => payloadExpressValidator(req, res, next, config),
(req, res, next) => insertPlaceController(req, res, next, config),
@ -999,7 +1002,8 @@ export default(config) => {
varChar('name').optional({ nullable: false, values: 'falsy' }),
varChar('address').optional({ nullable: true, values: 'falsy' }),
varChar('description').optional({ nullable: true, values: 'falsy' }),
uuid('fk_coordinate').optional({ nullable: false, values: 'falsy' }),
latitudeRange('latitude').optional({ nullable: false, values: 'falsy' }),
longitudeRange('longitude').optional({nullable: false, values: 'falsy'})
],
(req, res, next) => payloadExpressValidator(req, res, next, config),
(req, res, next) => modifyPlaceController(req, res, next, config),

View File

@ -5,11 +5,22 @@ const integer = field => check(field).isInt({min: Number.MIN_SAFE_INTEGER, max:
const integerRange = (field, { min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER } = {}) => check(field).isInt({min, max}).withMessage(`|${field}| must be an integer between ${min} and ${max}`)
const uuid = field => check(field).isUUID('all').withMessage(`|${field}| must be a valid UUID`)
const bigInt = field => check(field).isBigInt().withMessage(`|${field}| must be a valid BigInt`)
const longitudeRange = (field, { min = -180, max = 180 } = {}) =>
check(field)
.isFloat({ min, max })
.withMessage(`|${field}| must be a number between ${min} and ${max}`)
const latitudeRange = (field, { min = -90, max = 90 } = {}) =>
check(field)
.isFloat({ min, max })
.withMessage(`|${field}| must be a number between ${min} and ${max}`)
export {
integer,
integerRange,
uuid,
varChar,
bigInt
bigInt,
latitudeRange,
longitudeRange
}