File tree Expand file tree Collapse file tree 1 file changed +14
-13
lines changed
Expand file tree Collapse file tree 1 file changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -15,19 +15,20 @@ module.exports = app => {
1515 } ) ;
1616
1717 app . post ( '/api/surveys/webhooks' , ( req , res ) => {
18- const events = _ . map ( req . body , ( { email, url } ) => {
19- const pathname = new URL ( url ) . pathname ;
20- const p = new Path ( '/api/surveys/:surveyId/:choice' ) ;
21- const match = p . test ( pathname ) ;
22- if ( match ) {
23- return { email, surveyId : match . surveyId , choice : match . choice } ;
24- }
25- } ) ;
26-
27- const compactEvents = _ . compact ( events ) ;
28- const uniqueEvents = _ . uniqBy ( compactEvents , 'email' , 'surveyId' ) ;
29-
30- console . log ( uniqueEvents ) ;
18+ const p = new Path ( '/api/surveys/:surveyId/:choice' ) ;
19+
20+ const events = _ . chain ( req . body )
21+ . map ( ( { email, url } ) => {
22+ const match = p . test ( new URL ( url ) . pathname ) ;
23+ if ( match ) {
24+ return { email, surveyId : match . surveyId , choice : match . choice } ;
25+ }
26+ } )
27+ . compact ( )
28+ . uniqBy ( 'email' , 'surveyId' )
29+ . value ( ) ;
30+
31+ console . log ( events ) ;
3132
3233 res . send ( { } ) ;
3334 } ) ;
You can’t perform that action at this time.
0 commit comments