File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ module.exports = app => {
17
17
app . post ( '/api/surveys/webhooks' , ( req , res ) => {
18
18
const p = new Path ( '/api/surveys/:surveyId/:choice' ) ;
19
19
20
- const events = _ . chain ( req . body )
20
+ _ . chain ( req . body )
21
21
. map ( ( { email, url } ) => {
22
22
const match = p . test ( new URL ( url ) . pathname ) ;
23
23
if ( match ) {
@@ -26,9 +26,20 @@ module.exports = app => {
26
26
} )
27
27
. compact ( )
28
28
. uniqBy ( 'email' , 'surveyId' )
29
- . value ( ) ;
30
-
31
- console . log ( events ) ;
29
+ . each ( ( { email, choice, surveyId } ) => {
30
+ Survey . updateOne (
31
+ {
32
+ id : surveyId ,
33
+ recipients : {
34
+ $elemMatch : { email : email , responded : false }
35
+ }
36
+ } ,
37
+ {
38
+ $inc : { [ choice ] : 1 } ,
39
+ $set : { 'recipients.$.responded' : true }
40
+ }
41
+ ) ;
42
+ } ) ;
32
43
33
44
res . send ( { } ) ;
34
45
} ) ;
You can’t perform that action at this time.
0 commit comments