File indexing completed on 2024-12-29 04:51:04

0001 /*
0002    SPDX-FileCopyrightText: 2023 Kai Uwe Broulik <kde@broulik.de>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 function main(pass, node)
0008 {
0009     let res = node.result[0];
0010 
0011     // Override "Gleich startet Dein kinoheld Erlebnis" with actual cinema name.
0012     const cinemaAddress = pass.field["cinema-address"];
0013     if (cinemaAddress) {
0014         res.reservationFor.location.name = cinemaAddress.label;
0015     }
0016 
0017     const movieInfo = pass.field["movieinfo"];
0018     if (movieInfo) {
0019         res.reservationFor.description = movieInfo.value;
0020     }
0021 
0022     // Even with a single ticket, it's ticketnumber*s*.
0023     const ticketNumbers = pass.field["ticketnumbers"];
0024     if (ticketNumbers) {
0025         res.reservationNumber = ticketNumbers.value;
0026     }
0027 
0028     let seatLd = JsonLd.newObject("Seat");
0029 
0030     const seatNumbers = pass.field["seat-numbers"];
0031     if (seatNumbers) {
0032         const seats = seatNumbers.value.split("; ");
0033         let rows = [];
0034         let numbers = [];
0035 
0036         seats.forEach((seat) => {
0037             const seatParts = seat.split("/");
0038 
0039             rows.push(seatParts[0]);
0040             numbers.push(seatParts[1]);
0041         });
0042 
0043         // Itinerary doesn't support multiple seats on the same reservation,
0044         // concatenate them so the information isn't lost.
0045         // Except, if all seats are in the same row, show just a single row.
0046         if (new Set(rows).size === 1) {
0047             seatLd.seatRow = rows[0];
0048         } else {
0049             seatLd.seatRow = rows.join(", ");
0050         }
0051         seatLd.seatNumber = numbers.join(", ");
0052     }
0053 
0054     const seatCategory = pass.field["seat-cat"];
0055     if (seatCategory) {
0056         seatLd.seatingType = seatCategory.value;
0057     }
0058 
0059     res.reservedTicket.ticketedSeat = seatLd;
0060 
0061     const orderPage = pass.field["order-page"];
0062     if (orderPage) {
0063         res.potentialAction = JsonLd.newObject("UpdateAction");
0064         res.potentialAction.url = orderPage.value;
0065     }
0066 
0067     return res;
0068 }