Skip to content

Commit 813935b

Browse files
committed
Substitute the Subject and Body with values
1 parent ac8471e commit 813935b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/common/helper.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,22 @@ async function getUserByHandle (userHandle) {
13681368
return _.get(res, 'body')
13691369
}
13701370

1371+
/**
1372+
*
1373+
* @param {String} string that will be modifed
1374+
* @param {*} object of json that would be replaced in string
1375+
* @returns
1376+
*/
1377+
async function substituteStringByObject (string, object) {
1378+
for (var key in object) {
1379+
if (!object.hasOwnProperty(key)) {
1380+
continue;
1381+
}
1382+
string = string.replace(new RegExp("{{" + key + "}}", "g"), object[key]);
1383+
}
1384+
return string
1385+
}
1386+
13711387
module.exports = {
13721388
getParamFromCliArgs,
13731389
promptUser,
@@ -1417,5 +1433,6 @@ module.exports = {
14171433
updateChallenge,
14181434
createChallengeResource,
14191435
extractWorkPeriods,
1420-
getUserByHandle
1436+
getUserByHandle,
1437+
substituteStringByObject
14211438
}

src/services/TeamService.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ async function sendEmail (currentUser, data) {
325325
subject: data.subject || template.subject,
326326
body: data.body || template.body
327327
}
328+
for(var key in subjectBody) {
329+
subjectBody[key] = await helper.substituteStringByObject(subjectBody[key], data.data)
330+
}
328331
const emailData = {
329332
// override template if coming data already have the 'from' address
330333
from: data.from || template.from,

0 commit comments

Comments
 (0)