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 25
Expand file tree
/
Copy pathdivorce.js
More file actions
117 lines (105 loc) · 2.85 KB
/
Copy pathdivorce.js
File metadata and controls
117 lines (105 loc) · 2.85 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import name from 'models/shared/name'
import address from 'models/shared/locations/address'
import birthplaceWithoutCounty from 'models/shared/locations/birthplaceWithoutCounty'
import usCityStateZipInternationalCity from 'models/shared/locations/usCityStateZipInternationalCity'
import phone from 'models/shared/phone'
import { DEFAULT_LATEST, OTHER } from 'constants/dateLimits'
import { sortDateObjects } from 'helpers/date'
import {
previouslyMarriedOptions,
} from 'constants/enums/relationshipOptions'
const divorce = {
Name: {
presence: true,
model: { validator: name },
},
Birthdate: {
presence: true,
date: OTHER,
},
BirthPlace: {
presence: true,
location: { validator: birthplaceWithoutCounty },
},
Citizenship: {
presence: true,
country: true,
},
Telephone: (value, attributes, attributeName, options) => {
if (options.requireRelationshipMaritalDivorcePhoneNumber) {
return {
presence: true,
model: { validator: phone },
}
}
return {}
},
Recognized: (value, attributes, attributeName, options) => {
const { Birthdate } = attributes
const { applicantBirthdate } = options
const sortedDates = sortDateObjects([Birthdate, applicantBirthdate])
const earliestDate = sortedDates.length
? sortedDates[sortedDates.length - 1]
: null
return {
presence: true,
date: {
earliest: earliestDate,
latest: DEFAULT_LATEST,
},
}
},
Address: {
presence: true,
location: { validator: birthplaceWithoutCounty },
},
DateDivorced: (value, attributes) => {
const dateLimits = { latest: DEFAULT_LATEST }
if (attributes.Recognized) {
dateLimits.earliest = attributes.Recognized
}
return {
presence: true,
date: dateLimits,
}
},
Status: {
presence: true,
hasValue: {
validator: { inclusion: previouslyMarriedOptions },
},
},
DivorceLocation: (value, attributes) => {
if (attributes.Status
&& attributes.Status.value === 'Widowed') return {}
return {
presence: true,
location: { validator: usCityStateZipInternationalCity },
}
},
Deceased: (value, attributes) => {
if (attributes.Status
&& attributes.Status.value === 'Widowed') return {}
return {
presence: true,
hasValue: {
validator: { inclusion: ['Yes', 'No', 'DK'] },
},
}
},
DeceasedAddress: (value, attributes) => {
if (attributes.DeceasedAddressNotApplicable
&& attributes.DeceasedAddressNotApplicable.applicable === false) {
return {}
}
if (attributes.Status
&& attributes.Status.value === 'Widowed') return {}
if (attributes.Deceased
&& attributes.Deceased.value !== 'No') return {}
return {
presence: true,
location: { validator: address },
}
},
}
export default divorce