File tree Expand file tree Collapse file tree 1 file changed +41
-13
lines changed Expand file tree Collapse file tree 1 file changed +41
-13
lines changed Original file line number Diff line number Diff line change @@ -56,38 +56,66 @@ export default eventHandler(async (event) => {
56
56
} )
57
57
} )
58
58
}
59
- else {
60
- throw createError ( {
61
- statusCode : 400 ,
62
- message : '未知操作' ,
63
- } )
64
- }
65
59
}
66
60
}
67
61
else {
62
+ // Get the user's student ID first
63
+ const user = await prisma . user . findUnique ( {
64
+ where : {
65
+ clerkUserId : auth . userId ,
66
+ } ,
67
+ } )
68
+
69
+ if ( ! user ) {
70
+ throw createError ( {
71
+ statusCode : 404 ,
72
+ message : '用户不存在' ,
73
+ } )
74
+ }
75
+
76
+ // Find all clubs where user is president or vice president
77
+ const userClubs = await prisma . club . findMany ( {
78
+ where : {
79
+ OR : [
80
+ {
81
+ presidentByTsimsStudentId : user . tsimsStudentId ,
82
+ } ,
83
+ {
84
+ vicesByTsimsStudentId : {
85
+ has : user . tsimsStudentId ,
86
+ } ,
87
+ } ,
88
+ ] ,
89
+ } ,
90
+ } )
91
+
92
+ const clubIds = userClubs . map ( club => club . id )
93
+
68
94
const currentReservation = await prisma . reservationRecord . findUnique ( {
69
95
include : {
70
- user : true ,
96
+ club : true ,
71
97
} ,
72
98
where : {
73
99
id : query . id ,
74
100
} ,
75
101
} )
102
+
76
103
if ( ! currentReservation ) {
77
104
throw createError ( {
78
105
statusCode : 400 ,
79
106
message : '未找到记录' ,
80
107
} )
81
108
}
82
- else if ( currentReservation . user . clerkUserId !== auth . userId ) {
109
+
110
+ // Check if user has access to this club's reservations
111
+ if ( ! clubIds . includes ( currentReservation . clubId ) ) {
83
112
throw createError ( {
84
- statusCode : 400 ,
85
- message : '这不是你的记录 ' ,
113
+ statusCode : 403 ,
114
+ message : '您没有权限管理此预约记录 ' ,
86
115
} )
87
116
}
88
- else if ( query . action === 'DELETE' ) {
89
- if ( query . id === - 1 )
90
- return
117
+
118
+ if ( query . action === 'DELETE' ) {
91
119
return await prisma . reservationRecord . delete ( {
92
120
where : {
93
121
id : query . id ,
You can’t perform that action at this time.
0 commit comments