All files / src/lib charge-labels.ts

100% Statements 9/9
100% Branches 4/4
100% Functions 7/7
100% Lines 9/9

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            14x 243x 227x 94x 93x     14x 93x 93x               185x        
// A usage charge's or tenant fee's kind and basis in the user's language
// (openspec: usage-charges, tenancies). Shared by both, because their kinds
// and bases are the same.
import { m } from '#/paraglide/messages.js'
import type { ChargeBasis, ChargeKind } from '#/server/db/schema'
 
export const chargeKindLabel: Record<ChargeKind, () => string> = {
  water: () => m.charge_kind_water(),
  parking: () => m.charge_kind_parking(),
  sauna: () => m.charge_kind_sauna(),
  other: () => m.charge_kind_other(),
}
 
export const chargeBasisLabel: Record<ChargeBasis, () => string> = {
  fixed: () => m.charge_basis_fixed(),
  per_occupant: () => m.charge_basis_per_occupant(),
}
 
/** What a charge is called: its description for `other`, else its kind. */
export function chargeName(charge: {
  kind: ChargeKind
  description: string | null
}): string {
  return charge.kind === 'other' && charge.description !== null
    ? charge.description
    : chargeKindLabel[charge.kind]()
}