Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a358c12

Browse files
committed
add query
1 parent 6167279 commit a358c12

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

server/routes/surveyRoutes.js

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

0 commit comments

Comments
 (0)