VBB: remove vbb-parse-ticket, adapt to new response format 💥

This commit is contained in:
Jannis R 2021-12-29 18:25:56 +01:00
parent d2bc134645
commit 673d6f8279
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 20 additions and 17 deletions

View file

@ -1,7 +1,6 @@
'use strict'
const parseLineName = require('vbb-parse-line')
const parseTicket = require('vbb-parse-ticket')
const {parseHook} = require('../../lib/profile-hooks')
const parseAndAddLocationDHID = require('./parse-loc-dhid')
@ -31,23 +30,29 @@ const parseLocation = ({parsed}, l) => {
return parsed
}
// todo: move this to parse/tickets.js?
const parseJourneyWithTickets = ({parsed}, j) => {
if (
j.trfRes &&
Array.isArray(j.trfRes.fareSetL) &&
j.trfRes.fareSetL[0] &&
Array.isArray(j.trfRes.fareSetL[0].fareL)
Array.isArray(j.trfRes.fareSetL)
) {
parsed.tickets = []
const sets = j.trfRes.fareSetL[0].fareL
for (let s of sets) {
if (!Array.isArray(s.ticketL) || s.ticketL.length === 0) continue
for (let t of s.ticketL) {
const ticket = parseTicket(t)
ticket.name = s.name + ' ' + ticket.name
parsed.tickets.push(ticket)
}
}
parsed.tickets = j.trfRes.fareSetL
.map((s) => {
if (!Array.isArray(s.fareL) || s.fareL.length === 0) return null
return {
name: s.name,
description: s.desc,
tickets: s.fareL.map((f) => ({
// todo: sometimes there's also t.ticketL
name: f.name,
price: f.price,
})),
}
})
.filter(set => !!set)
// todo: j.trfRes.totalPrice
// todo: j.trfRes.msgL
}
return parsed

View file

@ -17,5 +17,4 @@ const client = createClient(vbbProfile, 'my-awesome-program')
- parses *VBB*-specific products (such as *X-Bus*)
- parses line names to give more information (e.g. "Is it an express bus?")
- parses *VBB*-specific tickets
- renames *Ringbahn* line names to contain `⟳` and `⟲`

View file

@ -61,8 +61,7 @@
"pinkie-promise": "^2.0.1",
"qs": "^6.6.0",
"slugg": "^1.2.0",
"vbb-parse-line": "^1.0.0",
"vbb-parse-ticket": "^0.2.1"
"vbb-parse-line": "^1.0.0"
},
"devDependencies": {
"eslint": "^7.0.0",