feat(bookings): allow cancelling booking confirmations
Add API endpoint to revert confirmed bookings to pending status Add unconfirm buttons to the bookings list and confirmation page Update inventory summary when a confirmation is cancelled
This commit is contained in:
31
server/api/public/bookings/[token]/cancel.post.ts
Normal file
31
server/api/public/bookings/[token]/cancel.post.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { CancelBookingConfirmationResponse } from '~~/shared/booking'
|
||||
|
||||
import { cancelBookingConfirmationByConfirmationToken, getBookingByConfirmationToken } from '../../../../utils/booking-repository'
|
||||
import { getRequiredRouteParam, httpError } from '../../../../utils/http'
|
||||
|
||||
export default defineEventHandler(async (event): Promise<CancelBookingConfirmationResponse> => {
|
||||
const token = getRequiredRouteParam(event, 'token', 'Confirmation token')
|
||||
const existingBooking = await getBookingByConfirmationToken(token)
|
||||
|
||||
if (!existingBooking) {
|
||||
httpError(404, 'Booking not found')
|
||||
}
|
||||
|
||||
if (existingBooking.status === 'pending') {
|
||||
return {
|
||||
booking: existingBooking,
|
||||
alreadyPending: true
|
||||
}
|
||||
}
|
||||
|
||||
const booking = await cancelBookingConfirmationByConfirmationToken(token)
|
||||
|
||||
if (!booking) {
|
||||
httpError(404, 'Booking not found')
|
||||
}
|
||||
|
||||
return {
|
||||
booking,
|
||||
alreadyPending: false
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user