Fix column names in send-notification and migration

Updated to use the correct database column names:
- email_subject (not subject)
- email_body_html (not body_html)

Changes:
- send-notification/index.ts: Added fallback to check both email_subject/subject
  and email_body_html/body_html for compatibility
- Migration: Updated to use correct column names (email_subject, email_body_html)

This matches the actual database schema shown in the notification_templates table.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
dwindown
2026-01-03 08:59:49 +07:00
parent 485263903f
commit 1fbaf4d360
2 changed files with 6 additions and 5 deletions

View File

@@ -265,8 +265,8 @@ serve(async (req: Request): Promise<Response> => {
} }
} }
const subject = replaceVariables(template.subject, allVariables); const subject = replaceVariables(template.email_subject || template.subject || "", allVariables);
const htmlContent = replaceVariables(template.body_html || template.body_text || "", allVariables); const htmlContent = replaceVariables(template.email_body_html || template.body_html || template.body_text || "", allVariables);
// Wrap with master template for consistent branding // Wrap with master template for consistent branding
const htmlBody = EmailTemplateRenderer.render({ const htmlBody = EmailTemplateRenderer.render({

View File

@@ -3,7 +3,8 @@
UPDATE notification_templates UPDATE notification_templates
SET SET
body_html = ' email_subject = 'Konfirmasi Pesanan - Order #{order_id}',
email_body_html = '
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px;"> <div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px;">
<h2 style="color: #333;">Konfirmasi Pesanan</h2> <h2 style="color: #333;">Konfirmasi Pesanan</h2>
@@ -78,9 +79,9 @@ WHERE key = 'order_created';
-- Verify the update -- Verify the update
SELECT SELECT
key, key,
subject, email_subject,
is_active, is_active,
LEFT(body_html, 100) as body_preview, LEFT(email_body_html, 100) as body_preview,
updated_at updated_at
FROM notification_templates FROM notification_templates
WHERE key = 'order_created'; WHERE key = 'order_created';