● Zion Boggan
repos/Docket/lib/vote-subject.ts
zionboggan.com ↗
79 lines · typescript
History for this file →
1
 
2
 
3
import { formatBillNumber } from "@/lib/format";
4
 
5
export type VoteSubjectKind =
6
  | "bill"
7
  | "nomination"
8
  | "treaty"
9
  | "ref"
10
  | "question"
11
  | "result";
12
 
13
export type VoteSubject = {
14
  primary: string;
15
  secondary: string;
16
  kind: VoteSubjectKind;
17
};
18
 
19
export type VoteSubjectInput = {
20
  billId?: number | null;
21
  billNumber?: string;
22
  billTitle?: string;
23
  billTextRef?: string;
24
  question?: string;
25
  result?: string;
26
};
27
 
28
export function resolveVoteSubject(v: VoteSubjectInput): VoteSubject {
29
  const ref = v.billTextRef ?? "";
30
  const question = v.question ?? "";
31
  const result = v.result ?? "";
32
 
33
  if (v.billNumber) {
34
    const title = v.billTitle ? ` -${v.billTitle}` : "";
35
    return {
36
      primary: `${formatBillNumber(v.billNumber)}${title}`,
37
      secondary: question || result,
38
      kind: "bill",
39
    };
40
  }
41
 
42
  if (ref.toUpperCase().startsWith("PN")) {
43
    return {
44
      primary: `Nomination -${question || ref}`,
45
      secondary: result,
46
      kind: "nomination",
47
    };
48
  }
49
 
50
  if (ref.toUpperCase().startsWith("TREATYDOC")) {
51
    return {
52
      primary: `Treaty document -${question || ref}`,
53
      secondary: result,
54
      kind: "treaty",
55
    };
56
  }
57
 
58
  if (ref) {
59
    return {
60
      primary: formatBillNumber(ref),
61
      secondary: question || result,
62
      kind: "ref",
63
    };
64
  }
65
 
66
  if (question) {
67
    return {
68
      primary: question,
69
      secondary: result,
70
      kind: "question",
71
    };
72
  }
73
 
74
  return {
75
    primary: result || "Roll-call vote",
76
    secondary: "",
77
    kind: "result",
78
  };
79
}