Skip to content

Commit a7f6164

Browse files
committed
notifying ticket creator on new coment
1 parent 8f3e369 commit a7f6164

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

app/controllers/ticket.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ module.exports = {
177177
userId,
178178
postId: id
179179
})
180+
notification.heading = 'New Comment on Ticket!'
181+
notification.content = `${req.user.name.firstName} ${req.user.name.lastName} commented on your Ticket!`
182+
notification.tag = TAGS.NEW
183+
await ticketNotificationHelper.addToNotificationForUser(ticket.createdBy, res, notification, next)
180184
await ticket.save()
181185
res.status(HttpStatus.OK).json({ ticket: ticket })
182186
} catch (error) {

app/utils/ticket-notif-helper.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,15 @@ module.exports = {
99
} catch (error) {
1010
console.log(error)
1111
}
12+
},
13+
addToNotificationForUser: async (userId, res, obj, next) => {
14+
try {
15+
console.log('adding to user\'s notifications')
16+
const user = await User.findById(userId)
17+
user.ticketNotifications.unshift(obj)
18+
await user.save()
19+
} catch (error) {
20+
console.log(error)
21+
}
1222
}
1323
}

0 commit comments

Comments
 (0)