This repository was archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathinvestigation.js
90 lines (79 loc) · 2.52 KB
/
investigation.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { checkValueIncluded, hasYesOrNo } from 'models/validate'
import { US_DEPT_OF_TREASURY, FOREIGN_GOVT, OTHER } from 'constants/enums/legalOptions'
import { DEFAULT_LATEST } from 'constants/dateLimits'
export const clearanceLevel = {
Level: { presence: true, hasValue: true },
Explanation: (value, attributes) => {
if (attributes.Level && attributes.Level.value === 'Other') {
return { presence: true, hasValue: true }
}
return {}
},
}
const investigation = {
Agency: (value, attributes) => {
if (attributes.AgencyNotApplicable
&& attributes.AgencyNotApplicable.applicable === false) {
return {}
}
return { presence: true, hasValue: true }
},
AgencyExplanation: (value, attributes) => {
if (checkValueIncluded(attributes.Agency, [US_DEPT_OF_TREASURY, FOREIGN_GOVT, OTHER])) {
return { presence: true, hasValue: true }
}
return {}
},
Completed: (value, attributes, attributeName, options = {}) => {
if (attributes.CompletedNotApplicable
&& attributes.CompletedNotApplicable.applicable === false) {
return {}
}
const { applicantBirthdate } = options
return {
presence: true,
date: { earliest: applicantBirthdate, latest: DEFAULT_LATEST },
}
},
Issued: {},
Granted: (value, attributes, attributeName, options) => {
if (attributes.GrantedNotApplicable
&& attributes.GrantedNotApplicable.applicable === false) {
return {}
}
if (
options.requireLegalInvestigationClearanceGranted
&& attributes.ClearanceGranted
&& attributes.ClearanceGranted.value === 'No'
) {
return {}
}
const dateLimits = { latest: DEFAULT_LATEST }
if (attributes.Completed) dateLimits.earliest = attributes.Completed
return { presence: true, date: dateLimits }
},
ClearanceGranted: (value, attributes, attributeName, options) => {
if (options.requireLegalInvestigationClearanceGranted) {
return {
presence: true,
hasValue: { validator: hasYesOrNo },
}
}
return {}
},
ClearanceLevel: (value, attributes, attributeName, options) => {
if (attributes.ClearanceLevelNotApplicable
&& attributes.ClearanceLevelNotApplicable.applicable === false) {
return {}
}
if (
options.requireLegalInvestigationClearanceGranted
&& attributes.ClearanceGranted
&& attributes.ClearanceGranted.value === 'No'
) {
return {}
}
return { presence: true, model: { validator: clearanceLevel } }
},
}
export default investigation