26 lines
849 B
JavaScript
26 lines
849 B
JavaScript
const { mongoose } = require('../db-connection');
|
|
const { escapeHtml } = require('../utils');
|
|
|
|
/**
|
|
* Returns { text, html } for a staff member's signature.
|
|
* Returns { text: '', html: '' } if no signature is set.
|
|
*/
|
|
async function getStaffSignatureBlocks(userId) {
|
|
const StaffSignature = mongoose.model('StaffSignature');
|
|
const sig = await StaffSignature.findOne({ userId }).lean();
|
|
if (!sig || (!sig.valediction && !sig.displayName && !sig.tagline)) {
|
|
return { text: '', html: '' };
|
|
}
|
|
|
|
const lines = [];
|
|
if (sig.valediction) lines.push(sig.valediction);
|
|
if (sig.displayName) lines.push(sig.displayName);
|
|
if (sig.tagline) lines.push(sig.tagline);
|
|
|
|
const text = lines.join('\n');
|
|
const html = lines.map(l => `<div>${escapeHtml(l)}</div>`).join('');
|
|
|
|
return { text, html };
|
|
}
|
|
|
|
module.exports = { getStaffSignatureBlocks }; |