fixxed
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Html5QrcodeScanner } from 'html5-qrcode';
|
import { Html5QrcodeScanner } from 'html5-qrcode';
|
||||||
import { CheckCircle, XCircle, RefreshCw } from 'lucide-react';
|
import { CheckCircle, XCircle, RefreshCw } from 'lucide-react';
|
||||||
import { getTickets, updateTicketStatus } from '../utils/storage';
|
import { getTicket, updateTicketStatus } from '../utils/storage';
|
||||||
import type { Ticket } from '../types';
|
import type { Ticket } from '../types';
|
||||||
|
|
||||||
export const Scan: React.FC = () => {
|
export const Scan: React.FC = () => {
|
||||||
@@ -25,9 +25,8 @@ export const Scan: React.FC = () => {
|
|||||||
async (decodedText) => {
|
async (decodedText) => {
|
||||||
try {
|
try {
|
||||||
scanner.clear();
|
scanner.clear();
|
||||||
const ticketId = decodedText;
|
const ticketId = decodedText.trim();
|
||||||
const tickets = await getTickets('default-event'); // Hardcoded event
|
const ticket = await getTicket(ticketId);
|
||||||
const ticket = tickets.find(t => t.id === ticketId);
|
|
||||||
|
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
if (ticket.status === 'valid') {
|
if (ticket.status === 'valid') {
|
||||||
@@ -54,7 +53,7 @@ export const Scan: React.FC = () => {
|
|||||||
console.error(e);
|
console.error(e);
|
||||||
setScanResult({
|
setScanResult({
|
||||||
success: false,
|
success: false,
|
||||||
message: 'Scan Error: Invalid QR code.',
|
message: 'Invalid QR Code',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -32,6 +32,12 @@ export const getTickets = async (eventId: string): Promise<Ticket[]> => {
|
|||||||
return response.json();
|
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> => {
|
export const saveTicket = async (ticket: Omit<Ticket, 'id' | 'status' | 'createdAt'>): Promise<Ticket> => {
|
||||||
const response = await fetch(`${API_URL}/tickets`, {
|
const response = await fetch(`${API_URL}/tickets`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ export class TicketsController {
|
|||||||
return this.ticketsService.findAll(eventId);
|
return this.ticketsService.findAll(eventId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
findOne(@Param('id') id: string) {
|
||||||
|
return this.ticketsService.findOne(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Post(':id/resend')
|
@Post(':id/resend')
|
||||||
resendEmail(@Param('id') id: string) {
|
resendEmail(@Param('id') id: string) {
|
||||||
return this.ticketsService.resendEmail(id);
|
return this.ticketsService.resendEmail(id);
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ export class TicketsService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findOne(id: string) {
|
||||||
|
return this.prisma.ticket.findUnique({
|
||||||
|
where: { id },
|
||||||
|
include: { event: true },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async resendEmail(id: string) {
|
async resendEmail(id: string) {
|
||||||
const ticket = await this.prisma.ticket.findUnique({
|
const ticket = await this.prisma.ticket.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
|
|||||||
Reference in New Issue
Block a user