1
|
|
|
import { Application } from "../../models/types"; |
2
|
|
|
import { ReviewStatusId } from "../../models/lookupConstants"; |
3
|
|
|
|
4
|
|
|
type Bucket = "priority" | "citizen" | "non-citizen" | "unqualified"; |
5
|
|
|
|
6
|
|
|
type Category = "primary" | "optional" | "screened-out"; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Returns true if application has been screened out. |
10
|
|
|
*/ |
11
|
|
|
export function isScreenedOut(application: Application): boolean { |
12
|
|
|
return application.application_review && |
13
|
|
|
application.application_review.review_status |
14
|
|
|
? application.application_review.review_status.name === "screened_out" |
15
|
|
|
: false; // non-reviewed applications have not been screened-out yet |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Returns true if application has been screened in. |
20
|
|
|
*/ |
21
|
|
|
export function isStillIn(application: Application): boolean { |
22
|
|
|
return application.application_review && |
23
|
|
|
application.application_review.review_status |
24
|
|
|
? application.application_review.review_status.name === "still_in" |
25
|
|
|
: false; // non-reviewed applications have not been screened-out yet |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Return the bucket this application belongs to. Either: |
30
|
|
|
* priority |
31
|
|
|
* citizen |
32
|
|
|
* secondary |
33
|
|
|
* unqualified |
34
|
|
|
* |
35
|
|
|
*/ |
36
|
|
|
export function applicationBucket(application: Application): Bucket { |
37
|
|
|
if (!application.meets_essential_criteria) { |
38
|
|
|
if (application.citizenship_declaration.name !== "citizen") { |
39
|
|
|
return "non-citizen"; |
40
|
|
|
} |
41
|
|
|
return "unqualified"; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if (application.applicant.user.is_priority) { |
45
|
|
|
return "priority"; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (application.citizenship_declaration.name === "citizen") { |
49
|
|
|
return "citizen"; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return "non-citizen"; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return the category this application belongs to. Either: |
57
|
|
|
* primary |
58
|
|
|
* optional |
59
|
|
|
* screened-out |
60
|
|
|
* @param {Application} application |
61
|
|
|
*/ |
62
|
|
|
export function applicationCategory(application: Application): Category { |
63
|
|
|
if (isScreenedOut(application)) { |
64
|
|
|
return "screened-out"; |
65
|
|
|
} |
66
|
|
|
if (isStillIn(application)) { |
67
|
|
|
return "primary"; |
68
|
|
|
} |
69
|
|
|
const bucket = applicationBucket(application); |
70
|
|
|
|
71
|
|
|
switch (bucket) { |
72
|
|
|
case "priority": |
73
|
|
|
case "citizen": |
74
|
|
|
return "primary"; |
75
|
|
|
case "non-citizen": |
76
|
|
|
case "unqualified": |
77
|
|
|
default: |
78
|
|
|
return "optional"; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
function isVet(application: Application): boolean { |
83
|
|
|
return application.veteran_status.name !== "none"; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Compare function used for sorting applications |
88
|
|
|
*/ |
89
|
|
|
export function applicationCompare( |
90
|
|
|
first: Application, |
91
|
|
|
second: Application, |
92
|
|
|
): number { |
93
|
|
|
// Sort by status in the following order: |
94
|
|
|
// "still_in", "Not Reviewed", "still_thinking", "screened_out", |
95
|
|
|
const score = (application: Application): number => { |
96
|
|
|
switch ( |
97
|
|
|
application.application_review |
98
|
|
|
? application.application_review.review_status_id |
99
|
|
|
: null |
100
|
|
|
) { |
101
|
|
|
case ReviewStatusId.StillIn: |
102
|
|
|
return 1; |
103
|
|
|
case null: |
104
|
|
|
return 2; |
105
|
|
|
case ReviewStatusId.StillThinking: |
106
|
|
|
return 3; |
107
|
|
|
case ReviewStatusId.ScreenedOut: |
108
|
|
|
return 4; |
109
|
|
|
default: |
110
|
|
|
return 2; // Treat default same as "Not Reviewed" |
111
|
|
|
} |
112
|
|
|
}; |
113
|
|
|
|
114
|
|
|
// Add a preference for veterans within each status group |
115
|
|
|
const scoreVet = (application: Application): number => |
116
|
|
|
score(application) - (isVet(application) ? 0.1 : 0); |
117
|
|
|
const scoreDiff = scoreVet(first) - scoreVet(second); |
118
|
|
|
|
119
|
|
|
if (scoreDiff !== 0) { |
120
|
|
|
return scoreDiff; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// Otherwise, sort alphabetically by name; |
124
|
|
|
return first.applicant.user.last_name.localeCompare( |
125
|
|
|
second.applicant.user.last_name, |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Compare function used for sorting applications, which prioritizes veterans over all others. |
131
|
|
|
*/ |
132
|
|
|
export function applicationComparePrioritizeVeterans( |
133
|
|
|
first: Application, |
134
|
|
|
second: Application, |
135
|
|
|
): number { |
136
|
|
|
// Veterans come before others |
137
|
|
|
if (isVet(first) && !isVet(second)) { |
138
|
|
|
return -1; |
139
|
|
|
} |
140
|
|
|
if (!isVet(first) && isVet(second)) { |
141
|
|
|
return 1; |
142
|
|
|
} |
143
|
|
|
return applicationCompare(first, second); |
144
|
|
|
} |
145
|
|
|
|