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
This commit is contained in:
31
server/api/bookings/[id].delete.ts
Normal file
31
server/api/bookings/[id].delete.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user