db-vendo-client/parse/line.js

27 lines
989 B
JavaScript
Raw Normal View History

import slugg from 'slugg';
2024-12-07 16:16:31 +00:00
const parseLine = (ctx, p) => {
const profile = ctx.profile;
const fahrtNr = p.verkehrsmittel?.nummer || p.transport?.number || p.train?.no;
const res = {
type: 'line',
2024-12-10 17:51:20 +00:00
id: slugg(p.verkehrsmittel?.langText || p.transport?.journeyDescription || p.train?.no), // TODO terrible
fahrtNr: fahrtNr ? String(fahrtNr) : undefined,
2024-12-10 17:51:20 +00:00
name: p.verkehrsmittel?.name || p.zugName || p.transport?.journeyDescription || p.train && p.train.category + ' ' + p.train.lineName,
public: true,
};
2024-12-07 16:16:31 +00:00
// TODO res.adminCode
2024-12-10 17:51:20 +00:00
res.productName = p.verkehrsmittel?.kurzText || p.transport?.category || p.train?.category;
const foundProduct = profile.products.find(pp => pp.vendo == p.verkehrsmittel?.produktGattung || pp.ris == p.transport?.type || pp.ris == p.train?.type);
2024-12-07 16:16:31 +00:00
res.mode = foundProduct?.mode;
res.product = foundProduct?.id;
2024-12-07 16:16:31 +00:00
res.operator = profile.parseOperator(ctx, p.verkehrsmittel?.zugattribute || p.zugattribute);
return res;
};
2017-11-11 22:35:41 +01:00
2022-05-07 16:17:37 +02:00
export {
parseLine,
};