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
/
person.js
85 lines (77 loc) · 2.05 KB
/
person.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
import name from 'models/shared/name'
import phone from 'models/shared/phone'
import email from 'models/shared/email'
import address from 'models/shared/locations/address'
import { relationshipOptions } from 'constants/enums/relationshipOptions'
import { DEFAULT_LATEST } from 'constants/dateLimits'
const person = {
Name: {
presence: true,
model: { validator: name },
},
Dates: (value, attributes, attributeName, options = {}) => {
const { applicantBirthdate } = options
return {
presence: true,
daterange: { earliest: applicantBirthdate, latest: DEFAULT_LATEST },
}
},
Rank: (value, attributes) => {
if (attributes.RankNotApplicable
&& attributes.RankNotApplicable.applicable === false) return {}
return {
presence: true,
hasValue: true,
}
},
Relationship: {
presence: true,
array: {
validator: {
presence: true,
inclusion: relationshipOptions,
},
length: { minimum: 1 },
},
},
RelationshipOther: (value, attributes) => {
if (attributes.Relationship
&& attributes.Relationship.values
&& attributes.Relationship.values.some(i => i === 'Other')) {
return {
presence: true,
hasValue: true,
}
}
return {}
},
MobileTelephone: (value, attributes) => {
const requireNumber = !!(attributes.OtherTelephone
&& attributes.OtherTelephone.noNumber)
return {
presence: true,
model: { validator: phone, requireNumber },
}
},
OtherTelephone: (value, attributes) => {
const requireNumber = !!(attributes.MobileTelephone
&& attributes.MobileTelephone.noNumber)
return {
presence: true,
model: { validator: phone, requireNumber },
}
},
Email: (value, attributes) => {
if (attributes.EmailNotApplicable
&& attributes.EmailNotApplicable.applicable === false) return {}
return {
presence: true,
model: { validator: email },
}
},
Address: {
presence: true,
location: { validator: address },
},
}
export default person