From 5c5c1acd4400a468ff67749d21e53ec6fba124cd Mon Sep 17 00:00:00 2001 From: Traines Date: Tue, 17 Dec 2024 20:43:54 +0000 Subject: [PATCH] don't set undefined price fields --- p/db/index.js | 21 ++++++++++++++------- test/fixtures/db-refresh-journey.js | 9 --------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/p/db/index.js b/p/db/index.js index 2bfb872f..8af394cc 100644 --- a/p/db/index.js +++ b/p/db/index.js @@ -250,21 +250,28 @@ const mutateToAddTickets = (parsed, opt, j) => { .filter(s => s.typ == 'REISEANGEBOT' && !s.angebotsbeziehungList.flatMap(b => b.referenzen) .find(r => r.referenzAngebotsoption == 'PFLICHT')) .map((s) => { - return { + const p = { name: s.name, priceObj: { amount: Math.round(s.preis?.betrag * 100), currency: s.preis?.waehrung, }, - addData: s.teilpreis ? 'Teilpreis / partial fare' : undefined, - addDataTicketInfo: s.konditionsAnzeigen?.map(a => a.anzeigeUeberschrift) - .join('. '), - addDataTicketDetails: s.konditionsAnzeigen?.map(a => a.textLang) - .join(' '), - addDataTravelInfo: s.leuchtturmInfo?.text, firstClass: s.klasse == 'KLASSE_1', partialFare: s.teilpreis, }; + if (s.teilpreis) { + p.addData = 'Teilpreis / partial fare'; + } + if (s.konditionsAnzeigen) { + p.addDataTicketInfo = s.konditionsAnzeigen?.map(a => a.anzeigeUeberschrift) + .join('. '); + p.addDataTicketDetails = s.konditionsAnzeigen?.map(a => a.textLang) + .join(' '); + } + if (s.leuchtturmInfo) { + p.addDataTravelInfo = s.leuchtturmInfo?.text; + } + return p; }); if (opt.generateUnreliableTicketUrls) { // TODO diff --git a/test/fixtures/db-refresh-journey.js b/test/fixtures/db-refresh-journey.js index 5de2d0bc..6d9724e3 100644 --- a/test/fixtures/db-refresh-journey.js +++ b/test/fixtures/db-refresh-journey.js @@ -183,10 +183,8 @@ const dbJourney = { amount: 2799, currency: 'EUR', }, - addData: undefined, addDataTicketInfo: 'Train-specific travel. No cancellations', addDataTicketDetails: 'You can use all trains indicated on your ticket. Your ticket constitutes a continuous contract of carriage in each direction (through ticket). Should you make a passenger rights claim, the ticket will be considered in its entirety. Special rules apply to tickets including City-Ticket, see there. Your ticket cannot be cancelled.', - addDataTravelInfo: undefined, firstClass: false, partialFare: false, }, @@ -196,7 +194,6 @@ const dbJourney = { amount: 3599, currency: 'EUR', }, - addData: undefined, addDataTicketInfo: 'Train-specific travel. No cancellations. No access to the DB Lounge', addDataTicketDetails: 'You can use all trains indicated on your ticket. Your ticket constitutes a continuous contract of carriage in each direction (through ticket). Should you make a passenger rights claim, the ticket will be considered in its entirety. Special rules apply to tickets including City-Ticket, see there. Your ticket cannot be cancelled. Your ticket does not entitle you to use the DB Lounge.', addDataTravelInfo: 'Travel 1st class', @@ -209,10 +206,8 @@ const dbJourney = { amount: 3499, currency: 'EUR', }, - addData: undefined, addDataTicketInfo: 'Train-specific travel. Cancellation subject to a fee before first day of validity', addDataTicketDetails: 'You can use all trains indicated on your ticket. Your ticket constitutes a continuous contract of carriage in each direction (through ticket). Should you make a passenger rights claim, the ticket will be considered in its entirety. Special rules apply to tickets including City-Ticket, see there. You can cancel your ticket up to and including 17.12.2024 for a fee of EUR 10,00. You will receive a voucher for the remaining amount. No cancellation thereafter.', - addDataTravelInfo: undefined, firstClass: false, partialFare: false, }, @@ -222,7 +217,6 @@ const dbJourney = { amount: 4499, currency: 'EUR', }, - addData: undefined, addDataTicketInfo: 'Train-specific travel. Cancellation subject to a fee before first day of validity. No access to the DB Lounge', addDataTicketDetails: 'You can use all trains indicated on your ticket. Your ticket constitutes a continuous contract of carriage in each direction (through ticket). Should you make a passenger rights claim, the ticket will be considered in its entirety. Special rules apply to tickets including City-Ticket, see there. You can cancel your ticket up to and including 17.12.2024 for a fee of EUR 10,00. You will receive a voucher for the remaining amount. No cancellation thereafter. Your ticket does not entitle you to use the DB Lounge.', addDataTravelInfo: 'Travel 1st class', @@ -235,10 +229,8 @@ const dbJourney = { amount: 13280, currency: 'EUR', }, - addData: undefined, addDataTicketInfo: 'Unrestricted choice of trains. Cancellation free of charge before first day of validity. City-Ticket', addDataTicketDetails: 'Your ICE ticket lets you take any type of train. Your ticket constitutes a continuous contract of carriage in each direction (through ticket). Should you make a passenger rights claim, the ticket will be considered in its entirety. Special rules apply to tickets including City-Ticket; see there. You can cancel your ticket free of charge up to and including 17.12.2024. After that, cancellation is available for a fee of EUR 19,00. Your ticket includes a City-Ticket for Berlin, Tarifbereiche A und B and Köln, Stadtgebiet Köln (Tarifgebiet 2100). The City-Ticket is valid in conjunction with your long-distance ticket only when you use it for connecting services in local or regional rail passenger transport (e.g. S-Bahn, RE and RB trains) as part of the through ticket. The City-Ticket is issued together with your Super Sparpreis or Sparpreis ticket, depending on the journey you have booked.', - addDataTravelInfo: undefined, firstClass: false, partialFare: false, }, @@ -248,7 +240,6 @@ const dbJourney = { amount: 23910, currency: 'EUR', }, - addData: undefined, addDataTicketInfo: 'Unrestricted choice of trains. Cancellation free of charge before first day of validity. City-Ticket. Access to the DB Lounge. Seat included', addDataTicketDetails: 'Your ICE ticket lets you take any type of train. Your ticket constitutes a continuous contract of carriage in each direction (through ticket). Should you make a passenger rights claim, the ticket will be considered in its entirety. Special rules apply to tickets including City-Ticket; see there. You can cancel your ticket free of charge up to and including 17.12.2024. After that, cancellation is available for a fee of EUR 19,00. Your ticket includes a City-Ticket for Berlin, Tarifbereiche A und B and Köln, Stadtgebiet Köln (Tarifgebiet 2100). The City-Ticket is valid in conjunction with your long-distance ticket only when you use it for connecting services in local or regional rail passenger transport (e.g. S-Bahn, RE and RB trains) as part of the through ticket. The City-Ticket is issued together with your Super Sparpreis or Sparpreis ticket, depending on the journey you have booked. Your ticket entitles you to use the DB Lounge. Your ticket includes a free seat reservation.', addDataTravelInfo: 'Travel 1st class',