2017-11-12 23:51:39 +01:00
|
|
|
'use strict'
|
|
|
|
|
2017-12-11 16:06:37 +01:00
|
|
|
const _createParseJourney = require('../../parse/journey')
|
|
|
|
const _formatStation = require('../../format/station')
|
2017-12-18 20:01:12 +01:00
|
|
|
const {bike} = require('../../format/filters')
|
2017-11-12 23:51:39 +01:00
|
|
|
|
2018-03-16 14:23:27 +01:00
|
|
|
const products = require('./products')
|
2017-11-12 23:51:39 +01:00
|
|
|
const formatLoyaltyCard = require('./loyalty-cards').format
|
|
|
|
|
|
|
|
const transformReqBody = (body) => {
|
|
|
|
body.client = {id: 'DB', v: '16040000', type: 'IPH', name: 'DB Navigator'}
|
|
|
|
body.ext = 'DB.R15.12.a'
|
|
|
|
body.ver = '1.15'
|
|
|
|
body.auth = {type: 'AID', aid: 'n91dB8Z77MLdoR0K'}
|
|
|
|
|
|
|
|
return body
|
|
|
|
}
|
|
|
|
|
|
|
|
const transformJourneysQuery = (query, opt) => {
|
|
|
|
const filters = query.jnyFltrL
|
|
|
|
if (opt.bike) filters.push(bike)
|
|
|
|
|
|
|
|
query.trfReq = {
|
2017-12-12 23:15:06 +01:00
|
|
|
jnyCl: opt.firstClass === true ? 1 : 2,
|
2017-11-12 23:51:39 +01:00
|
|
|
tvlrProf: [{
|
|
|
|
type: 'E',
|
|
|
|
redtnCard: opt.loyaltyCard
|
|
|
|
? formatLoyaltyCard(opt.loyaltyCard)
|
|
|
|
: null
|
|
|
|
}],
|
|
|
|
cType: 'PK'
|
|
|
|
}
|
|
|
|
|
|
|
|
return query
|
|
|
|
}
|
|
|
|
|
2017-12-11 16:06:37 +01:00
|
|
|
const createParseJourney = (profile, stations, lines, remarks) => {
|
|
|
|
const parseJourney = _createParseJourney(profile, stations, lines, remarks)
|
|
|
|
|
2017-12-11 19:40:46 +01:00
|
|
|
// todo: j.sotRating, j.conSubscr, j.isSotCon, j.showARSLink, k.sotCtxt
|
|
|
|
// todo: j.conSubscr, j.showARSLink, j.useableTime
|
2017-12-11 16:06:37 +01:00
|
|
|
const parseJourneyWithPrice = (j) => {
|
|
|
|
const res = parseJourney(j)
|
|
|
|
|
|
|
|
// todo: find cheapest, find discounts
|
|
|
|
// todo: write a parser like vbb-parse-ticket
|
|
|
|
// [ {
|
|
|
|
// prc: 15000,
|
|
|
|
// isFromPrice: true,
|
|
|
|
// isBookable: true,
|
|
|
|
// isUpsell: false,
|
|
|
|
// targetCtx: 'D',
|
|
|
|
// buttonText: 'To offer selection'
|
|
|
|
// } ]
|
|
|
|
res.price = {amount: null, hint: 'No pricing information available.'}
|
|
|
|
if (
|
|
|
|
j.trfRes &&
|
|
|
|
Array.isArray(j.trfRes.fareSetL) &&
|
|
|
|
j.trfRes.fareSetL[0] &&
|
|
|
|
Array.isArray(j.trfRes.fareSetL[0].fareL) &&
|
|
|
|
j.trfRes.fareSetL[0].fareL[0]
|
|
|
|
) {
|
|
|
|
const tariff = j.trfRes.fareSetL[0].fareL[0]
|
|
|
|
if (tariff.prc >= 0) { // wat
|
|
|
|
res.price = {amount: tariff.prc / 100, hint: null}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseJourneyWithPrice
|
|
|
|
}
|
|
|
|
|
2017-11-12 23:51:39 +01:00
|
|
|
const isIBNR = /^\d{6,}$/
|
|
|
|
const formatStation = (id) => {
|
|
|
|
if (!isIBNR.test(id)) throw new Error('station ID must be an IBNR.')
|
|
|
|
return _formatStation(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: find option for absolute number of results
|
|
|
|
|
|
|
|
const dbProfile = {
|
2017-12-11 17:21:50 +01:00
|
|
|
locale: 'de-DE',
|
2017-11-12 23:51:39 +01:00
|
|
|
timezone: 'Europe/Berlin',
|
|
|
|
endpoint: 'https://reiseauskunft.bahn.de/bin/mgate.exe',
|
2018-01-15 00:45:05 +01:00
|
|
|
|
|
|
|
salt: Buffer.from('bdI8UVj40K5fvxwf', 'utf8'),
|
|
|
|
addChecksum: true,
|
|
|
|
|
2017-11-12 23:51:39 +01:00
|
|
|
transformReqBody,
|
|
|
|
transformJourneysQuery,
|
|
|
|
|
2018-03-16 17:00:06 +01:00
|
|
|
products: products,
|
2017-12-12 03:28:54 +01:00
|
|
|
|
2017-11-12 23:51:39 +01:00
|
|
|
// todo: parseLocation
|
2017-12-11 16:06:37 +01:00
|
|
|
parseJourney: createParseJourney,
|
2017-11-12 23:51:39 +01:00
|
|
|
|
2018-03-16 16:11:32 +01:00
|
|
|
formatStation
|
2017-11-12 23:51:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = dbProfile
|