Templating for names and surnames

This commit is contained in:
Roman Krček
2025-07-12 22:01:05 +02:00
parent 308e70941f
commit a8f1b973e6
3 changed files with 52 additions and 9 deletions

View File

@@ -16,6 +16,16 @@ interface EmailResult {
error?: string;
}
/**
* Replaces template variables in a string with participant data
* Currently supports {name} and {surname} placeholders
*/
function replaceTemplateVariables(template: string, participant: Participant): string {
return template
.replace(/{name}/gi, participant.name || '')
.replace(/{surname}/gi, participant.surname || '');
}
async function generateQRCode(participantId: string): Promise<string> {
const qrCodeBase64 = await QRCode.toDataURL(participantId, {
type: 'image/png',
@@ -38,11 +48,15 @@ async function sendEmailToParticipant(
try {
const qrCodeBase64Data = await generateQRCode(participant.id);
// Replace template variables in subject and body
const personalizedSubject = replaceTemplateVariables(subject, participant);
const personalizedText = replaceTemplateVariables(text, participant);
// Send email with QR code
await sendGmail(refreshToken, {
to: participant.email,
subject: subject,
text: text,
subject: personalizedSubject,
text: personalizedText,
qr_code: qrCodeBase64Data
});