Replace 'pax' booking mode with 'seat' Consolidate inventory summary to track only seat counts Update database schema and UI for seat-centric capacity
36 lines
1.0 KiB
TypeScript
36 lines
1.0 KiB
TypeScript
import { confirmBookingByConfirmationToken, getBookingByConfirmationToken, getBookingInventorySummary } from '../../../../utils/booking-repository'
|
|
import { getRequiredRouteParam, httpError } from '../../../../utils/http'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const token = getRequiredRouteParam(event, 'token', 'Confirmation token')
|
|
const existingBooking = await getBookingByConfirmationToken(token)
|
|
|
|
if (!existingBooking) {
|
|
httpError(404, 'Booking not found')
|
|
}
|
|
|
|
if (existingBooking.status === 'confirmed') {
|
|
return {
|
|
booking: existingBooking,
|
|
alreadyConfirmed: true
|
|
}
|
|
}
|
|
|
|
const summary = await getBookingInventorySummary()
|
|
|
|
if (summary.leftSeats !== null && existingBooking.seatCount > summary.leftSeats) {
|
|
httpError(409, 'Not enough capacity left to confirm this booking')
|
|
}
|
|
|
|
const booking = await confirmBookingByConfirmationToken(token)
|
|
|
|
if (!booking) {
|
|
httpError(404, 'Booking not found')
|
|
}
|
|
|
|
return {
|
|
booking,
|
|
alreadyConfirmed: false
|
|
}
|
|
})
|