120 lines
3.2 KiB
Markdown
120 lines
3.2 KiB
Markdown
# Email Template Models
|
|
|
|
## Overview
|
|
|
|
The Email Template module provides a reusable template system with Handlebars-style variable interpolation, version history, and test email functionality.
|
|
|
|
**Models (4):**
|
|
- EmailTemplate — Template master with categories
|
|
- EmailTemplateVariable — Variable definitions
|
|
- EmailTemplateVersion — Version history
|
|
- EmailTemplateTestLog — Test email audit
|
|
|
|
**Key Features:**
|
|
- Handlebars-style {{VAR}} interpolation
|
|
- 3 categories: INFLUENCE, MAP, SYSTEM
|
|
- System template protection (isSystem flag prevents deletion)
|
|
- Version history with auto-increment version numbers
|
|
- Conditional variables for {{#if}} blocks
|
|
- Test email sending with sample data
|
|
- HTML + plain text content
|
|
|
|
See [Schema Reference](../schema.md#email-templates) for complete field listings.
|
|
|
|
---
|
|
|
|
## Template Categories
|
|
|
|
```prisma
|
|
enum EmailTemplateCategory {
|
|
INFLUENCE // Campaign emails, response verification
|
|
MAP // Shift confirmations, reminders
|
|
SYSTEM // Password resets, welcome emails
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Variable Interpolation
|
|
|
|
**Syntax:** Handlebars-style `{{VARIABLE_NAME}}`
|
|
|
|
**Example Template:**
|
|
```html
|
|
<p>Hello {{USER_NAME}},</p>
|
|
<p>Thank you for signing up for the shift:</p>
|
|
<ul>
|
|
<li>Title: {{SHIFT_TITLE}}</li>
|
|
<li>Date: {{SHIFT_DATE}}</li>
|
|
<li>Time: {{SHIFT_TIME}}</li>
|
|
</ul>
|
|
{{#if IS_NEW_USER}}
|
|
<p>Your temporary password is: {{TEMP_PASSWORD}}</p>
|
|
{{/if}}
|
|
```
|
|
|
|
**Variable Record:**
|
|
```typescript
|
|
{
|
|
key: 'USER_NAME',
|
|
label: 'User Name',
|
|
description: 'Name of the volunteer',
|
|
isRequired: true,
|
|
isConditional: false,
|
|
sampleValue: 'Jane Doe',
|
|
sortOrder: 0,
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Version History
|
|
|
|
**Auto-Increment Version Numbers:**
|
|
```typescript
|
|
const latestVersion = await prisma.emailTemplateVersion.findFirst({
|
|
where: { templateId },
|
|
orderBy: { versionNumber: 'desc' },
|
|
});
|
|
|
|
const newVersion = await prisma.emailTemplateVersion.create({
|
|
data: {
|
|
templateId,
|
|
versionNumber: (latestVersion?.versionNumber || 0) + 1,
|
|
subjectLine,
|
|
htmlContent,
|
|
textContent,
|
|
changeNotes: 'Updated call-to-action wording',
|
|
createdByUserId: user.id,
|
|
},
|
|
});
|
|
```
|
|
|
|
---
|
|
|
|
## System Templates (4 seeded)
|
|
|
|
**1. campaign-email** (INFLUENCE)
|
|
- Variables: CAMPAIGN_TITLE, MESSAGE, USER_NAME, USER_EMAIL, POSTAL_CODE, RECIPIENT_NAME, RECIPIENT_LEVEL, ORGANIZATION_NAME, TIMESTAMP
|
|
- Used by: Campaign email sending
|
|
|
|
**2. response-verification** (INFLUENCE)
|
|
- Variables: CAMPAIGN_TITLE, RESPONSE_TYPE, RESPONSE_TEXT, SUBMITTER_NAME, SUBMITTED_DATE, VERIFICATION_URL, REPORT_URL, ORGANIZATION_NAME, TIMESTAMP
|
|
- Used by: Response wall submission verification
|
|
|
|
**3. shift-signup-confirmation** (MAP)
|
|
- Variables: ORGANIZATION_NAME, USER_NAME, USER_EMAIL, SHIFT_TITLE, SHIFT_DATE, SHIFT_TIME, SHIFT_LOCATION, IS_NEW_USER, TEMP_PASSWORD, LOGIN_URL
|
|
- Used by: Public shift signup
|
|
|
|
**4. shift-details** (MAP)
|
|
- Variables: ORGANIZATION_NAME, USER_NAME, SHIFT_TITLE, SHIFT_DATE, SHIFT_START_TIME, SHIFT_END_TIME, SHIFT_LOCATION, SHIFT_DESCRIPTION, CURRENT_VOLUNTEERS, MAX_VOLUNTEERS, SHIFT_STATUS
|
|
- Used by: Shift reminder emails
|
|
|
|
---
|
|
|
|
## Related Documentation
|
|
|
|
- [Schema Reference](../schema.md#email-templates) — Complete field listings
|
|
- [Seeding](../seeding.md) — Default templates
|
|
- [API Email Template Routes](../../api/email-templates.md) — REST endpoints
|