Allow users to select payment method and upload receipts before confirming. Add public API endpoints for payment updates and document management.
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import type { CancelBookingConfirmationResponse } from '~~/shared/booking'
|
|
|
|
import { cancelBookingConfirmationByConfirmationToken, getBookingByConfirmationToken } from '../../../../utils/booking-repository'
|
|
import { getRequiredRouteParam, httpError } from '../../../../utils/http'
|
|
|
|
export default defineEventHandler(async (event): Promise<CancelBookingConfirmationResponse> => {
|
|
const token = getRequiredRouteParam(event, 'token', 'Confirmation token')
|
|
const existingBooking = await getBookingByConfirmationToken(token, { includeTransactionDocument: true })
|
|
|
|
if (!existingBooking) {
|
|
httpError(404, 'Booking not found')
|
|
}
|
|
|
|
if (existingBooking.status === 'pending') {
|
|
return {
|
|
booking: existingBooking,
|
|
alreadyPending: true
|
|
}
|
|
}
|
|
|
|
const booking = await cancelBookingConfirmationByConfirmationToken(token)
|
|
|
|
if (!booking) {
|
|
httpError(404, 'Booking not found')
|
|
}
|
|
|
|
return {
|
|
booking: await getBookingByConfirmationToken(token, { includeTransactionDocument: true }) || booking,
|
|
alreadyPending: false
|
|
}
|
|
})
|