Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('dotenv').config();
- const db_creds = {
- host : process.env.MYSQL_HOST || '',
- user : process.env.MYSQL_USER || '',
- password : process.env.MYSQL_PASSWORD || '',
- dateStrings : true,
- }
- const mysql = require('mysql2');
- module.exports = {
- /**
- * Send email
- *
- * @return email object
- **/
- "sendEmail": async function(req, res, next, notification) {
- try {
- var db = await mysql.createConnection(db_creds);
- // Save email to database
- const createEmail = `INSERT INTO system.notification
- (to_user_id, email, template, template_data, type, created, created_by)
- VALUES (?, ?, ?, ?, ?, NOW(), ?);`;
- const emailValues = [
- notification.to_user_id,
- notification.email,
- templateData,
- notification.template,
- notification.type,
- notification.createdBy
- ];
- const result = await db.execute(createEmail, emailValues);
- console.log(result.insertId); // Returns 0
- // TODO: send email after successful save...
- return result;
- } catch (err) {
- console.error(err.stack);
- }
- }
- }
Add Comment
Please, Sign In to add comment