parseLocation: L param as fallback ID

This commit is contained in:
Jannis R 2019-02-05 19:07:19 +01:00
parent 9c449958c4
commit 4a79b91680
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 9 additions and 4 deletions

View file

@ -6,7 +6,7 @@ const DEBUG = process.env.DEBUG === 'hafas-client'
const {join} = require('path')
const createHash = require('create-hash')
const captureStackTrace = DEV ? require('capture-stack-trace') : () => {}
const {stringify} = require('query-string')
const {stringify} = require('qs')
const Promise = require('pinkie-promise')
const {fetch} = require('fetch-ponyfill')({Promise})

View file

@ -44,7 +44,7 @@
"p-retry": "^2.0.0",
"p-throttle": "^2.1.0",
"pinkie-promise": "^2.0.1",
"query-string": "^6.0.0",
"qs": "^6.6.0",
"slugg": "^1.2.0",
"vbb-parse-line": "^0.3.1",
"vbb-parse-ticket": "^0.2.1",

View file

@ -1,5 +1,7 @@
'use strict'
const {parse} = require('qs')
const POI = 'P'
const STATION = 'S'
const ADDRESS = 'A'
@ -14,10 +16,13 @@ const parseLocation = (profile, opt, {lines}, l) => {
res.longitude = l.crd.x / 1000000
}
const lid = parse(l.lid, {delimiter: '@'})
const id = (l.extId || lid.L || '').replace(leadingZeros, '') || null
if (l.type === STATION) {
const stop = {
type: l.isMainMast ? 'station' : 'stop',
id: (l.extId || '').replace(leadingZeros, ''),
id,
name: l.name ? profile.parseStationName(l.name) : null,
location: 'number' === typeof res.latitude ? res : null
}
@ -41,7 +46,7 @@ const parseLocation = (profile, opt, {lines}, l) => {
if (l.type === ADDRESS) res.address = l.name
else res.name = l.name
if (l.type === POI) res.id = l.extId && l.extId.replace(leadingZeros, '') || null
if (l.type === POI) res.id = id
return res
}