db-vendo-client/parse/journey.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-05-07 16:17:37 +02:00
import {findRemarks} from './find-remarks.js'
2021-11-18 18:29:25 +01:00
// todo: c.conSubscr (e.g. `F`)
// todo: c.trfRes x vbb-parse-ticket
// todo: c.sotRating, c.isSotCon, c.sotCtxt
// todo: c.showARSLink
// todo: c.useableTime
2021-11-18 18:29:25 +01:00
// todo: c.cksum (e.g. `b3a94228_3`), c.cksumDti (e.g. `c2717eb3_3`)
// todo: c.isNotRdbl
// todo: c.badSecRefX
// todo: c.bfATS, c.bfIOSTS
2021-11-18 18:29:25 +01:00
// todo: c.recState (e.g. `U`)
// todo: c.intvlSubscr (e.g. `F`)
const parseJourney = (ctx, j) => { // j = raw jouney
const {profile, opt} = ctx
const legs = j.secL.map(l => profile.parseJourneyLeg(ctx, l, j.date))
const res = {
type: 'journey',
legs,
refreshToken: (j.recon && j.recon.ctx) || j.ctxRecon || null
}
2018-12-02 01:05:19 +01:00
const freq = j.freq || {}
if (freq.minC || freq.maxC) {
res.cycle = {}
if (freq.minC) res.cycle.min = freq.minC * 60
if (freq.maxC) res.cycle.max = freq.maxC * 60
// nr of connections in this frequency, from now on
if (freq.numC) res.cycle.nr = freq.numC
}
if (opt.remarks && Array.isArray(j.msgL)) {
res.remarks = findRemarks(j.msgL).map(([remark]) => remark)
}
2018-07-23 20:42:22 +02:00
2022-11-16 15:18:12 +01:00
if (opt.scheduledDays && j.sDays) {
// todo [breaking]: rename to scheduledDates
res.scheduledDays = profile.parseScheduledDays(ctx, j.sDays)
2017-11-11 22:35:41 +01:00
}
return res
2017-11-11 22:35:41 +01:00
}
2022-05-07 16:17:37 +02:00
export {
parseJourney,
}