@@ -3,19 +3,34 @@ env = require '../config/env'
3
3
mongoose = require (' ../models' )(env .mongo_url )
4
4
util = require ' util'
5
5
postageapp = require (' postageapp' )(env .secrets .postageapp )
6
+ _ = require (' underscore' )
7
+ async = require (' async' )
6
8
7
9
Vote = mongoose .model ' Vote'
8
10
Person = mongoose .model ' Person'
9
11
10
- Person .find { role : ' judge' , email : / @/ , twitterScreenName : / \w / }, (err , judges ) ->
12
+ nag = (judge , callback ) ->
13
+ email = judge .email .replace (/ \. nodeknockout\. com$ / , ' ' )
14
+
15
+ alreadySent = _ .include ([
16
+ # redacted
17
+ ], email)
18
+
19
+ if ! alreadySent
20
+ util .log " Sending 'judge_nag_two' to '#{ email} '" .yellow
21
+ postageapp .sendMessage
22
+ recipients : email,
23
+ template : ' judge_nag_two'
24
+ variables :
25
+ first_name : judge .name .split (/ \s / )[0 ]
26
+ , callback
27
+ else
28
+ util .log " Skipping '#{ email} '"
29
+ callback ()
30
+
31
+ Person .find { role : ' judge' , email : / @/ }, (err , judges ) ->
11
32
throw err if err
12
- judges .forEach (judge) ->
13
- Vote .count { personId : judge .id }, (err , count ) ->
14
- throw err if err
15
- votes_left = 10 - count
16
- if votes_left > 0
17
- util .log " Sending 'judge_nag_two' to '#{ judge .email } ' (#{ count} )" .yellow
18
- postageapp .apiCall judge .email , ' judge_nag_two' , null , null ,
19
- first_name : judge .name .split (/ \s / )[0 ]
20
- votes_left : if votes_left is 1 then ' 1 vote' else " #{ votes_left} votes"
21
- else util .log " Skipping '#{ judge .email } ' (#{ count} )"
33
+
34
+ async .forEachSeries judges, nag, (err ) ->
35
+ util .error (err) if err
36
+ mongoose .connection .close ()
0 commit comments