Files
dticket.tootaio.com/server/api/bookings/[id].delete.ts
xiaomai e05c238495 feat(bookings): allow editing and soft-deleting bookings
Add edit modal to update guest details, ticket selection, and quantity
Implement soft delete functionality to archive bookings
2026-05-08 15:57:32 +08:00

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
}
})