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

View file

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

View file

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