This commit is contained in:
DerJesen
2025-11-29 14:14:54 +01:00
parent cd6a832ad0
commit 1df2487d1c
4 changed files with 22 additions and 5 deletions

View File

@@ -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',
});
}
},

View File

@@ -32,6 +32,12 @@ export const getTickets = async (eventId: string): Promise<Ticket[]> => {
return response.json();
};
export const getTicket = async (ticketId: string): Promise<Ticket> => {
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<Ticket, 'id' | 'status' | 'createdAt'>): Promise<Ticket> => {
const response = await fetch(`${API_URL}/tickets`, {
method: 'POST',

View File

@@ -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);

View File

@@ -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 },