Kaizen
Browse modulesPricingpricing/serverClasses

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. getPricingMatrix builds (and memoizes) the pricing-matrix repository container lazily, on first call — NOT here in the constructor — so simply constructing this class, or calling getBasePrices, never requires the consumer's Prisma client to have the PricingRateTiers/PricingRateTierRequirements models generated. Only a getPricingMatrix call does.
  • new PricingRepository(ruleRepositories) — pre-PLA-136 compatibility. This class's constructor originally took an optional RuleRepositories ("so tests can inject one bound to a transactional Prisma client"); this form honors that exact contract for getBasePrices — 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) — getPricingMatrix throws PricingMatrixUnavailableError on this path.

Constructors

Constructor

new PricingRepository(legacyRules?: RuleRepositories): PricingRepository;

Defined in: server/pricing/pricing-repository.ts:136

Parameters

ParameterType
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:

  1. Load org + pricing domain rules from the DB via the core RuleRepository (findActiveByDomainAndOrg), THEN — sequentially, not via Promise.all — the raw Rules rows via RuleCrudRepository (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-shaped Rule type doesn't carry that pricing-specific column, so this remains a set-difference rather than widening the generic engine contract.
  2. Parse each non-matrix-managed row's domain_config through PricingDomainConfig (throws on malformed config — surfaces bad rules rather than silently dropping them) and keep only calculation_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

ParameterType
organizationIdstring

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

ParameterType
organizationIdstring

Returns

Promise<PricingMatrix>

On this page