Skip to content

Commit

Permalink
Extend and prepare mail handling
Browse files Browse the repository at this point in the history
  • Loading branch information
GPlay97 committed Aug 15, 2020
1 parent 648332a commit 92a6819
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions controllers/mail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
const mailjet = require('node-mailjet').connect(process.env.MAILJET_API_KEY, process.env.MAILJET_API_SECRET);

const sendMail = (type, receiver, language, data) => {
const sendMail = (dataObj) => {
const receiver = dataObj.notifications.mail;
const templateId = getTemplateID(dataObj.type, dataObj.settings.language);

// TODO: validate email
if (!receiver) return;
if (!templateId) return;

mailjet
.post('send', {
version: 'v3.1'
Expand All @@ -15,8 +22,8 @@ const sendMail = (type, receiver, language, data) => {
Email: receiver
}],
TemplateLanguage: true,
TemplateID: getTemplateID(type, language),
Variables: data
TemplateID: templateID,
Variables: getDataForTemplateID(templateID, dataObj)
}]
}).then(() => {
// update last mail timestamp
Expand All @@ -26,6 +33,12 @@ const sendMail = (type, receiver, language, data) => {
};

const getTemplateID = (type, language) => {
const templateName = (type + '_' + language).toUpperCase();

return process.env['MAILJET_TEMPLATE_' + templateName];
};

const getDataForTemplateID = (templateID, dataObj) => {

};

Expand Down

0 comments on commit 92a6819

Please sign in to comment.