diff --git a/client/src/pages/Scan.tsx b/client/src/pages/Scan.tsx index 939aa86..f52d2dc 100644 --- a/client/src/pages/Scan.tsx +++ b/client/src/pages/Scan.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import { Html5QrcodeScanner } from 'html5-qrcode'; import { CheckCircle, XCircle, RefreshCw } from 'lucide-react'; -import { getTickets, updateTicketStatus } from '../utils/storage'; +import { getTicket, updateTicketStatus } from '../utils/storage'; import type { Ticket } from '../types'; export const Scan: React.FC = () => { @@ -25,9 +25,8 @@ export const Scan: React.FC = () => { async (decodedText) => { try { scanner.clear(); - const ticketId = decodedText; - const tickets = await getTickets('default-event'); // Hardcoded event - const ticket = tickets.find(t => t.id === ticketId); + const ticketId = decodedText.trim(); + const ticket = await getTicket(ticketId); if (ticket) { if (ticket.status === 'valid') { @@ -54,7 +53,7 @@ export const Scan: React.FC = () => { console.error(e); setScanResult({ success: false, - message: 'Scan Error: Invalid QR code.', + message: 'Invalid QR Code', }); } }, diff --git a/client/src/utils/storage.ts b/client/src/utils/storage.ts index daeaf76..3e8df02 100644 --- a/client/src/utils/storage.ts +++ b/client/src/utils/storage.ts @@ -32,6 +32,12 @@ export const getTickets = async (eventId: string): Promise => { return response.json(); }; +export const getTicket = async (ticketId: string): Promise => { + const response = await fetch(`${API_URL}/tickets/${ticketId}`, { headers: getHeaders() }); + if (!response.ok) throw new Error('Failed to fetch ticket'); + return response.json(); +}; + export const saveTicket = async (ticket: Omit): Promise => { const response = await fetch(`${API_URL}/tickets`, { method: 'POST', diff --git a/src/tickets/tickets.controller.ts b/src/tickets/tickets.controller.ts index a4c3eff..2b25611 100644 --- a/src/tickets/tickets.controller.ts +++ b/src/tickets/tickets.controller.ts @@ -16,6 +16,11 @@ export class TicketsController { return this.ticketsService.findAll(eventId); } + @Get(':id') + findOne(@Param('id') id: string) { + return this.ticketsService.findOne(id); + } + @Post(':id/resend') resendEmail(@Param('id') id: string) { return this.ticketsService.resendEmail(id); diff --git a/src/tickets/tickets.service.ts b/src/tickets/tickets.service.ts index 90ebd17..544b552 100644 --- a/src/tickets/tickets.service.ts +++ b/src/tickets/tickets.service.ts @@ -59,6 +59,13 @@ export class TicketsService { }); } + findOne(id: string) { + return this.prisma.ticket.findUnique({ + where: { id }, + include: { event: true }, + }); + } + async resendEmail(id: string) { const ticket = await this.prisma.ticket.findUnique({ where: { id },