Skip to content

Commit

Permalink
style(email) & feat: Added HTML email template & UUID dashes
Browse files Browse the repository at this point in the history
  • Loading branch information
alu0100966589 committed May 9, 2021
1 parent 450217d commit 9a86d3c
Show file tree
Hide file tree
Showing 4 changed files with 1,080 additions and 6 deletions.
22 changes: 16 additions & 6 deletions eventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const EEAClient = require('web3-eea')
const config = require('./config')
const mail = require('./mail-sender')
const { logger } = require("./utils/logger")
const { toUUID } = require("to-uuid");

const mailTemplate = fs
.readFileSync(path.join(__dirname, "templates", "mail.template"))
.toString();

const chainId = 1337
const web3 = new EEAClient(new Web3(config.besu.node.url), chainId)
Expand Down Expand Up @@ -95,15 +100,20 @@ function hex2a(hexx) {
* Envio de correos a la aseguradora con los datos del pago a realizar
*/
function sendEmailToInsurer(takerId, insuranceId) {
let link = "" //TODO: poner enlace a consulta de póliza de aplicación web
const parsedInsuranceId = toUUID(insuranceId);
const parsedTakerId = toUUID(takerId);

const htmlEmail = mailTemplate
.replace(/\<INSURANCEID\>/g, parsedInsuranceId)
.replace(/\<TAKERID\>/g, parsedTakerId);

// send email
mail.sendEmail(
config.EMAIL.insurerEmail,
'SPC19: Indemnización calculada por la blockchain',
`Hola,\nSe ha recibido un evento de la blockchain indicando que procede un pago con los siguientes datos.\n - Identificador de la póliza: ${insuranceId}\n - Identitifador del hotel: ${takerId}\nPuede acceder a los datos de la póliza usando el siguiente enlace: ${link}`,
`<p>Hola, <br><br>Se ha recibido un evento de la blockchain indicando que procede un pago con los siguientes datos:</p><p><ul><li>Identificador de la p&oacute;liza: ${insuranceId}</li><li>Identitifador del hotel: ${takerId}</li></ul></p><p>Puede acceder a los datos de la p&oacute;liza usando el siguiente enlace: ${link}</p>`
)
config.EMAIL.insurerEmail,
"SPC19: Indemnización calculada por la blockchain",
`Hola,\nSe ha recibido un evento de la blockchain indicando que procede un pago con los siguientes datos.\n - Identificador de la póliza: ${parsedInsuranceId}\n - Identitifador del hotel: ${parsedTakerId}`,
htmlEmail
);
}

async function manage(log) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"abi-decoder": "^2.4.0",
"nodemailer": "^4.6.8",
"pino": "^6.11.3",
"to-uuid": "^0.1.3",
"web3": "^1.2.6",
"web3-eea": "^0.10.0"
}
Expand Down
Loading

0 comments on commit 9a86d3c

Please sign in to comment.