mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
validateMovement: min/max longitude/latitude config
This commit is contained in:
parent
b9282435a5
commit
b55c2c1579
2 changed files with 45 additions and 32 deletions
|
@ -376,7 +376,9 @@ const validateDepartures = (val, deps, name = 'departures') => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateMovement = (val, m, name = 'movement') => {
|
const createValidateMovement = (cfg) => {
|
||||||
|
const { maxLatitude, minLatitude, maxLongitude, minLongitude } = cfg
|
||||||
|
const validateMovement = (val, m, name = 'movement') => {
|
||||||
a.ok(isObj(m), name + ' must be an object')
|
a.ok(isObj(m), name + ' must be an object')
|
||||||
// todo: let hafas-client add a .type field
|
// todo: let hafas-client add a .type field
|
||||||
|
|
||||||
|
@ -386,10 +388,18 @@ const validateMovement = (val, m, name = 'movement') => {
|
||||||
|
|
||||||
const lName = name + '.location'
|
const lName = name + '.location'
|
||||||
val.location(val, m.location, lName)
|
val.location(val, m.location, lName)
|
||||||
a.ok(m.location.latitude <= 55, lName + '.latitude is too small')
|
if ('number' === typeof maxLatitude) {
|
||||||
a.ok(m.location.latitude >= 45, lName + '.latitude is too large')
|
a.ok(m.location.latitude <= maxLatitude, lName + '.latitude is too large')
|
||||||
a.ok(m.location.longitude >= 9, lName + '.longitude is too small')
|
}
|
||||||
a.ok(m.location.longitude <= 15, lName + '.longitude is too small')
|
if ('number' === typeof minLatitude) {
|
||||||
|
a.ok(m.location.latitude >= minLatitude, lName + '.latitude is too small')
|
||||||
|
}
|
||||||
|
if ('number' === typeof maxLongitude) {
|
||||||
|
a.ok(m.location.longitude <= maxLongitude, lName + '.longitude is too large')
|
||||||
|
}
|
||||||
|
if ('number' === typeof minLongitude) {
|
||||||
|
a.ok(m.location.longitude >= minLongitude, lName + '.longitude is too small')
|
||||||
|
}
|
||||||
|
|
||||||
a.ok(Array.isArray(m.nextStops), name + '.nextStops must be an array')
|
a.ok(Array.isArray(m.nextStops), name + '.nextStops must be an array')
|
||||||
for (let i = 0; i < m.nextStops.length; i++) {
|
for (let i = 0; i < m.nextStops.length; i++) {
|
||||||
|
@ -410,6 +420,8 @@ const validateMovement = (val, m, name = 'movement') => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: validate polyline
|
// todo: validate polyline
|
||||||
|
}
|
||||||
|
return validateMovement
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateMovements = (val, ms, name = 'movements') => {
|
const validateMovements = (val, ms, name = 'movements') => {
|
||||||
|
@ -437,6 +449,6 @@ module.exports = {
|
||||||
departure: createValidateDeparture,
|
departure: createValidateDeparture,
|
||||||
departures: () => validateDepartures,
|
departures: () => validateDepartures,
|
||||||
arrivals: () => validateArrivals,
|
arrivals: () => validateArrivals,
|
||||||
movement: () => validateMovement,
|
movement: createValidateMovement,
|
||||||
movements: () => validateMovements
|
movements: () => validateMovements
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ const {
|
||||||
line: createValidateLine,
|
line: createValidateLine,
|
||||||
journeyLeg: createValidateJourneyLeg,
|
journeyLeg: createValidateJourneyLeg,
|
||||||
departure: createValidateDeparture,
|
departure: createValidateDeparture,
|
||||||
movement: _validateMovement
|
movement: createValidateMovement
|
||||||
} = require('./validators')
|
} = require('./validators')
|
||||||
|
|
||||||
const when = createWhen('Europe/Berlin', 'de-DE')
|
const when = createWhen('Europe/Berlin', 'de-DE')
|
||||||
|
@ -72,6 +72,7 @@ const validateDeparture = (validate, dep, name) => {
|
||||||
validateDirection(dep.direction, name + '.direction')
|
validateDirection(dep.direction, name + '.direction')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _validateMovement = createValidateMovement(cfg)
|
||||||
const validateMovement = (validate, m, name) => {
|
const validateMovement = (validate, m, name) => {
|
||||||
_validateMovement(validate, m, name)
|
_validateMovement(validate, m, name)
|
||||||
validateDirection(m.direction, name + '.direction')
|
validateDirection(m.direction, name + '.direction')
|
||||||
|
|
Loading…
Add table
Reference in a new issue