fix: get notification template failed
This commit is contained in:
1 parent
a6a9976852
commit
5fbb84bfe9
7 files changed
+4010
-53
No files matched your search
File renamed without changes.
File diff suppressed because it is too large.
Load diff
@@ -33,9 +33,9 @@
|
||||
{
|
||||
"idx": 4,
|
||||
"version": "6",
|
||||
"when": 1751016668000,
|
||||
"tag": "0004_lame_mercenary",
|
||||
"when": 1762361284317,
|
||||
"tag": "0004_many_avengers",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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 布尔值
|
||||
|
||||
@@ -677,13 +677,23 @@ 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}的默认通知模板`);
|
||||
return { success: false, results: [] };
|
||||
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(
|
||||
|
||||
Generated
+2621
-39
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user