daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require('dotenv').config();
  2.  
  3. const db_creds = {
  4.   host            : process.env.MYSQL_HOST || '',
  5.   user            : process.env.MYSQL_USER || '',
  6.   password        : process.env.MYSQL_PASSWORD || '',
  7.   dateStrings     : true,
  8. }
  9.  
  10. const mysql = require('mysql2');
  11.  
  12. module.exports = {
  13.   /**
  14.    *  Send email
  15.    *
  16.    *  @return email object
  17.   **/
  18.   "sendEmail": async function(req, res, next, notification) {
  19.     try {
  20.       var db = await mysql.createConnection(db_creds);
  21.  
  22.       // Save email to database
  23.       const createEmail = `INSERT INTO system.notification
  24.         (to_user_id, email, template, template_data, type, created, created_by)
  25.         VALUES (?, ?, ?, ?, ?, NOW(), ?);`;
  26.  
  27.       const emailValues = [
  28.         notification.to_user_id,
  29.         notification.email,
  30.         templateData,
  31.         notification.template,
  32.         notification.type,
  33.         notification.createdBy
  34.       ];
  35.  
  36.       const result = await db.execute(createEmail, emailValues);
  37.  
  38.       console.log(result.insertId); // Returns 0
  39.  
  40.       // TODO: send email after successful save...
  41.  
  42.       return result;
  43.      
  44.     } catch (err) {
  45.       console.error(err.stack);
  46.     }
  47.   }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top