-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
promote.js
53 lines (52 loc) · 1.45 KB
/
promote.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
const { sendEmail } = require('../../../comms');
module.exports = {
promote: (userId, model) => {
model
.findOne({
_id: userId,
})
.then((dbModel) => {
const canComply = () => {
if (
dbModel.isEmployed === true &&
(dbModel.occupation === '' || dbModel.employer === '')
)
return false;
else if (dbModel.country !== 'United States') {
return dbModel.passport !== '';
} else
return (
dbModel.zip.length >= 5 &&
// both initialization and empty states are falsy
dbModel.city !== '' &&
dbModel.state !== '' &&
dbModel.address !== '' &&
dbModel.lastName !== '' &&
dbModel.firstName !== ''
);
};
return canComply;
})
.then((canComply) => {
if (canComply) {
model
.findOneAndUpdate(
{ _id: userId },
{ isCompliant: true },
{ useFindAndModify: false }
)
.then((dbModel) => {
sendEmail(
dbModel.email.length ? dbModel.email : dbModel.username,
null,
'Promoted',
dbModel.firstName
);
});
}
})
.catch((err) => {
console.error('User Controller promote() err: ' + err);
});
},
};