FDR Service API
Manages fixed deposit receipts (FDRs) including lifecycle transitions and maturity calculations. The service still throws Error instances for validation and existence checks; it will migrate to Result signatures in a later neverthrow phase.
Location: worker/services/fdr/service.ts
Dependencies
FdrRepository– storage for FDR entities- Optional
FundService– verifies fund ownership when provided - Shared financial constants – basis points, day counts, and millisecond conversions
Public Methods
createFdr(data: CreateFdrRequest): Promise<FdrEntity>
: Validates payload, ensures the fund exists, enforces reference uniqueness per fund, and creates an ACTIVE FDR with computed maturity dates.
getFdrById(id: string): Promise<FdrEntity | null>
getFdrsByFund(fundId: string): Promise<FdrEntity[]>
getActiveFdrs(fundId: string): Promise<FdrEntity[]>
getActiveFdrsByFund(fundId: string): Promise<FdrEntity[]>
: Query helpers returning nullable or array data directly from the repository.
updateFdr(id: string, data: UpdateFdrRequest): Promise<FdrEntity>
: Loads the current FDR, validates rates/terms, recalculates maturity date, and persists updates.
transitionStatus(id: string, request: FdrStatusTransitionRequest): Promise<FdrEntity>
: Validates allowed transitions (ACTIVE → MATURED → CLOSED) before updating status.
markAsMatured(id: string, maturedAt?: string): Promise<FdrEntity>
closeFdr(id: string, closedAt?: string): Promise<FdrEntity>
: Convenience wrappers around transitionStatus.
calculateExpectedMaturityValue(id: string): Promise<ExpectedMaturityValue>
: Computes simple interest at maturity using the stored term and rate.
Error Semantics (Legacy)
throw new Error("...")for validation failures (missing fields, invalid rates/terms)throw new Error("Fund with ID ... not found")when the optionalFundServicereports an error Resultthrow new Error("FDR with ID ... not found")for missing entitiesthrow new Error("Invalid FDR status transition ...")for illegal status changes
Callers must wrap these methods in try/catch and convert errors into domain-friendly responses (for example, via createValidationError) until the neverthrow migration lands.
Last Validated: 2025-11-10 against commit
0342a62e