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 => {
1717 app . post ( '/api/surveys/webhooks' , ( req , res ) => {
1818 const p = new Path ( '/api/surveys/:surveyId/:choice' ) ;
1919
20- const events = _ . chain ( req . body )
20+ _ . chain ( req . body )
2121 . map ( ( { email, url } ) => {
2222 const match = p . test ( new URL ( url ) . pathname ) ;
2323 if ( match ) {
@@ -26,9 +26,20 @@ module.exports = app => {
2626 } )
2727 . compact ( )
2828 . 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+ } ) ;
3243
3344 res . send ( { } ) ;
3445 } ) ;
You can’t perform that action at this time.
0 commit comments