All files farmer-dashboard.ts

100% Statements 11/11
100% Branches 10/10
100% Functions 1/1
100% Lines 11/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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                                                                                                                  1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x  
export interface FinanceViewModel {
  purpose: string;
  amount: string;
  existingLoans: string;
  monthlyIncome: string;
  repaymentHistory: string;
  caseId: string;
  status: "pending" | "under_review" | "approved" | "rejected";
  stages: { label: string; completed: boolean }[];
}
 
export interface CropEntry {
  crop: string;
  variety: string;
  season: string;
  expectedYield: string;
}
 
export interface TradeViewModel {
  crops: CropEntry[];
  buyerMatches: { buyerName: string; commodity: string; priceRange: string }[];
  exportDocsComplete: boolean;
}
 
export interface IdentityViewModel {
  fullName: string;
  district: string;
  gender: string;
  kycStatus: string;
  farmSizeHa: string;
  landOwnership: string;
  hasGisMapping: boolean;
  documentCompleteness: number;
}
 
export interface AssetEntry {
  assetType: string;
  description: string;
  estimatedValue: string;
  condition: string;
}
 
export interface InputsViewModel {
  assets: AssetEntry[];
  recommendedInputs: { name: string; category: string; relevance: string }[];
}
 
export interface DashboardData {
  finance: FinanceViewModel | null;
  trade: TradeViewModel | null;
  identity: IdentityViewModel | null;
  inputs: InputsViewModel | null;
  applicationStatus: string;
  score: number | null;
  eligibility: string | null;
}
 
export function mapDashboardResponse(payload: Record<string, unknown>): DashboardData {
  return {
    finance: (payload.finance as FinanceViewModel | null) ?? null,
    trade: (payload.trade as TradeViewModel | null) ?? null,
    identity: (payload.identity as IdentityViewModel | null) ?? null,
    inputs: (payload.inputs as InputsViewModel | null) ?? null,
    applicationStatus: String(payload.applicationStatus ?? "none"),
    score: payload.score != null ? Number(payload.score) : null,
    eligibility: payload.eligibility != null ? String(payload.eligibility) : null,
  };
}