var path = require('path'); var database = require(path.join(__dirname, '../../database.js')); var format = require(path.join(__dirname, '../../util/format.js')); module.exports = class ClientWelcome { getData(params, cb) { let query = `SELECT CONCAT(w.name, ' ', w.firstName) name, w.phone AS phone, CONCAT(wu.name, '@verdnatura.es') AS email, u.name AS userName, LOWER(ct.code) countryCode, c.email recipient FROM client c JOIN account.user u ON u.id = c.id LEFT JOIN worker w ON w.id = c.workerFk LEFT JOIN account.user wu ON wu.id = w.userFk JOIN country ct ON ct.id = c.countryFk WHERE c.id = ?`; database.pool.query(query, [params.recipient], (error, result) => { if (error || result.length == 0) return cb(new Error('No template data found')); Object.assign(this, result[0]); cb(); }); } get salesPersonName() { if (this.name) return `
${this._.salesPersonNameText}: ${this.name}
`; } get salesPersonPhone() { if (this.phone) return `
${this._.salesPersonPhoneText}: ${format.phone(this.phone)}
`; } get salesPersonEmail() { if (this.email) return `
${this._.salesPersonEmailText}: ` + `${this.email}
`; } };