All files / src/features/recurring-amounts labels.ts

76.92% Statements 10/13
100% Branches 2/2
62.5% Functions 5/8
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                  13x         13x 319x 46x     13x 18x 43x       13x 245x     13x          
// Names for the kinds of amounts, the financing charges and the treatments,
// in the user's language, and the kinds as they appear in URLs.
import { m } from '#/paraglide/messages.js'
import type {
  FinancingTreatment,
  RecurringAmountKind,
} from '#/server/db/schema'
 
/** The amounts with one sequence per flat; financing charges are several. */
export const KINDS = [
  'maintenance_charge',
] as const satisfies readonly RecurringAmountKind[]
export type SingleKind = (typeof KINDS)[number]
 
export const kindLabel: Record<RecurringAmountKind, () => string> = {
  maintenance_charge: () => m.amounts_maintenance_charge(),
  financing_charge: () => m.amounts_financing_charge(),
}
 
export const treatmentLabel: Record<FinancingTreatment, () => string> = {
  income_recognised: () => m.amounts_treatment_income_recognised(),
  capitalised: () => m.amounts_treatment_capitalised(),
}
 
/** A financing charge's name, or the term's word for the unnamed one. */
export const chargeLabel = (charge: { name: string | null }) =>
  charge.name ?? m.amounts_financing_charge()
 
/** The kind in a URL: `maintenance-charge`. */
export const kindSlug = (kind: SingleKind) => kind.replace('_', '-')
 
export function kindFromSlug(slug: string): SingleKind | undefined {
  return KINDS.find((kind) => kindSlug(kind) === slug)
}