feat(bookings): add transaction document uploads for bank payments
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
This commit is contained in:
35
server/api/bookings/[id]/transaction-document.get.ts
Normal file
35
server/api/bookings/[id]/transaction-document.get.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { sendStream, setHeader } from 'h3'
|
||||
|
||||
import { requireAuth } from '../../../utils/auth'
|
||||
import { getBookingTransactionDocument } from '../../../utils/booking-repository'
|
||||
import { getRequiredRouteParam, httpError } from '../../../utils/http'
|
||||
import {
|
||||
getSafeDownloadName,
|
||||
getTransactionDocumentFile
|
||||
} from '../../../utils/transaction-documents'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const auth = await requireAuth(event)
|
||||
const bookingId = getRequiredRouteParam(event, 'id', 'Booking ID')
|
||||
|
||||
const document = await getBookingTransactionDocument({
|
||||
bookingId,
|
||||
personInChargeId: auth.user.role === 'super_admin' ? undefined : auth.user.id
|
||||
})
|
||||
|
||||
if (!document) {
|
||||
httpError(404, 'Transaction document not found')
|
||||
}
|
||||
|
||||
const file = await getTransactionDocumentFile(document.storageName)
|
||||
const downloadName = getSafeDownloadName(document.originalName)
|
||||
|
||||
setHeader(event, 'content-type', document.mimeType)
|
||||
setHeader(event, 'content-length', String(file.size))
|
||||
setHeader(event, 'content-disposition', `attachment; filename="${downloadName}"`)
|
||||
setHeader(event, 'x-content-type-options', 'nosniff')
|
||||
setHeader(event, 'cache-control', 'private, no-store')
|
||||
setHeader(event, 'content-security-policy', 'sandbox')
|
||||
|
||||
return sendStream(event, file.stream)
|
||||
})
|
||||
Reference in New Issue
Block a user