Skip to content

Commit dcf011b

Browse files
committed
lodash chain
1 parent 697c11e commit dcf011b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

server/routes/surveyRoutes.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)