elections-types 1.0.91 → 1.0.93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/src/index.d.ts +6 -6
  2. package/dist/src/index.js +6 -6
  3. package/dist/src/types/ElectionsConfig.d.ts +6 -6
  4. package/dist/src/types/FederalElection.d.ts +27 -0
  5. package/dist/src/types/FederalElection.js +86 -0
  6. package/dist/src/types/FederalElectionCandidate.d.ts +38 -0
  7. package/dist/src/types/FederalElectionCandidate.js +99 -0
  8. package/dist/src/types/FederalElectionCandidateCommittee.d.ts +7 -0
  9. package/dist/src/types/FederalElectionCandidateCommittee.js +32 -0
  10. package/dist/src/types/FederalElectionCommittee.d.ts +27 -0
  11. package/dist/src/types/FederalElectionCommittee.js +68 -0
  12. package/dist/src/types/FederalElectionDonation.d.ts +3 -3
  13. package/dist/src/types/FederalElectionDonation.js +9 -9
  14. package/dist/src/types/FederalElectionF1File.d.ts +10 -10
  15. package/dist/src/types/FederalElectionF1File.js +24 -24
  16. package/dist/src/types/FederalElectionF24File.d.ts +3 -3
  17. package/dist/src/types/FederalElectionF24File.js +5 -5
  18. package/dist/src/types/FederalElectionF2File.d.ts +5 -5
  19. package/dist/src/types/FederalElectionF2File.js +13 -13
  20. package/dist/src/types/FederalElectionF3File.d.ts +1 -1
  21. package/dist/src/types/FederalElectionF3File.js +3 -3
  22. package/dist/src/types/FederalElectionFileExpenditure.d.ts +28 -0
  23. package/dist/src/types/FederalElectionFileExpenditure.js +70 -0
  24. package/dist/src/types/Tweet.d.ts +1 -4
  25. package/dist/src/types/Tweet.js +14 -13
  26. package/dist/src/types/UserFederalElection.d.ts +9 -0
  27. package/dist/src/types/UserFederalElection.js +24 -0
  28. package/package.json +1 -1
  29. package/src/index.ts +6 -6
  30. package/src/types/ElectionsConfig.ts +6 -6
  31. package/src/types/FederalElection.ts +105 -0
  32. package/src/types/FederalElectionCandidate.ts +118 -0
  33. package/src/types/FederalElectionCandidateCommittee.ts +42 -0
  34. package/src/types/FederalElectionCommittee.ts +84 -0
  35. package/src/types/FederalElectionDonation.ts +9 -9
  36. package/src/types/FederalElectionF1File.ts +25 -25
  37. package/src/types/FederalElectionF24File.ts +6 -6
  38. package/src/types/FederalElectionF2File.ts +13 -13
  39. package/src/types/FederalElectionF3File.ts +3 -3
  40. package/src/types/FederalElectionFileExpenditure.ts +82 -0
  41. package/src/types/Tweet.ts +13 -13
  42. package/src/types/UserFederalElection.ts +31 -0
  43. package/src/types/Candidate.ts +0 -118
  44. package/src/types/CandidateCommittee.ts +0 -42
  45. package/src/types/Committee.ts +0 -84
  46. package/src/types/Election.ts +0 -105
  47. package/src/types/Expenditure.ts +0 -82
  48. package/src/types/UserElection.ts +0 -31
@@ -2,11 +2,11 @@ export class Tweet {
2
2
  readonly tweet_id : string
3
3
  readonly username : string
4
4
  readonly url : string
5
- readonly tweet_time : string
6
- readonly tweet_content : string
7
- readonly quote? : string
5
+ readonly publish_time : string
6
+ // readonly tweet_content : string
7
+ // readonly quote? : string
8
8
  readonly html : string
9
- readonly text : string
9
+ // readonly text : string
10
10
 
11
11
  constructor(tweet : Tweet) {
12
12
  if (!Tweet.is(tweet)) {
@@ -15,11 +15,11 @@ export class Tweet {
15
15
  this.tweet_id = tweet.tweet_id
16
16
  this.username = tweet.username
17
17
  this.url = tweet.url
18
- this.tweet_time = tweet.tweet_time
19
- this.tweet_content = tweet.tweet_content
20
- this.quote = tweet.quote
18
+ this.publish_time = tweet.publish_time
19
+ // this.tweet_content = tweet.tweet_content
20
+ // this.quote = tweet.quote
21
21
  this.html = tweet.html
22
- this.text = tweet.text
22
+ // this.text = tweet.text
23
23
  }
24
24
 
25
25
  static is(tweet : any) : tweet is Tweet {
@@ -28,11 +28,11 @@ export class Tweet {
28
28
  typeof tweet.tweet_id === "string" &&
29
29
  typeof tweet.username === "string" &&
30
30
  typeof tweet.url === "string" &&
31
- typeof tweet.tweet_time === "string" &&
32
- typeof tweet.tweet_content === "string" &&
33
- (tweet.quote === undefined || typeof tweet.quote === "string") &&
34
- typeof tweet.html === "string" &&
35
- (typeof tweet.text === "string")
31
+ typeof tweet.publish_time === "string" &&
32
+ // typeof tweet.tweet_content === "string" &&
33
+ // (tweet.quote === undefined || typeof tweet.quote === "string") &&
34
+ typeof tweet.html === "string"
35
+ // (typeof tweet.text === "string")
36
36
  )
37
37
  }
38
38
  }
@@ -0,0 +1,31 @@
1
+ import { FederalElectionID, is_federal_election_id } from "./FederalElection"
2
+ import { is_long_form_type_id, LongFormTypeID } from "./FormTypeID"
3
+
4
+ export class UserFederalElection {
5
+ readonly user_id : string
6
+ readonly federal_election_id : FederalElectionID
7
+ readonly candidate_display : Record<string, number>
8
+ readonly notify : boolean
9
+
10
+ // readonly [x : string] : any
11
+
12
+ constructor(user_federal_election : UserFederalElection) {
13
+ if (!UserFederalElection.is(user_federal_election)) {
14
+ throw Error("Invalid Input.")
15
+ }
16
+ this.user_id = user_federal_election.user_id
17
+ this.federal_election_id = user_federal_election.federal_election_id
18
+ this.candidate_display = user_federal_election.candidate_display
19
+ this.notify = user_federal_election.notify
20
+ }
21
+
22
+ static is(user_federal_election : any) : user_federal_election is UserFederalElection {
23
+ return (
24
+ user_federal_election !== undefined &&
25
+ typeof user_federal_election.user_id === "string" &&
26
+ is_federal_election_id(user_federal_election.federal_election_id) &&
27
+ Object.entries(user_federal_election.candidate_display).every(([key, value]) => (typeof key === "string" && typeof value === "number")) &&
28
+ typeof user_federal_election.notify === "boolean"
29
+ )
30
+ }
31
+ }
@@ -1,118 +0,0 @@
1
- import { Committee, CommitteeAux } from "./Committee"
2
- import { ElectionID, is_election_id, is_office_id, OfficeID } from "./Election"
3
- import { Expenditure, ExpenditureAux } from "./Expenditure"
4
- import { FederalElectionF3File } from "./FederalElectionF3File"
5
- import { is_state_id, StateID } from "./State"
6
-
7
- export class ActivityIndex {
8
- readonly news_index : number
9
- readonly twitter_index : number
10
- readonly total_index : number
11
-
12
- constructor(activity_index : any) {
13
- if (!ActivityIndex.is(activity_index)) {
14
- throw Error("Invalid input.")
15
- }
16
- this.news_index = activity_index.news_index
17
- this.twitter_index = activity_index.twitter_index
18
- this.total_index = activity_index.total_index
19
- }
20
-
21
- static is(activity_index : any) : activity_index is ActivityIndex {
22
- return (
23
- activity_index !== undefined &&
24
- typeof activity_index.news_index === "number" &&
25
- typeof activity_index.twitter_index === "number" &&
26
- typeof activity_index.total_index === "number"
27
- )
28
- }
29
- }
30
-
31
- export class Candidate {
32
- readonly candidate_id : string
33
- readonly fec_name : string
34
- readonly office_id : OfficeID
35
- readonly state_id : StateID
36
- readonly district? : number
37
- readonly election_id : ElectionID
38
- readonly party_id? : string
39
- readonly active? : boolean
40
- readonly status? : string
41
- readonly federal_election_file_id? : number
42
- readonly ballotpedia_name? : string
43
- readonly ballotpedia_url? : string
44
- readonly ballotpedia_data? : Record<string, any>
45
- readonly activity_index? : ActivityIndex
46
- // readonly urls? : string[]
47
- // readonly previews? : string[]
48
- [x : string] : any
49
-
50
-
51
- constructor(candidate : Candidate) {
52
- if (!Candidate.is(candidate)) {
53
- throw Error("Invalid input.")
54
- }
55
- this.candidate_id = candidate.candidate_id
56
- this.fec_name = candidate.fec_name
57
- this.office_id = candidate.office_id
58
- this.state_id = candidate.state_id
59
- this.district = candidate.district
60
- this.election_id = candidate.election_id
61
- this.party_id = candidate.party_id
62
- this.active = candidate.active
63
- this.status = candidate.status
64
- this.federal_election_file_id = candidate.federal_election_file_id
65
- this.ballotpedia_name = candidate.ballotpedia_name
66
- this.ballotpedia_url = candidate.ballotpedia_url
67
- this.ballotpedia_data = candidate.ballotpedia_data
68
- this.activity_index = candidate.activity_index !== undefined ? new ActivityIndex(candidate.activity_index) : undefined
69
- }
70
-
71
- static is(candidate : any) : candidate is Candidate {
72
- return (
73
- candidate !== undefined &&
74
- typeof candidate.candidate_id === "string" &&
75
- typeof candidate.fec_name === "string" &&
76
- is_office_id(candidate.office_id) &&
77
- is_state_id(candidate.state_id) &&
78
- (candidate.district === undefined || typeof candidate.district === "number") &&
79
- is_election_id(candidate.election_id) &&
80
- (candidate.party_id === undefined || typeof candidate.party_id === "string") &&
81
- (candidate.active === undefined || typeof candidate.active === "boolean") &&
82
- (candidate.status === undefined || typeof candidate.status === "string") &&
83
- (candidate.federal_election_file_id === undefined || typeof candidate.federal_election_file_id === "number" && !isNaN(candidate.federal_election_file_id)) &&
84
- (candidate.ballotpedia_name === undefined || typeof candidate.ballotpedia_name === "string") &&
85
- (candidate.ballotpedia_url === undefined || typeof candidate.ballotpedia_url === "string") &&
86
- (candidate.ballotpedia_data === undefined || typeof candidate.ballotpedia_data === "object" && Object.keys(candidate.ballotpedia_data).map((key : any) => typeof key === "string")) &&
87
- (candidate.activity_index === undefined || ActivityIndex.is(candidate.activity_index))
88
- )
89
- }
90
- }
91
-
92
- export class CandidateAux extends Candidate {
93
- readonly committees : CommitteeAux[]
94
- readonly federal_election_f3_files : FederalElectionF3File[]
95
- readonly expenditures : ExpenditureAux[]
96
-
97
- constructor(candidate : any) {
98
- if (!CandidateAux.is(candidate)) {
99
- throw Error("Invalid input.")
100
- }
101
- super(candidate)
102
- this.committees = candidate.committees
103
- this.federal_election_f3_files = candidate.federal_election_f3_files
104
- this.expenditures = candidate.expenditures
105
- }
106
-
107
- static is(candidate : any) : candidate is CandidateAux {
108
- return (
109
- Candidate.is(candidate) &&
110
- Array.isArray(candidate.committees) &&
111
- candidate.committees.every(CommitteeAux.is) &&
112
- Array.isArray(candidate.federal_election_f3_files) &&
113
- candidate.federal_election_f3_files.every(FederalElectionF3File.is) &&
114
- Array.isArray(candidate.expenditures) &&
115
- candidate.expenditures.every(ExpenditureAux.is)
116
- )
117
- }
118
- }
@@ -1,42 +0,0 @@
1
- import { Committee, CommitteeAux } from "./Committee"
2
-
3
- export class CandidateCommittee {
4
- readonly candidate_id : string
5
- readonly committee_id : string
6
- [x : string] : any
7
-
8
- constructor(candidate_committee : CandidateCommittee) {
9
- if (!CandidateCommittee.is(candidate_committee)) {
10
- throw Error("Invalid input.")
11
- }
12
- this.candidate_id = candidate_committee.candidate_id
13
- this.committee_id = candidate_committee.committee_id
14
- }
15
-
16
- static is(candidate_committee : any) : candidate_committee is CandidateCommittee {
17
- return (
18
- candidate_committee !== undefined &&
19
- typeof candidate_committee.candidate_id === "string" &&
20
- typeof candidate_committee.committee_id === "string"
21
- )
22
- }
23
- }
24
-
25
- // export class CandidateCommitteeAux extends CandidateCommittee {
26
- // readonly committee : CommitteeAux
27
-
28
- // constructor(candidate_committee : any) {
29
- // if (!CandidateCommitteeAux.is(candidate_committee)) {
30
- // throw Error("Invalid input.")
31
- // }
32
- // super(candidate_committee)
33
- // this.committee = candidate_committee.committee
34
- // }
35
-
36
- // static is(candidate_committee : any) : candidate_committee is CandidateCommitteeAux {
37
- // return (
38
- // CandidateCommittee.is(candidate_committee) &&
39
- // CommitteeAux.is(candidate_committee.committee)
40
- // )
41
- // }
42
- // }
@@ -1,84 +0,0 @@
1
- import { Candidate } from "./Candidate"
2
- import { CandidateCommittee } from "./CandidateCommittee"
3
- import { FederalElectionF3File } from "./FederalElectionF3File"
4
-
5
- export const designations = ["P", "A", "U", "J", "D", "B"] as const
6
-
7
- export type CommitteeDesignation = typeof designations[number]
8
-
9
- export function is_committee_designation(designation : any) : designation is CommitteeDesignation {
10
- return designations.includes(designation)
11
- }
12
-
13
- export class Committee {
14
- readonly committee_id : string
15
- readonly name : string
16
- readonly url? : string
17
- readonly designation? : CommitteeDesignation
18
- readonly federal_election_file_id? : number
19
- readonly jfp_committee_ids? : string[]
20
- readonly jfr_committee_ids : string[]
21
- readonly aff_committee_ids : string[]
22
- readonly [x : string] : any
23
-
24
- constructor(committee : Committee) {
25
- if (!Committee.is(committee)) {
26
- throw Error("Invalid input.")
27
- }
28
- this.committee_id = committee.committee_id
29
- this.name = committee.name
30
- this.url = committee.url
31
- this.designation = committee.designation
32
- this.federal_election_file_id = committee.federal_election_file_id
33
- this.jfp_committee_ids = committee.jfp_committee_ids
34
- this.jfr_committee_ids = committee.jfr_committee_ids
35
- this.aff_committee_ids = committee.aff_committee_ids
36
- }
37
-
38
- static is(committee : any) : committee is Committee {
39
- return (
40
- committee !== undefined &&
41
- typeof committee.committee_id === "string" &&
42
- typeof committee.name === "string" &&
43
- (committee.url === undefined || typeof committee.url === "string") &&
44
- (committee.designation === undefined || is_committee_designation(committee.designation)) &&
45
- (committee.federal_election_file_id === undefined || typeof committee.federal_election_file_id === "number" && !isNaN(committee.federal_election_file_id)) &&
46
- (committee.jfp_committee_ids === undefined || Array.isArray(committee.jfp_committee_ids) && committee.jfp_committee_ids.every((committee_id : any) => typeof committee_id === "string")) &&
47
- (Array.isArray(committee.jfr_committee_ids) && committee.jfr_committee_ids.every((committee_id : any) => typeof committee_id === "string")) &&
48
- (Array.isArray(committee.aff_committee_ids) && committee.aff_committee_ids.every((committee_id : any) => typeof committee_id === "string"))
49
- )
50
- }
51
- }
52
-
53
- export class CommitteeAux extends Committee {
54
- readonly candidates : Candidate[]
55
- readonly federal_election_f3_files : FederalElectionF3File[]
56
- readonly jfp_committees? : Committee[]
57
- readonly jfr_committees : Committee[]
58
- readonly aff_committees : Committee[]
59
-
60
- constructor(committee : any) {
61
- if (!CommitteeAux.is(committee)) {
62
- throw Error("Invalid input.")
63
- }
64
- super(committee)
65
- this.candidates = committee.candidates
66
- this.federal_election_f3_files = committee.federal_election_f3_files
67
- this.jfp_committees = committee.jfp_committees
68
- this.jfr_committees = committee.jfr_committees
69
- this.aff_committees = committee.aff_committees
70
- }
71
-
72
- static is(committee : any) : committee is CommitteeAux {
73
- return (
74
- Committee.is(committee) &&
75
- Array.isArray(committee.candidates) &&
76
- committee.candidates.every(Candidate.is) &&
77
- Array.isArray(committee.federal_election_f3_files) &&
78
- committee.federal_election_f3_files.every(FederalElectionF3File.is) &&
79
- (committee.jfp_committees === undefined || Array.isArray(committee.jfp_committees) && committee.jfp_committees.every(Committee.is)) &&
80
- (Array.isArray(committee.jfr_committees) && committee.jfr_committees.every(Committee.is)) &&
81
- (Array.isArray(committee.aff_committees) && committee.aff_committees.every(Committee.is))
82
- )
83
- }
84
- }
@@ -1,105 +0,0 @@
1
- import { Candidate, CandidateAux } from "./Candidate"
2
- import { Committee, CommitteeAux } from "./Committee"
3
- import { ExpenditureAux } from "./Expenditure"
4
- import { is_state_id, state_ids, StateID } from "./State"
5
-
6
- const office_ids = ["H", "S", "P"] as const
7
-
8
- export type OfficeID = typeof office_ids[number]
9
-
10
- export function is_office_id(office_id : any) : office_id is OfficeID {
11
- return office_ids.includes(office_id)
12
- }
13
-
14
- const state_ids_without_district : StateID[] = ["AK", "DE", "ND", "SD", "VT", "WY"]
15
-
16
- export type ElectionID = string
17
-
18
- export function is_election_id(election_id : any) : election_id is ElectionID {
19
- const parts = election_id.split("-")
20
- const year = Number(parts[0])
21
- const office_id = parts[1]
22
- const state_id = parts[2]
23
- const district = Number(parts[3])
24
- if (!(Number.isInteger(year) && year > 1700 && year < 3000 && is_office_id(office_id))) {
25
- return false
26
- }
27
- if (office_id === "P" && parts.length === 2) {
28
- return true
29
- }
30
- if (!is_state_id(state_id)) {
31
- return false
32
- }
33
- if (office_id === "S" && parts.length === 3) {
34
- return true
35
- }
36
- if (office_id !== "H") {
37
- return false
38
- }
39
- if (!(state_ids_without_district.includes(state_id) && parts.length === 3 || parts.length === 4)) {
40
- return false
41
- }
42
- if (!Number.isInteger(district) && district < 100) {
43
- return false
44
- }
45
- return true
46
- }
47
-
48
- export class Election {
49
- readonly election_id : ElectionID
50
- readonly name : string
51
- readonly office_id : OfficeID
52
- readonly state_id? : StateID
53
- readonly district? : number
54
- readonly [x : string] : any
55
-
56
- constructor(election : Election) {
57
- if (!Election.is(election)) {
58
- throw Error("Invalid input.")
59
- }
60
- this.election_id = election.election_id
61
- this.name = election.name
62
- this.office_id = election.office_id
63
- this.state_id = election.state_id
64
- this.district = election.district
65
- }
66
-
67
- static is(election : any) : election is Election {
68
- return (
69
- election !== undefined &&
70
- is_election_id(election.election_id) &&
71
- typeof election.name === "string" &&
72
- is_office_id(election.office_id) &&
73
- (election.state_id === undefined || is_state_id(election.state_id)) &&
74
- (election.district === undefined || typeof election.district === "number")
75
- )
76
- }
77
- }
78
-
79
- export class ElectionAux extends Election {
80
- readonly candidates : CandidateAux[]
81
- readonly committees : CommitteeAux[]
82
- readonly expenditures : ExpenditureAux[]
83
-
84
- constructor(election : any) {
85
- if (!ElectionAux.is(election)) {
86
- throw Error("Invalid input.")
87
- }
88
- super(election)
89
- this.candidates = election.candidates.map(candidate => new CandidateAux(candidate))
90
- this.committees = election.committees.map(committee => new CommitteeAux(committee))
91
- this.expenditures = election.expenditures.map(expenditure => new ExpenditureAux(expenditure))
92
- }
93
-
94
- static is(election : any) : election is ElectionAux {
95
- return (
96
- Election.is(election) &&
97
- Array.isArray(election.candidates) &&
98
- election.candidates.every(CandidateAux.is) &&
99
- Array.isArray(election.committees) &&
100
- election.committees.every(CommitteeAux.is) &&
101
- Array.isArray(election.expenditures) &&
102
- election.expenditures.every(ExpenditureAux.is)
103
- )
104
- }
105
- }
@@ -1,82 +0,0 @@
1
- import { Candidate } from "./Candidate"
2
- import { Committee } from "./Committee"
3
- import { ElectionID, is_election_id } from "./Election"
4
- import { FederalElectionF24File } from "./FederalElectionF24File"
5
-
6
- export class Expenditure {
7
- readonly federal_election_file_id : number
8
- readonly expenditure_id : string
9
- readonly committee_id : string
10
- readonly date : string
11
- readonly payee : string
12
- readonly election_stage : string
13
- readonly election_id : ElectionID
14
- readonly candidate_id : string
15
- readonly amount : number
16
- readonly cumulative_amount : number
17
- readonly purpose : string
18
- readonly is_support : boolean
19
- readonly [x : string] : any
20
-
21
- constructor(expenditure : any) {
22
- if (!Expenditure.is(expenditure)) {
23
- throw Error("Invalid input.")
24
- }
25
- this.federal_election_file_id = expenditure.federal_election_file_id
26
- this.expenditure_id = expenditure.expenditure_id
27
- this.committee_id = expenditure.committee_id
28
- this.date = expenditure.date
29
- this.payee = expenditure.payee
30
- this.election_stage = expenditure.election_stage
31
- this.election_id = expenditure.election_id
32
- this.candidate_id = expenditure.candidate_id
33
- this.amount = expenditure.amount
34
- this.cumulative_amount = expenditure.cumulative_amount
35
- this.purpose = expenditure.purpose
36
- this.is_support = expenditure.is_support
37
- }
38
-
39
- static is(expenditure : any) : expenditure is Expenditure {
40
- return (
41
- expenditure !== undefined &&
42
- typeof expenditure.federal_election_file_id === "number" &&
43
- typeof expenditure.expenditure_id === "string" &&
44
- typeof expenditure.committee_id === "string" &&
45
- typeof expenditure.date === "string" &&
46
- typeof expenditure.payee === "string" &&
47
- typeof expenditure.election_stage === "string" &&
48
- is_election_id(expenditure.election_id) &&
49
- typeof expenditure.candidate_id === "string" &&
50
- typeof expenditure.amount === "number" &&
51
- typeof expenditure.cumulative_amount === "number" &&
52
- typeof expenditure.purpose === "string" &&
53
- typeof expenditure.is_support === "boolean"
54
- )
55
- }
56
-
57
- }
58
-
59
- export class ExpenditureAux extends Expenditure {
60
- readonly candidate : Candidate
61
- readonly committee : Committee
62
- readonly federal_election_f24_file : FederalElectionF24File
63
-
64
- constructor(expenditure : any) {
65
- if (!ExpenditureAux.is(expenditure)) {
66
- throw Error("Invalid input.")
67
- }
68
- super(expenditure)
69
- this.candidate = new Candidate(expenditure.candidate)
70
- this.committee = new Committee(expenditure.committee)
71
- this.federal_election_f24_file = new FederalElectionF24File(expenditure.federal_election_f24_file)
72
- }
73
-
74
- static is(expenditure : any) : expenditure is ExpenditureAux {
75
- return (
76
- Expenditure.is(expenditure) &&
77
- Candidate.is(expenditure.candidate) &&
78
- Committee.is(expenditure.committee) &&
79
- FederalElectionF24File.is(expenditure.federal_election_f24_file)
80
- )
81
- }
82
- }
@@ -1,31 +0,0 @@
1
- import { ElectionID, is_election_id } from "./Election"
2
- import { is_long_form_type_id, LongFormTypeID } from "./FormTypeID"
3
-
4
- export class UserElection {
5
- readonly user_id : string
6
- readonly election_id : ElectionID
7
- readonly candidate_display : Record<string, number>
8
- readonly notify : boolean
9
-
10
- // readonly [x : string] : any
11
-
12
- constructor(user_election : UserElection) {
13
- if (!UserElection.is(user_election)) {
14
- throw Error("Invalid Input.")
15
- }
16
- this.user_id = user_election.user_id
17
- this.election_id = user_election.election_id
18
- this.candidate_display = user_election.candidate_display
19
- this.notify = user_election.notify
20
- }
21
-
22
- static is(user_election : any) : user_election is UserElection {
23
- return (
24
- user_election !== undefined &&
25
- typeof user_election.user_id === "string" &&
26
- is_election_id(user_election.election_id) &&
27
- Object.entries(user_election.candidate_display).every(([key, value]) => (typeof key === "string" && typeof value === "number")) &&
28
- typeof user_election.notify === "boolean"
29
- )
30
- }
31
- }