Add database tables and repository for managing bookings Create API endpoints for booking submission and capacity management Update landing page to persist bookings before WhatsApp redirection
27 lines
895 B
TypeScript
27 lines
895 B
TypeScript
import { requireRole } from '../../utils/auth'
|
|
import { parseBookingCapacityInput } from '../../utils/bookings'
|
|
import { getBookingInventorySummary, updateBookingCapacitySettings } from '../../utils/booking-repository'
|
|
import { assertBadRequest } from '../../utils/http'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
await requireRole(event, 'super_admin')
|
|
|
|
const body = await readBody<{
|
|
totalTables?: number | string | null
|
|
}>(event)
|
|
|
|
const input = parseBookingCapacityInput(body)
|
|
const summary = await getBookingInventorySummary()
|
|
|
|
assertBadRequest(
|
|
input.totalTables === null || (input.totalTables * 10) >= summary.soldCapacitySeats,
|
|
`Total tables cannot be lower than the currently sold capacity of ${summary.soldTables} tables and ${summary.soldSeats} seats`
|
|
)
|
|
|
|
const settings = await updateBookingCapacitySettings(input)
|
|
|
|
return {
|
|
settings
|
|
}
|
|
})
|