From f622a750acb4325f9d2de8599429892bf9232506 Mon Sep 17 00:00:00 2001 From: HappyNTH Date: Thu, 21 Nov 2024 11:12:41 +0000 Subject: [PATCH] Patch Release v1.2.4a fix: Fix hardware ticket scanner (#755) --- classes/Ticket.ts | 3 +-- components/ui/Input/UiInputTicketScanner.client.vue | 3 ++- composables/useHardwareTicketScanner.ts | 2 +- pages/box-office/[performanceId]/index.vue | 5 ++++- tests/unit/classes/Ticket.spec.js | 8 +------- yarn.lock | 8 ++++---- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/classes/Ticket.ts b/classes/Ticket.ts index fe53e3916..a6dc2c737 100644 --- a/classes/Ticket.ts +++ b/classes/Ticket.ts @@ -54,9 +54,8 @@ export default class { return ticket; } - static dataFromQRCode(detectedCodes: [string]) { + static dataFromQRCode(rawValue: string) { try { - const rawValue = JSON.parse(JSON.stringify(detectedCodes[0])).rawValue; const result = JSON.parse(atob(rawValue)); return { bookingReference: result[0], diff --git a/components/ui/Input/UiInputTicketScanner.client.vue b/components/ui/Input/UiInputTicketScanner.client.vue index 989ec18c1..c523b911a 100644 --- a/components/ui/Input/UiInputTicketScanner.client.vue +++ b/components/ui/Input/UiInputTicketScanner.client.vue @@ -94,7 +94,8 @@ function onDetect(string: [string]) { new Audio('/audio/beep_single.mp3').play(); try { - const ticketData = Ticket.dataFromQRCode(string); + const rawValue = JSON.parse(JSON.stringify(string[0])).rawValue; + const ticketData = Ticket.dataFromQRCode(rawValue); if (props.pauseOnDecode) { cameraReset.value = true; } diff --git a/composables/useHardwareTicketScanner.ts b/composables/useHardwareTicketScanner.ts index 425eae4d7..bf2ca0a55 100644 --- a/composables/useHardwareTicketScanner.ts +++ b/composables/useHardwareTicketScanner.ts @@ -12,7 +12,7 @@ export default function useHardwareTicketScanner() { if (!value) return (ticketDetails.value = undefined); try { - ticketDetails.value = Ticket.dataFromQRCode([value]); + ticketDetails.value = Ticket.dataFromQRCode(value); } catch (e) { if (e instanceof InvalidTicketQRCodeException) { return (isInvalid.value = true); diff --git a/pages/box-office/[performanceId]/index.vue b/pages/box-office/[performanceId]/index.vue index d378c6a36..1d2e52f6f 100644 --- a/pages/box-office/[performanceId]/index.vue +++ b/pages/box-office/[performanceId]/index.vue @@ -141,6 +141,9 @@ watch([searchText, searchFilter], () => { }); watch(scannedCode, async (newValue) => { + // Handles QR code scanning with physical scanners + // Mobile scanning is handled by the UiInputTicketScanner component + // If the newly scaned code is undefined (i.e. telling us a new code is about to be scanned) reset the state if (!newValue) { setCheckInState(); @@ -149,7 +152,7 @@ watch(scannedCode, async (newValue) => { try { // Convert the scanned text into ticket data - const ticketDetails = Ticket.dataFromQRCode([newValue]); + const ticketDetails = Ticket.dataFromQRCode(newValue); // Do the scan action as appropriate let state = await handleTicketScan( diff --git a/tests/unit/classes/Ticket.spec.js b/tests/unit/classes/Ticket.spec.js index 3f88c88d4..62c6aaa58 100644 --- a/tests/unit/classes/Ticket.spec.js +++ b/tests/unit/classes/Ticket.spec.js @@ -103,13 +103,7 @@ describe('Ticket Class', () => { }); it('can get data from a QR code', () => { - expect( - Ticket.dataFromQRCode([ - { - rawValue: 'WyJhYmNkMTIzNCIsMl0=' - } - ]) - ).to.include({ + expect(Ticket.dataFromQRCode('WyJhYmNkMTIzNCIsMl0=')).to.include({ bookingReference: 'abcd1234', ticketId: 2 }); diff --git a/yarn.lock b/yarn.lock index 4134fce61..56ff97cb4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5968,10 +5968,10 @@ cross-inspect@1.0.1: dependencies: tslib "^2.4.0" -cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3: - version "7.0.3" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" - integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== +cross-spawn@^7.0.0, cross-spawn@^7.0.3, cross-spawn@^7.0.5: + version "7.0.6" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.6.tgz#8a58fe78f00dcd70c370451759dfbfaf03e8ee9f" + integrity sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA== dependencies: path-key "^3.1.0" shebang-command "^2.0.0"