could not find the template to update.... create a beautofull template b
This commit is contained in:
@@ -30,7 +30,7 @@ export async function getEmailTemplate(): Promise<{ subject: string; body: strin
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the email template in the database.
|
||||
* Updates or creates the email template in the database.
|
||||
*/
|
||||
export async function updateEmailTemplate(data: { subject: string; body: string }): Promise<{ success: boolean; message: string }> {
|
||||
const validation = emailTemplateSchema.safeParse(data);
|
||||
@@ -42,12 +42,17 @@ export async function updateEmailTemplate(data: { subject: string; body: string
|
||||
const { subject, body } = validation.data;
|
||||
|
||||
try {
|
||||
const stmt = db.prepare('UPDATE email_templates SET subject = ?, body = ? WHERE id = ?');
|
||||
// We assume we're updating the template with id = 1
|
||||
const info = stmt.run(subject, body, 1);
|
||||
|
||||
if (info.changes === 0) {
|
||||
return { success: false, message: 'Could not find the template to update. No changes were made.' };
|
||||
const checkStmt = db.prepare('SELECT id FROM email_templates WHERE id = 1');
|
||||
const existing = checkStmt.get();
|
||||
|
||||
if (existing) {
|
||||
// Update existing template
|
||||
const stmt = db.prepare('UPDATE email_templates SET subject = ?, body = ? WHERE id = ?');
|
||||
stmt.run(subject, body, 1);
|
||||
} else {
|
||||
// Insert new template
|
||||
const stmt = db.prepare('INSERT INTO email_templates (id, subject, body) VALUES (?, ?, ?)');
|
||||
stmt.run(1, subject, body);
|
||||
}
|
||||
|
||||
revalidatePath('/admin/settings/email-templates');
|
||||
|
||||
Reference in New Issue
Block a user