This repository has been archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
foreignBenefitType.js
98 lines (86 loc) · 2.52 KB
/
foreignBenefitType.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
91
92
93
94
95
96
97
98
import { hasYesOrNo } from 'models/validate'
import {
ONE_TIME,
FUTURE,
CONTINUING,
OTHER,
foreignBenefitFrequencyOptions,
} from 'constants/enums/foreignActivityOptions'
import { DEFAULT_LATEST } from 'constants/dateLimits'
// TODO - check max currency value $2,147,483,647
const foreignBenefitType = {
Country: { presence: true, country: true },
Value: { presence: true, hasValue: { validator: { numericality: true } } },
Reason: { presence: true, hasValue: true },
Obligated: { presence: true, hasValue: { validator: hasYesOrNo } },
ObligatedExplanation: (value, attributes) => {
const { Obligated } = attributes
if (Obligated && Obligated.value === 'Yes') {
return { presence: true, hasValue: true }
}
return {}
},
Received: (value, attributes, attributeName, options) => {
const { benefitType } = options
if (benefitType === ONE_TIME) {
return {
presence: true,
date: { latest: DEFAULT_LATEST },
}
}
return {}
},
Began: (value, attributes, attributeName, options) => {
const { benefitType } = options
if ([FUTURE, CONTINUING, OTHER].indexOf(benefitType) > -1) {
const dateLimits = {}
if (benefitType === FUTURE) {
dateLimits.earliest = DEFAULT_LATEST
} else {
dateLimits.latest = DEFAULT_LATEST
}
return {
presence: true,
date: dateLimits,
}
}
return {}
},
Frequency: (value, attributes, attributeName, options) => {
const { benefitType } = options
if ([FUTURE, CONTINUING, OTHER].indexOf(benefitType) > -1) {
return {
presence: true,
hasValue: { validator: { inclusion: foreignBenefitFrequencyOptions } },
}
}
return {}
},
OtherFrequency: (value, attributes) => {
const { Frequency } = attributes
if (Frequency && Frequency.value === 'Other') {
return { presence: true, hasValue: true }
}
return {}
},
End: (value, attributes, attributeName, options) => {
const { benefitType } = options
if ([CONTINUING, OTHER].indexOf(benefitType) > -1) {
const dateLimits = {}
if (attributes.Began) dateLimits.earliest = attributes.Began
return {
presence: true,
date: dateLimits,
}
}
return {}
},
OtherFrequencyTypeExplanation: (value, attributes, attributeName, options) => {
const { benefitType } = options
if (benefitType === OTHER) {
return { presence: true, hasValue: true }
}
return {}
},
}
export default foreignBenefitType