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:
parent
f7450627bc
commit
63d636a8a0
6 changed files with 403 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,19 @@ export interface Event {
|
|||
banner: string | null
|
||||
}
|
||||
|
||||
export interface Ticket {
|
||||
id: string
|
||||
wallet: string
|
||||
event: string
|
||||
name: string | null
|
||||
email: string | null
|
||||
user_id: string | null
|
||||
registered: boolean
|
||||
paid: boolean
|
||||
time: string
|
||||
reg_timestamp: string
|
||||
}
|
||||
|
||||
export interface EventsApiError {
|
||||
detail: Array<{
|
||||
loc: [string, number]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue