Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 929ae69

Browse files
committedFeb 15, 2021
fix: email Kafka Event Payload
- use "data" propery - use "handle" of user who performs action
1 parent 941e694 commit 929ae69

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
 

‎src/controllers/TeamController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function getTeamJob (req, res) {
4040
* @param res the response
4141
*/
4242
async function sendEmail (req, res) {
43-
await service.sendEmail(req.body)
43+
await service.sendEmail(req.authUser, req.body)
4444
res.status(HttpStatus.NO_CONTENT).end()
4545
}
4646

‎src/services/TeamService.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,26 @@ getTeamJob.schema = Joi.object().keys({
310310

311311
/**
312312
* Send email through a particular template
313+
* @param {Object} currentUser the user who perform this operation
313314
* @param {Object} data the email object
314315
* @returns {undefined}
315316
*/
316-
async function sendEmail (data) {
317+
async function sendEmail (currentUser, data) {
317318
const template = emailTemplates[data.template]
318319
await helper.postEvent(config.EMAIL_TOPIC, {
319-
subject: template.subjectTemplate(data.data),
320-
handle: data.data.userHandle,
321-
message: template.messageTemplate(data.data),
320+
data: {
321+
handle: currentUser.handle,
322+
subject: template.subjectTemplate(data.data),
323+
message: template.messageTemplate(data.data),
324+
},
322325
sendgrid_template_id: template.sendgridTemplateId,
323326
version: 'v3',
324327
recipients: template.recipients
325328
})
326329
}
327330

328331
sendEmail.schema = Joi.object().keys({
332+
currentUser: Joi.object().required(),
329333
data: Joi.object().keys({
330334
template: Joi.string().valid(...Object.keys(emailTemplates)).required(),
331335
data: Joi.object().required()

0 commit comments

Comments
 (0)
Please sign in to comment.