hubxglpi/src/modules/comments/models/glpiComment.model.js

43 lines
983 B
JavaScript

//src/modules/comments/models/glpiComment.model.js
function escapeHtml(text = '') {
return text
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
}
function buildHtml({ author, message, source }) {
const safeAuthor = escapeHtml(author || 'Sistema')
const safeMessage = escapeHtml(message || '')
.replace(/\n/g, '<br>')
return `
<div style="font-family: Arial, sans-serif; font-size: 13px;">
<div style="margin-bottom: 4px; color: #555;">
<strong>${safeAuthor}</strong>
<span style="color:#999;">(${source})</span>
</div>
<div style="padding-left: 6px;">
${safeMessage}
</div>
</div>
`.trim()
}
function mapMessageToGlpiComment(glpiTicketId, msg) {
return {
ticketId: glpiTicketId,
content: buildHtml({
author: msg.usuario_nome,
message: msg.mensagem,
source: 'Hubsoft'
})
}
}
module.exports = {
mapMessageToGlpiComment
}