db-vendo-client/parse/journey.js

36 lines
845 B
JavaScript
Raw Normal View History

2017-11-11 22:35:41 +01:00
'use strict'
2017-12-28 16:56:27 +01:00
const createParseJourneyLeg = require('./journey-leg')
2017-11-11 22:35:41 +01:00
const clone = obj => Object.assign({}, obj)
2017-11-12 01:23:34 +01:00
const createParseJourney = (profile, stations, lines, remarks) => {
2017-12-28 16:56:27 +01:00
const parseLeg = createParseJourneyLeg(profile, stations, lines, remarks)
2017-11-11 22:35:41 +01:00
// todo: c.sDays
// todo: c.dep.dProgType, c.arr.dProgType
// todo: c.conSubscr
// todo: c.trfRes x vbb-parse-ticket
2017-11-12 01:23:34 +01:00
const parseJourney = (j) => {
2017-12-28 16:56:27 +01:00
const legs = j.secL.map(leg => parseLeg(j, leg))
const res = {
type: 'journey',
2017-12-28 16:56:27 +01:00
legs,
origin: legs[0].origin,
destination: legs[legs.length - 1].destination,
departure: legs[0].departure,
arrival: legs[legs.length - 1].arrival
2017-11-11 22:35:41 +01:00
}
2017-12-28 16:56:27 +01:00
if (legs.some(p => p.cancelled)) {
res.cancelled = true
res.departure = res.arrival = null
}
return res
2017-11-11 22:35:41 +01:00
}
return parseJourney
}
module.exports = createParseJourney