We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f4c66f5 commit 5bac251Copy full SHA for 5bac251
1 file changed
server/routes/surveyRoutes.js
@@ -17,7 +17,7 @@ module.exports = app => {
17
app.post('/api/surveys/webhooks', (req, res) => {
18
const p = new Path('/api/surveys/:surveyId/:choice');
19
20
- const events = _.chain(req.body)
+ _.chain(req.body)
21
.map(({ email, url }) => {
22
const match = p.test(new URL(url).pathname);
23
if (match) {
@@ -26,9 +26,20 @@ module.exports = app => {
26
})
27
.compact()
28
.uniqBy('email', 'surveyId')
29
- .value();
30
-
31
- console.log(events);
+ .each(({ email, choice, surveyId }) => {
+ Survey.updateOne(
+ {
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
+ });
43
44
res.send({});
45
});
0 commit comments