feat: Add My Tickets feature with ticket management

- Introduce MyTickets.vue page to display user tickets with filtering options for paid, pending, and registered tickets.
- Implement useUserTickets composable for fetching and managing user ticket data.
- Update Navbar.vue to include a link to the My Tickets page.
- Enhance events API to support fetching user tickets.
- Define Ticket type in event.ts for better type safety.
This commit is contained in:
padreug 2025-08-01 21:54:05 +02:00
parent f7450627bc
commit 63d636a8a0
6 changed files with 403 additions and 2 deletions

View file

@ -1,4 +1,4 @@
import type { Event, EventsApiError } from '../types/event'
import type { Event, EventsApiError, Ticket } from '../types/event'
import { config } from '@/lib/config'
import { lnbitsAPI } from './lnbits'
@ -131,4 +131,32 @@ export async function checkPaymentStatus(eventId: string, paymentHash: string):
console.error('Error checking payment status:', error)
throw error
}
}
export async function fetchUserTickets(userId: string): Promise<Ticket[]> {
try {
const response = await fetch(
`${API_BASE_URL}/events/api/v1/tickets/user/${userId}`,
{
headers: {
'accept': 'application/json',
'X-API-KEY': API_KEY,
'Authorization': `Bearer ${lnbitsAPI.getAccessToken()}`,
},
}
)
if (!response.ok) {
const error: ApiError = await response.json()
const errorMessage = typeof error.detail === 'string'
? error.detail
: error.detail[0]?.msg || 'Failed to fetch user tickets'
throw new Error(errorMessage)
}
return await response.json()
} catch (error) {
console.error('Error fetching user tickets:', error)
throw error
}
}