import type { PublicBookingSeatWithUrl } from '~~/shared/booking' import { updateBookingSeatShareByReceiptToken } from '../../../../../utils/booking-repository' import { parseSeatShareInput } from '../../../../../utils/bookings' import { buildAppUrl } from '../../../../../utils/app-url' import { getRequiredRouteParam, httpError } from '../../../../../utils/http' export default defineEventHandler(async (event): Promise<{ seat: PublicBookingSeatWithUrl }> => { const token = getRequiredRouteParam(event, 'token', 'Receipt token') const seatId = getRequiredRouteParam(event, 'seatId', 'Seat') const body = await readBody<{ shared?: boolean recipientName?: string | null recipientPhone?: string | null }>(event) const input = parseSeatShareInput(body) const seat = await updateBookingSeatShareByReceiptToken({ receiptToken: token, seatId, ...input }) if (!seat) { httpError(404, 'Seat not found') } return { seat: { ...seat, seatUrl: buildAppUrl(event, `/seat/${seat.seatToken}`) } } })