fixing email template

This commit is contained in:
Arjun Patel
2019-04-22 02:58:17 -07:00
parent 0ec8bb7468
commit 1f16e88fc6
2 changed files with 26 additions and 6 deletions
+15 -1
View File
@@ -6,6 +6,7 @@ const sendgrid = require('./sendgrid.controller');
const {
Grant,
Donor,
Charge,
Cause,
Region,
@@ -82,11 +83,24 @@ exports.createGrant = async (req, res, next) => {
{ transaction }
);
const donors = await sequelize.query(
`
SELECT email, first_name, last_name
FROM donors
WHERE id = :donor_id
`,
{
type: db.Sequelize.QueryTypes.SELECT,
replacements: { donor_id: user.id }
}
);
// send email
await sendgrid.paymentReceipt({
grant,
organizations,
total_amount: actual_total,
receiver: user.email
receiver: donors[0]
});
// commit
+11 -5
View File
@@ -6,7 +6,12 @@ sgMail.setApiKey(process.env.SENDGRID_KEY);
const {} = db;
exports.paymentReceipt = async ({ organizations, total_amount, receiver }) => {
exports.paymentReceipt = async ({
grant,
organizations,
total_amount,
receiver
}) => {
try {
var charitiesHtml = '';
@@ -22,17 +27,18 @@ exports.paymentReceipt = async ({ organizations, total_amount, receiver }) => {
});
const msg = {
to: receiver,
to: receiver.email,
from: { email: 'no-reply@charify.com', name: 'Charify Payments' },
template_id: 'd-569f804f5e7749cba66bac1994607280',
substitutionWrappers: ['{{', '}}'],
dynamic_template_data: {
donor_name: 'Arjun Patel',
donor_name: receiver.first_name,
bundle_id: grant.id,
charities_list: charitiesHtml,
total_amount,
date: 'April 1st, 2018',
subject: 'Your Charity Bundle Payment - Charify'
date: grant.created_at,
subject: 'Your Charify Bundle Payment - Charify'
}
};
const sentRes = await sgMail.send(msg);