parseLocation: strip leading zeros from IDs 💥

This commit is contained in:
Jannis R 2018-10-15 17:31:28 +02:00
parent 73261e99b4
commit 1e13cf15ae
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 6 additions and 2 deletions

View file

@ -4,6 +4,8 @@ const POI = 'P'
const STATION = 'S' const STATION = 'S'
const ADDRESS = 'A' const ADDRESS = 'A'
const leadingZeros = /^0+/
// todo: what is s.rRefL? // todo: what is s.rRefL?
const parseLocation = (profile, opt, {lines}, l) => { const parseLocation = (profile, opt, {lines}, l) => {
const res = {type: 'location'} const res = {type: 'location'}
@ -15,7 +17,7 @@ const parseLocation = (profile, opt, {lines}, l) => {
if (l.type === STATION) { if (l.type === STATION) {
const stop = { const stop = {
type: l.isMainMast ? 'station' : 'stop', type: l.isMainMast ? 'station' : 'stop',
id: l.extId, id: (l.extId || '').replace(leadingZeros, ''),
name: l.name ? profile.parseStationName(l.name) : null, name: l.name ? profile.parseStationName(l.name) : null,
location: 'number' === typeof res.latitude ? res : null location: 'number' === typeof res.latitude ? res : null
} }
@ -39,7 +41,7 @@ const parseLocation = (profile, opt, {lines}, l) => {
if (l.type === ADDRESS) res.address = l.name if (l.type === ADDRESS) res.address = l.name
else res.name = l.name else res.name = l.name
if (l.type === POI) res.id = l.extId || null if (l.type === POI) res.id = l.extId && l.extId.replace(leadingZeros, '') || null
return res return res
} }

View file

@ -40,11 +40,13 @@ const validateStop = (val, s, name = 'stop') => {
station.type = 'station' station.type = 'station'
s = Object.assign({station}, s) s = Object.assign({station}, s)
defaultValidators.stop(val, s, name) defaultValidators.stop(val, s, name)
// todo: check if s.id has leading zeros
} }
const validatePoi = (val, poi, name = 'location') => { const validatePoi = (val, poi, name = 'location') => {
defaultValidators.location(val, poi, name) defaultValidators.location(val, poi, name)
val.ref(val, poi.id, name + '.id') val.ref(val, poi.id, name + '.id')
// todo: check if s.id has leading zeros
a.ok(poi.name, name + '.name must not be empty') a.ok(poi.name, name + '.name must not be empty')
} }