Add receipt tokens and booking_seats table to track individual tickets Create receipt and seat view pages with QR code generation
24 lines
808 B
TypeScript
24 lines
808 B
TypeScript
import type { PublicBookingReceipt } from '~~/shared/booking'
|
|
|
|
import { getBookingReceiptByReceiptToken } from '../../../utils/booking-repository'
|
|
import { buildAppUrl } from '../../../utils/app-url'
|
|
import { getRequiredRouteParam, httpError } from '../../../utils/http'
|
|
|
|
export default defineEventHandler(async (event): Promise<PublicBookingReceipt> => {
|
|
const token = getRequiredRouteParam(event, 'token', 'Receipt token')
|
|
const receipt = await getBookingReceiptByReceiptToken(token)
|
|
|
|
if (!receipt) {
|
|
httpError(404, 'Receipt not found')
|
|
}
|
|
|
|
return {
|
|
booking: receipt.booking,
|
|
receiptUrl: buildAppUrl(event, `/receipt/${receipt.booking.receiptToken}`),
|
|
seats: receipt.seats.map((seat) => ({
|
|
...seat,
|
|
seatUrl: buildAppUrl(event, `/seat/${seat.seatToken}`)
|
|
}))
|
|
}
|
|
})
|