refactor(bookings): simplify capacity tracking to use seats

Replace 'pax' booking mode with 'seat'
Consolidate inventory summary to track only seat counts
Update database schema and UI for seat-centric capacity
This commit is contained in:
2026-04-13 08:49:54 +08:00
parent c47d0d287e
commit faa998c7e1
12 changed files with 136 additions and 139 deletions

View File

@@ -11,7 +11,7 @@ import type {
TicketType
} from '~~/shared/booking'
import { calculateBookingInventorySummary, isBookingStatus } from '~~/shared/booking'
import { calculateBookingInventorySummary, isBookingMode, isBookingStatus } from '~~/shared/booking'
import { randomToken, toIsoString } from './base64url'
import { ensureDatabaseReady } from './db-init'
@@ -23,7 +23,7 @@ type DbBookingRow = {
receipt_token: string
customer_name: string
customer_phone: string
booking_mode: BookingMode
booking_mode: string
quantity: number | string
seat_count: number | string
ticket_type: TicketType
@@ -54,7 +54,7 @@ type DbBookingSeatWithBookingRow = DbBookingSeatRow & {
receipt_token: string
customer_name: string
customer_phone: string
booking_mode: BookingMode
booking_mode: string
quantity: number | string
seat_count: number | string
ticket_type: TicketType
@@ -67,6 +67,7 @@ type DbBookingSeatWithBookingRow = DbBookingSeatRow & {
type DbBookingSettingsRow = {
total_tables: number | string | null
total_seats: number | string | null
updated_at: Date | string
}
@@ -74,16 +75,22 @@ function parseInteger(value: number | string) {
return typeof value === 'number' ? value : Number.parseInt(value, 10)
}
function normalizeBookingMode(value: string): BookingMode {
return isBookingMode(value) ? value : 'seat'
}
function mapBooking(row: DbBookingRow): PublicBooking {
const seatCount = parseInteger(row.seat_count)
return {
id: row.id,
confirmationToken: row.confirmation_token,
receiptToken: row.receipt_token,
customerName: row.customer_name,
customerPhone: row.customer_phone,
bookingMode: row.booking_mode,
bookingMode: normalizeBookingMode(row.booking_mode),
quantity: parseInteger(row.quantity),
seatCount: parseInteger(row.seat_count),
seatCount,
ticketType: row.ticket_type,
unitPrice: parseInteger(row.unit_price),
totalPrice: parseInteger(row.total_price),
@@ -97,14 +104,16 @@ function mapBooking(row: DbBookingRow): PublicBooking {
}
function mapReceiptBooking(row: DbBookingRow | DbBookingSeatWithBookingRow): ReceiptBooking {
const seatCount = parseInteger(row.seat_count)
return {
id: row.id,
receiptToken: row.receipt_token,
customerName: row.customer_name,
customerPhone: row.customer_phone,
bookingMode: row.booking_mode,
bookingMode: normalizeBookingMode(row.booking_mode),
quantity: parseInteger(row.quantity),
seatCount: parseInteger(row.seat_count),
seatCount,
ticketType: row.ticket_type,
unitPrice: parseInteger(row.unit_price),
totalPrice: parseInteger(row.total_price),
@@ -130,13 +139,17 @@ function mapBookingSeat(row: DbBookingSeatRow): PublicBookingSeat {
function mapBookingCapacitySettings(row: DbBookingSettingsRow | undefined): BookingCapacitySettings {
if (!row) {
return {
totalTables: null,
totalSeats: null,
updatedAt: null
}
}
const totalSeats = row.total_seats === null
? (row.total_tables === null ? null : parseInteger(row.total_tables) * 10)
: parseInteger(row.total_seats)
return {
totalTables: row.total_tables === null ? null : parseInteger(row.total_tables),
totalSeats,
updatedAt: toIsoString(row.updated_at)
}
}
@@ -521,6 +534,7 @@ export async function getBookingCapacitySettings(): Promise<BookingCapacitySetti
const [row] = await sql<DbBookingSettingsRow[]>`
select
total_tables,
total_seats,
updated_at
from booking_settings
where id = 'default'
@@ -531,7 +545,7 @@ export async function getBookingCapacitySettings(): Promise<BookingCapacitySetti
}
export async function updateBookingCapacitySettings(input: {
totalTables: number | null
totalSeats: number | null
}): Promise<BookingCapacitySettings> {
await ensureDatabaseReady()
const sql = getSqlClient()
@@ -539,11 +553,12 @@ export async function updateBookingCapacitySettings(input: {
const [row] = await sql<DbBookingSettingsRow[]>`
update booking_settings
set
total_tables = ${input.totalTables},
total_seats = ${input.totalSeats},
updated_at = now()
where id = 'default'
returning
total_tables,
total_seats,
updated_at
`