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
32 lines
922 B
TypeScript
32 lines
922 B
TypeScript
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
|
|
}
|
|
})
|