Kaizen
Browse modulesBookingsbookings/serverFunctions

Function: quoteBooking()

function quoteBooking(input: QuoteBookingInput, deps: QuoteBookingDeps): Promise<BookingQuote | null>;

Defined in: server/bookings/pricing-glue.ts:347

Quote the amount owed for a booking at terms-pin (§8.3).

Pipeline:

  1. If deps.payments.quoteAmount is present, delegate entirely to it (the external payment module overrides). This call is the deliberate exception to "ports are never awaited inside the transition tx" — see the note on PaymentPort.
  2. Otherwise, load active pricing domain rules + conditions through BookingRepositories.rules / .ruleConditions (same Prisma client as the enclosing transaction — avoids the ambient-binding problem).
  3. Run the engine KERNEL (matchRulesAgainstTables) → partition → qualify → calculate, scoping via the merged mapping filtered by the pinned policy bag's pricingScopes selector (see below).
  4. If no base-price rule matched, return null (no pricing configured for this org/type — caller leaves amountOwedCents null). Likewise return null when the booking has NO schedule and the matched base rule's unit is time-shaped (hour/day/night) — a time-priced booking cannot be quoted without a duration.
  5. Otherwise snapshot amountOwedCents = calculation.order.total_cents and currency = "USD" (hard-coded for v1; multi-currency is a future extension point).

pricingScopes interpretation. The policy bag carries pricingScopes: string[], but the engine wants a Record<scope_type, path> — the plan's literal scopes: policy.pricingScopes is type-impossible. We read the field as a scope-key SELECTOR: when non-empty, the merged scope mapping is filtered to those keys (rules scoped on any other type can no longer resolve a context value, so they never match this type's bookings); when empty/absent, the full merged mapping applies.

The caller is responsible for writing the returned quote into the booking row via repos.bookings.updateIfVersion (or the create data) inside the same transaction.

Parameters

ParameterType
inputQuoteBookingInput
depsQuoteBookingDeps

Returns

Promise<BookingQuote | null>

On this page