Class: PricingRepository
Defined in: server/pricing/pricing-repository.ts:131
Pricing-domain read repository. Display-oriented callers ask
pricing-specific questions ("what are this org's base pricing rules?",
"what's the full tier x schedule matrix?") without going through the
full matchRules engine path, and get back rules with domain_config
typed as PricingDomainConfig instead of the raw JSON view.
Two constructor forms:
new PricingRepository()— the normal form. Resolves the ambient Prisma client.getPricingMatrixbuilds (and memoizes) the pricing-matrix repository container lazily, on first call — NOT here in the constructor — so simply constructing this class, or callinggetBasePrices, never requires the consumer's Prisma client to have thePricingRateTiers/PricingRateTierRequirementsmodels generated. Only agetPricingMatrixcall does.new PricingRepository(ruleRepositories)— pre-PLA-136 compatibility. This class's constructor originally took an optionalRuleRepositories("so tests can inject one bound to a transactional Prisma client"); this form honors that exact contract forgetBasePrices— the only method that existed at the time that shape was published. It never builds the pricing-matrix repositories at all (not lazily, not eagerly) —getPricingMatrixthrowsPricingMatrixUnavailableErroron this path.
Constructors
Constructor
new PricingRepository(legacyRules?: RuleRepositories): PricingRepository;Defined in: server/pricing/pricing-repository.ts:136
Parameters
| Parameter | Type |
|---|---|
legacyRules? | RuleRepositories |
Returns
PricingRepository
Methods
getBasePrices()
getBasePrices(organizationId: string): Promise<BasePricingRule[]>;Defined in: server/pricing/pricing-repository.ts:183
Fetch every active base-phase pricing rule for the given organization,
EXCLUDING matrix-managed cell rules (PLA-136) — those surface only via
getPricingMatrix, preserving this method's existing contract for
callers that predate the pricing matrix.
Pipeline:
- Load org +
pricingdomain rules from the DB via the coreRuleRepository(findActiveByDomainAndOrg), THEN — sequentially, not viaPromise.all— the rawRulesrows viaRuleCrudRepository(findMatrixManagedIdsByDomainAndOrgIncludingDeleted) to learn which ids carry immutable matrix ownership. The ownership query deliberately includes soft-deleted/inactive rows: if a concurrent unset/status change commits between the two reads, an engine row from the earlier snapshot must still be excluded rather than leaking through as an ordinary base-price rule. The engine-shapedRuletype doesn't carry that pricing-specific column, so this remains a set-difference rather than widening the generic engine contract. - Parse each non-matrix-managed row's
domain_configthroughPricingDomainConfig(throws on malformed config — surfaces bad rules rather than silently dropping them) and keep onlycalculation_phase === "base".
The phase filter runs in memory; calculation_phase lives inside
the JSON domain_config column anyway, so a DB-level filter would
require a JSON path query for no current win.
Parameters
| Parameter | Type |
|---|---|
organizationId | string |
Returns
Promise<BasePricingRule[]>
getPricingMatrix()
getPricingMatrix(organizationId: string): Promise<PricingMatrix>;Defined in: server/pricing/pricing-repository.ts:243
The full pricing matrix for an organization (PLA-136): every active
PRICING_SCHEDULE condition as a column, every active
PricingRateTiers row as a row, and every live matrix-managed cell
Rule slotted into rateTiers[].cells[scheduleConditionId].
Sparse — a tier x schedule pair with no price set is simply absent
from cells, not present with a null amount.
Reads through getMatrixRepos(), which lazily builds and memoizes the
pricing-matrix repository container on first call rather than in the
constructor — throws PricingMatrixUnavailableError if this instance
was constructed via the legacy new PricingRepository(ruleRepositories)
compatibility form, which has no matrix repositories to serve this with.
Cells come from a single matrix-scoped CRUD query (live rows with
rateTierId set + current version), not a dual engine/CRUD full-org
scan — the matrix read doesn't need the engine-shaped Rule type.
Parameters
| Parameter | Type |
|---|---|
organizationId | string |
Returns
Promise<PricingMatrix>