Add payment method selection (Cash/Bank) to booking details Support uploading, downloading, and deleting transaction documents Update database schema and API endpoints to handle file storage
27 lines
891 B
TypeScript
27 lines
891 B
TypeScript
import type { UpdateBookingDetailsResponse } from '~~/shared/booking'
|
|
|
|
import { requireAuth } from '../../../utils/auth'
|
|
import { clearBookingTransactionDocument } from '../../../utils/booking-repository'
|
|
import { getRequiredRouteParam, httpError } from '../../../utils/http'
|
|
import { deleteTransactionDocument } from '../../../utils/transaction-documents'
|
|
|
|
export default defineEventHandler(async (event): Promise<UpdateBookingDetailsResponse> => {
|
|
const auth = await requireAuth(event)
|
|
const bookingId = getRequiredRouteParam(event, 'id', 'Booking ID')
|
|
|
|
const result = await clearBookingTransactionDocument({
|
|
bookingId,
|
|
personInChargeId: auth.user.role === 'super_admin' ? undefined : auth.user.id
|
|
})
|
|
|
|
if (!result) {
|
|
httpError(404, 'Booking not found')
|
|
}
|
|
|
|
await deleteTransactionDocument(result.previousStorageName)
|
|
|
|
return {
|
|
booking: result.booking
|
|
}
|
|
})
|