Add edit modal to update guest details, ticket selection, and quantity Implement soft delete functionality to archive bookings
32 lines
919 B
TypeScript
32 lines
919 B
TypeScript
import type { DeleteBookingResponse } from '~~/shared/booking'
|
|
|
|
import { requireAuth } from '../../utils/auth'
|
|
import { getBookingById, softDeleteBooking } from '../../utils/booking-repository'
|
|
import { getRequiredRouteParam, httpError } from '../../utils/http'
|
|
|
|
export default defineEventHandler(async (event): Promise<DeleteBookingResponse> => {
|
|
const auth = await requireAuth(event)
|
|
const bookingId = getRequiredRouteParam(event, 'id', 'Booking ID')
|
|
|
|
const existingBooking = await getBookingById(bookingId, auth.user.role === 'super_admin'
|
|
? undefined
|
|
: { personInChargeId: auth.user.id })
|
|
|
|
if (!existingBooking) {
|
|
httpError(404, 'Booking not found')
|
|
}
|
|
|
|
const booking = await softDeleteBooking({
|
|
bookingId,
|
|
personInChargeId: auth.user.role === 'super_admin' ? undefined : auth.user.id
|
|
})
|
|
|
|
if (!booking) {
|
|
httpError(404, 'Booking not found')
|
|
}
|
|
|
|
return {
|
|
booking
|
|
}
|
|
})
|