fix: get notification template failed

This commit is contained in:
zaunist committed 2025-11-06 01:31:37 +08:00
1 parent a6a9976852
commit 5fbb84bfe9
7 files changed
+4008 -51

No files matched your search

File diff suppressed because it is too large. Load diff
+2 -2
View File
@@ -33,8 +33,8 @@
{
"idx": 4,
"version": "6",
"when": 1751016668000,
"tag": "0004_lame_mercenary",
"when": 1762361284317,
"tag": "0004_many_avengers",
"breakpoints": true
}
]
+1 -1
View File
@@ -228,7 +228,7 @@ CREATE INDEX IF NOT EXISTS \`monitor_status_history_24h_monitor_timestamp_idx\`
sql: `CREATE INDEX IF NOT EXISTS \`monitor_status_history_24h_timestamp_idx\` ON \`monitor_status_history_24h\` (\`timestamp\`);`
},
{
name: "0004_lame_mercenary.sql",
name: "0004_many_avengers.sql",
sql: `CREATE TABLE IF NOT EXISTS \`settings\` (
\`key\` text PRIMARY KEY NOT NULL,
\`value\` text
+27 -7
View File
@@ -182,15 +182,35 @@ export const updateNotificationTemplate = async (
Omit<NotificationTemplate, "id" | "created_at" | "updated_at">
>
): Promise<boolean> => {
const updateData: Partial<typeof notificationTemplates.$inferInsert> = {};
if (template.name !== undefined) {
updateData.name = template.name;
}
if (template.type !== undefined) {
updateData.type = template.type;
}
if (template.subject !== undefined) {
updateData.subject = template.subject;
}
if (template.content !== undefined) {
updateData.content = template.content;
}
if (template.is_default !== undefined) {
updateData.is_default = template.is_default ? 1 : 0;
}
if (Object.keys(updateData).length === 0) {
return true; // 没有需要更新的字段时视为成功
}
const result = await db
.update(notificationTemplates)
.set({
name: template.name,
type: template.type,
subject: template.subject,
content: template.content,
is_default: template.is_default ? 1 : 0,
})
.set(updateData)
.where(and(eq(notificationTemplates.id, id), eq(notificationTemplates.created_by, userId)));
return result.success; // fix: 返回 success 布尔值
+12 -2
View File
@@ -677,15 +677,25 @@ export async function sendNotification(
const templates = await repositories.getNotificationTemplates(userId);
console.log(`[发送通知] 获取到${templates.length}个通知模板`);
const defaultTemplate = templates.find(
let defaultTemplate = templates.find(
(t) => t.is_default && t.type === type
);
if (!defaultTemplate) {
console.error(`[发送通知] 找不到类型为${type}的默认通知模板`);
const fallbackTemplate = templates.find((t) => t.type === type);
if (!fallbackTemplate) {
console.error(`[发送通知] 找不到类型为${type}的任何通知模板`);
return { success: false, results: [] };
}
console.warn(
`[发送通知] 找不到类型为${type}的默认通知模板,使用ID=${fallbackTemplate.id}作为回退模板`
);
defaultTemplate = fallbackTemplate;
}
console.log(
`[发送通知] 使用模板ID=${defaultTemplate.id},名称=${defaultTemplate.name}`
);
+2621 -39
View File
File diff suppressed because it is too large. Load diff