Skip to content

Commit 697c11e

Browse files
committed
uniqueness
1 parent 1f1d49a commit 697c11e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

server/routes/surveyRoutes.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ module.exports = app => {
1515
});
1616

1717
app.post('/api/surveys/webhooks', (req, res) => {
18-
const events = _.map(req.body, event => {
19-
const pathname = new URL(event.url).pathname;
18+
const events = _.map(req.body, ({ email, url }) => {
19+
const pathname = new URL(url).pathname;
2020
const p = new Path('/api/surveys/:surveyId/:choice');
21-
console.log(p.test(pathname));
21+
const match = p.test(pathname);
22+
if (match) {
23+
return { email, surveyId: match.surveyId, choice: match.choice };
24+
}
2225
});
26+
27+
const compactEvents = _.compact(events);
28+
const uniqueEvents = _.uniqBy(compactEvents, 'email', 'surveyId');
29+
30+
console.log(uniqueEvents);
31+
32+
res.send({});
2333
});
2434

2535
app.post('/api/surveys', requireLogin, requireCredits, async (req, res) => {

0 commit comments

Comments
 (0)