|
| 1 | +/// <reference path="../global.d.ts" /> |
| 2 | +// @ts-check |
| 3 | + |
| 4 | +/** |
| 5 | + * Creates a new visitor. |
| 6 | + * |
| 7 | + * @param {string} name |
| 8 | + * @param {number} age |
| 9 | + * @param {string} ticketId |
| 10 | + * @returns {Visitor} the visitor that was created |
| 11 | + */ |
| 12 | +export function createVisitor(name, age, ticketId) { |
| 13 | + return { name, age, ticketId }; |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * Revokes a ticket for a visitor. |
| 18 | + * |
| 19 | + * @param {Visitor} visitor the visitor with an active ticket |
| 20 | + * @returns {Visitor} the visitor without a ticket |
| 21 | + */ |
| 22 | +export function revokeTicket(visitor) { |
| 23 | + visitor.ticketId = null; |
| 24 | + return visitor; |
| 25 | +} |
| 26 | + |
| 27 | +/** |
| 28 | + * Determines the status a ticket has in the ticket tracking object. |
| 29 | + * |
| 30 | + * @param {Record<string, string|null>} tickets |
| 31 | + * @param {string} ticketId |
| 32 | + * @returns {string} ticket status |
| 33 | + */ |
| 34 | +export function ticketStatus(tickets, ticketId) { |
| 35 | + if (tickets[ticketId] === undefined) { |
| 36 | + return 'unknown ticket id'; |
| 37 | + } |
| 38 | + |
| 39 | + if (tickets[ticketId] === null) { |
| 40 | + return 'not sold'; |
| 41 | + } |
| 42 | + |
| 43 | + return 'sold to ' + tickets[ticketId]; |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * Determines the status a ticket has in the ticket tracking object |
| 48 | + * and returns a simplified status message. |
| 49 | + * |
| 50 | + * @param {Record<string, string|null>} tickets |
| 51 | + * @param {string} ticketId |
| 52 | + * @returns {string} ticket status |
| 53 | + */ |
| 54 | +export function simpleTicketStatus(tickets, ticketId) { |
| 55 | + return tickets[ticketId] ?? 'invalid ticket !!!'; |
| 56 | +} |
| 57 | + |
| 58 | +/** |
| 59 | + * Determines the version of the GTC that was signed by the visitor. |
| 60 | + * |
| 61 | + * @param {VisitorWithGtc} visitor |
| 62 | + * @returns {string | undefined} version |
| 63 | + */ |
| 64 | +export function gtcVersion(visitor) { |
| 65 | + return visitor.gtc?.version; |
| 66 | +} |
0 commit comments