@@ -2,9 +2,9 @@ import * as models from "../models";
22import * as repositories from "../repositories" ;
33
44// 通知渠道相关服务
5- export async function getNotificationChannels ( userId : number ) : Promise <
6- models . NotificationChannel [ ]
7- > {
5+ export async function getNotificationChannels (
6+ userId : number
7+ ) : Promise < models . NotificationChannel [ ] > {
88 return await repositories . getNotificationChannels ( userId ) ;
99}
1010
@@ -39,7 +39,11 @@ export async function updateNotificationChannel(
3939 >
4040) : Promise < { success : boolean ; message ?: string } > {
4141 try {
42- const result = await repositories . updateNotificationChannel ( id , userId , channel ) ;
42+ const result = await repositories . updateNotificationChannel (
43+ id ,
44+ userId ,
45+ channel
46+ ) ;
4347 return {
4448 success : result ,
4549 message : result ? "通知渠道更新成功" : "通知渠道不存在或未做任何更改" ,
@@ -55,7 +59,7 @@ export async function updateNotificationChannel(
5559
5660export async function deleteNotificationChannel (
5761 id : number ,
58- userId : number ,
62+ userId : number
5963) : Promise < { success : boolean ; message ?: string } > {
6064 try {
6165 const result = await repositories . deleteNotificationChannel ( id , userId ) ;
@@ -76,15 +80,15 @@ export async function deleteNotificationChannel(
7680}
7781
7882// 通知模板相关服务
79- export async function getNotificationTemplates ( userId : number ) : Promise <
80- models . NotificationTemplate [ ]
81- > {
83+ export async function getNotificationTemplates (
84+ userId : number
85+ ) : Promise < models . NotificationTemplate [ ] > {
8286 return await repositories . getNotificationTemplates ( userId ) ;
8387}
8488
8589export async function getNotificationTemplateById (
8690 id : number ,
87- userId : number ,
91+ userId : number
8892) : Promise < models . NotificationTemplate | null > {
8993 return await repositories . getNotificationTemplateById ( id , userId ) ;
9094}
@@ -115,7 +119,11 @@ export async function updateNotificationTemplate(
115119 >
116120) : Promise < { success : boolean ; message ?: string } > {
117121 try {
118- const result = await repositories . updateNotificationTemplate ( id , userId , template ) ;
122+ const result = await repositories . updateNotificationTemplate (
123+ id ,
124+ userId ,
125+ template
126+ ) ;
119127 return {
120128 success : result ,
121129 message : result ? "通知模板更新成功" : "通知模板不存在或未做任何更改" ,
@@ -131,7 +139,7 @@ export async function updateNotificationTemplate(
131139
132140export async function deleteNotificationTemplate (
133141 id : number ,
134- userId : number ,
142+ userId : number
135143) : Promise < { success : boolean ; message ?: string } > {
136144 try {
137145 const result = await repositories . deleteNotificationTemplate ( id , userId ) ;
@@ -149,7 +157,9 @@ export async function deleteNotificationTemplate(
149157}
150158
151159// 通知设置相关服务,获取所有的通知设置
152- export async function getNotificationConfig ( userId : number ) : Promise < models . NotificationConfig > {
160+ export async function getNotificationConfig (
161+ userId : number
162+ ) : Promise < models . NotificationConfig > {
153163 return await repositories . getNotificationConfig ( userId ) ;
154164}
155165
@@ -218,8 +228,6 @@ interface WeComConfig {
218228 webhookUrl : string ;
219229}
220230
221-
222-
223231/**
224232 * 解析通知渠道配置
225233 */
@@ -277,7 +285,6 @@ function parseChannelConfig<T>(channel: models.NotificationChannel): T {
277285 }
278286}
279287
280-
281288// =================================================================
282289// Section: 各渠道发送器实现 (Sender Implementations)
283290// =================================================================
@@ -470,7 +477,7 @@ interface NotificationSender {
470477/**
471478 * 发送器注册表。
472479 * 这是一个从渠道类型字符串到其发送器实现的映射。
473- * "Talk is cheap. Show me the code."
480+ * "Talk is cheap. Show me the code."
474481 * 这段代码取代了原来愚蠢的 if-else 链。
475482 */
476483const senderRegistry : Record < string , NotificationSender > = { } ;
@@ -488,7 +495,6 @@ function registerSender(type: string, sender: NotificationSender) {
488495 console . log ( `[通知注册] 成功注册发送器: ${ type } ` ) ;
489496}
490497
491-
492498/**
493499 * 根据渠道类型发送通知 (重构后)
494500 * 这个函数现在只负责查找和调用,不再关心具体实现。
@@ -518,8 +524,6 @@ async function sendNotificationByChannel(
518524 }
519525}
520526
521-
522-
523527/**
524528 * 发送飞书通知
525529 */
@@ -557,7 +561,7 @@ async function sendFeishuNotification(
557561 ] ,
558562 } ,
559563 } ;
560-
564+
561565 console . log ( "[飞书通知] 准备发送通知到:" , webhookUrl ) ;
562566 const response = await fetch ( webhookUrl , {
563567 method : "POST" ,
@@ -707,7 +711,9 @@ export async function sendNotification(
707711 // 获取所有通知渠道
708712 console . log ( `[发送通知] 开始获取${ channelIds . length } 个通知渠道的详细信息` ) ;
709713 const channels = await Promise . all (
710- channelIds . map ( ( id ) => repositories . getNotificationChannelById ( id , userId ) )
714+ channelIds . map ( ( id ) =>
715+ repositories . getNotificationChannelById ( id , userId )
716+ )
711717 ) ;
712718
713719 // 过滤掉不存在的渠道
@@ -853,7 +859,11 @@ export async function shouldSendNotification(
853859 }
854860
855861 // 获取此对象的特定设置
856- const specificSettings = await repositories . getSpecificSettings ( userId , type , id ) ;
862+ const specificSettings = await repositories . getSpecificSettings (
863+ userId ,
864+ type ,
865+ id
866+ ) ;
857867
858868 console . log (
859869 `[通知触发检查] 获取到特定设置数量: ${
@@ -993,7 +1003,9 @@ export async function deleteNotificationSettings(
9931003 userId : number
9941004) : Promise < { success : boolean ; message ?: string } > {
9951005 try {
996- console . log ( `[删除通知设置] 开始删除${ type } 通知设置,ID=${ id } ,用户ID=${ userId } ` ) ;
1006+ console . log (
1007+ `[删除通知设置] 开始删除${ type } 通知设置,ID=${ id } ,用户ID=${ userId } `
1008+ ) ;
9971009 // 执行删除操作
9981010 await repositories . deleteNotificationSettings ( type , id , userId ) ;
9991011 } catch ( error ) {
@@ -1013,7 +1025,9 @@ export async function deleteNotificationSettings(
10131025 * 为新用户创建默认的通知设置
10141026 * @param userId 新用户的ID
10151027 */
1016- export async function createDefaultNotificationSettingsForUser ( userId : number ) : Promise < void > {
1028+ export async function createDefaultNotificationSettingsForUser (
1029+ userId : number
1030+ ) : Promise < void > {
10171031 try {
10181032 console . log ( `为新用户 ${ userId } 创建默认通知设置...` ) ;
10191033 const now = new Date ( ) . toISOString ( ) ;
@@ -1041,10 +1055,10 @@ export async function createDefaultNotificationSettingsForUser(userId: number):
10411055
10421056 // 创建默认通知渠道
10431057 const defaultChannelId = await repositories . createNotificationChannel ( {
1044- name : "默认Telegram通知渠道 " ,
1058+ name : "TG测试Bot(仅提供了Token,请自行填写ChatID或者使用你的Bot) " ,
10451059 type : "telegram" ,
10461060 config :
1047- '{"botToken": "8163201319:AAGyY7FtdaRb6o8NCVXSbBUb6ofDK45cNJU ", "chatId": "-1002608818360 "}' ,
1061+ '{"botToken": "8538953065:AAG51lJ31MNLWe3na5wai4SBRiZ8T-sOC3c ", "chatId": "111111111 "}' ,
10481062 enabled : true ,
10491063 created_by : userId ,
10501064 } ) ;
@@ -1089,4 +1103,4 @@ export async function createDefaultNotificationSettingsForUser(userId: number):
10891103 console . error ( `为新用户 ${ userId } 创建默认通知设置失败:` , error ) ;
10901104 // 此处不向上抛出异常,以免影响用户创建的主流程
10911105 }
1092- }
1106+ }
0 commit comments