feat(bookings): add payment and document upload to confirmation page
Allow users to select payment method and upload receipts before confirming. Add public API endpoints for payment updates and document management.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import type { UpdateBookingDetailsResponse } from '~~/shared/booking'
|
||||
|
||||
import {
|
||||
clearBookingTransactionDocumentByConfirmationToken,
|
||||
getBookingByConfirmationToken
|
||||
} from '../../../../utils/booking-repository'
|
||||
import { getRequiredRouteParam, httpError } from '../../../../utils/http'
|
||||
import { deleteTransactionDocument } from '../../../../utils/transaction-documents'
|
||||
|
||||
export default defineEventHandler(async (event): Promise<UpdateBookingDetailsResponse> => {
|
||||
const token = getRequiredRouteParam(event, 'token', 'Confirmation token')
|
||||
const booking = await getBookingByConfirmationToken(token, { includeTransactionDocument: true })
|
||||
|
||||
if (!booking) {
|
||||
httpError(404, 'Booking not found')
|
||||
}
|
||||
|
||||
if (booking.status !== 'pending') {
|
||||
httpError(409, 'Transaction document can only be changed before confirmation')
|
||||
}
|
||||
|
||||
const result = await clearBookingTransactionDocumentByConfirmationToken(token)
|
||||
|
||||
if (!result) {
|
||||
httpError(404, 'Booking not found')
|
||||
}
|
||||
|
||||
await deleteTransactionDocument(result.previousStorageName)
|
||||
|
||||
return {
|
||||
booking: result.booking
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user