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 patheducation.js
117 lines (104 loc) · 2.82 KB
/
education.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import address from 'models/shared/locations/address'
import name from 'models/shared/name'
import phone from 'models/shared/phone'
import email from 'models/shared/email'
import { DEFAULT_LATEST } from 'constants/dateLimits'
import { today, dateWithinRange } from 'helpers/date'
/** Helpers */
export const educationRequiresReference = (dates = {}) => {
const { from, present } = dates
const to = present ? today.toObject() : dates.to
const educationTimeFrame = { years: 3 }
return dateWithinRange(to, educationTimeFrame)
|| dateWithinRange(from, educationTimeFrame)
}
const diploma = {
Diploma: { presence: true, hasValue: true },
DiplomaOther: (value, attributes) => {
if (attributes.Diploma && attributes.Diploma.value === 'Other') {
return {
presence: true,
hasValue: true,
}
}
return {}
},
Date: (value, attributes, attributeName, options = {}) => {
const { applicantBirthdate } = options
return {
presence: true,
date: { requireDay: false, earliest: applicantBirthdate, latest: DEFAULT_LATEST },
}
},
}
const education = {
Dates: (value, attributes, attributeName, options = {}) => {
const { applicantBirthdate } = options
return {
presence: true,
daterange: { earliest: applicantBirthdate, latest: DEFAULT_LATEST },
}
},
Address: {
presence: true,
location: { validator: address },
},
Name: {
presence: true,
hasValue: true,
},
Type: {
presence: true,
hasValue: true,
},
ReferenceName: (value, attributes = {}) => {
const { Dates, ReferenceNameNotApplicable } = attributes
if (!educationRequiresReference(Dates)) return {}
if (ReferenceNameNotApplicable && !ReferenceNameNotApplicable.applicable) {
return {}
}
return {
presence: true,
model: {
validator: name,
hideMiddleName: true,
},
}
},
ReferenceNameNotApplicable: {},
ReferencePhone: (value, attributes = {}) => (
educationRequiresReference(attributes.Dates)
? {
presence: true,
model: { validator: phone, requireNumber: true },
}
: {}
),
ReferenceEmail: (value, attributes = {}) => {
const { Dates, ReferenceEmailNotApplicable } = attributes
if (!educationRequiresReference(Dates)) return {}
if (ReferenceEmailNotApplicable && !ReferenceEmailNotApplicable.applicable) {
return {}
}
return {
presence: true,
model: { validator: email },
}
},
ReferenceEmailNotApplicable: {},
ReferenceAddress: (value, attributes = {}) => (
educationRequiresReference(attributes.Dates)
? {
presence: true,
location: { validator: address },
}
: {}
),
Diplomas: {
presence: true,
branchCollection: {
validator: diploma,
},
},
}
export default education