11import { Hono } from "hono" ;
2+ import { JwtPayload } from "../types" ;
23import { z } from "zod" ;
34import { Bindings } from "../models/db" ;
45import * as NotificationService from "../services/NotificationService" ;
56
6- const notifications = new Hono < { Bindings : Bindings ; Variables : { jwtPayload : any } } > ( ) ;
7+ const notifications = new Hono < { Bindings : Bindings ; Variables : { jwtPayload : JwtPayload } } > ( ) ;
78
89// 获取通知配置
910notifications . get ( "/" , async ( c ) => {
1011 try {
11- const userId = c . get ( "jwtPayload" ) . id ;
12+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ;
1213 const config = await NotificationService . getNotificationConfig ( userId ) ;
1314
1415 return c . json ( {
@@ -31,7 +32,7 @@ notifications.get("/", async (c) => {
3132// 获取通知渠道列表
3233notifications . get ( "/channels" , async ( c ) => {
3334 try {
34- const userId = c . get ( "jwtPayload" ) . id ;
35+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ;
3536 const channels = await NotificationService . getNotificationChannels ( userId ) ;
3637
3738 return c . json ( {
@@ -55,7 +56,7 @@ notifications.get("/channels", async (c) => {
5556notifications . get ( "/channels/:id" , async ( c ) => {
5657 try {
5758 const id = parseInt ( c . req . param ( "id" ) ) ;
58- const userId = c . get ( "jwtPayload" ) . id ;
59+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ;
5960
6061 if ( isNaN ( id ) ) {
6162 return c . json (
@@ -99,7 +100,7 @@ notifications.get("/channels/:id", async (c) => {
99100// 创建通知渠道
100101notifications . post ( "/channels" , async ( c ) => {
101102 try {
102- const userId = c . get ( "jwtPayload" ) . id ;
103+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ;
103104 const body = await c . req . json ( ) ;
104105
105106 // 验证请求数据
@@ -160,7 +161,7 @@ notifications.post("/channels", async (c) => {
160161notifications . put ( "/channels/:id" , async ( c ) => {
161162 try {
162163 const id = parseInt ( c . req . param ( "id" ) ) ;
163- const userId = c . get ( "jwtPayload" ) . id ;
164+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ;
164165
165166 if ( isNaN ( id ) ) {
166167 return c . json (
@@ -225,7 +226,7 @@ notifications.put("/channels/:id", async (c) => {
225226notifications . delete ( "/channels/:id" , async ( c ) => {
226227 try {
227228 const id = parseInt ( c . req . param ( "id" ) ) ;
228- const userId = c . get ( "jwtPayload" ) . id ;
229+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ;
229230
230231 if ( isNaN ( id ) ) {
231232 return c . json (
@@ -270,7 +271,7 @@ notifications.delete("/channels/:id", async (c) => {
270271// 获取通知模板列表
271272notifications . get ( "/templates" , async ( c ) => {
272273 try {
273- const userId = c . get ( "jwtPayload" ) . id ;
274+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ;
274275 const templates = await NotificationService . getNotificationTemplates ( userId ) ;
275276
276277 return c . json ( {
@@ -294,7 +295,7 @@ notifications.get("/templates", async (c) => {
294295notifications . get ( "/templates/:id" , async ( c ) => {
295296 try {
296297 const id = parseInt ( c . req . param ( "id" ) ) ;
297- const userId = c . get ( "jwtPayload" ) . id ; // 获取 userId
298+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ; // 获取 userId
298299
299300 if ( isNaN ( id ) ) {
300301 return c . json (
@@ -338,7 +339,7 @@ notifications.get("/templates/:id", async (c) => {
338339// 创建通知模板
339340notifications . post ( "/templates" , async ( c ) => {
340341 try {
341- const userId = c . get ( "jwtPayload" ) . id ;
342+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ;
342343 const body = await c . req . json ( ) ;
343344
344345 // 验证请求数据
@@ -402,7 +403,7 @@ notifications.post("/templates", async (c) => {
402403notifications . put ( "/templates/:id" , async ( c ) => {
403404 try {
404405 const id = parseInt ( c . req . param ( "id" ) ) ;
405- const userId = c . get ( "jwtPayload" ) . id ; // 获取 userId
406+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ; // 获取 userId
406407
407408 if ( isNaN ( id ) ) {
408409 return c . json (
@@ -465,7 +466,7 @@ notifications.put("/templates/:id", async (c) => {
465466notifications . delete ( "/templates/:id" , async ( c ) => {
466467 try {
467468 const id = parseInt ( c . req . param ( "id" ) ) ;
468- const userId = c . get ( "jwtPayload" ) . id ; // 获取 userId
469+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ; // 获取 userId
469470
470471 if ( isNaN ( id ) ) {
471472 return c . json (
@@ -510,7 +511,7 @@ notifications.delete("/templates/:id", async (c) => {
510511// 保存通知设置
511512notifications . post ( "/settings" , async ( c ) => {
512513 try {
513- const userId = c . get ( "jwtPayload" ) . id ;
514+ const userId = ( c . get ( "jwtPayload" ) as JwtPayload ) . id ;
514515 const body = await c . req . json ( ) ;
515516
516517 const schema = z . object ( {
0 commit comments