@@ -19,96 +19,114 @@ export async function POST(request: NextRequest, context: RouteContext) {
1919 return withPlatformAdmin ( async ( ) => {
2020 try {
2121 const { id } = await context . params
22- const body = await request . json ( )
23- const { action, reason } = body
22+ const body = await request . json ( )
23+ const { action, reason } = body
2424
25- if ( ! action || ! [ 'approve' , 'reject' ] . includes ( action ) ) {
26- return NextResponse . json (
27- { success : false , error : 'Invalid action' } ,
28- { status : 400 }
29- )
30- }
25+ if ( ! action || ! [ 'approve' , 'reject' , 'delete '] . includes ( action ) ) {
26+ return NextResponse . json (
27+ { success : false , error : 'Invalid action' } ,
28+ { status : 400 }
29+ )
30+ }
3131
32- if ( action === 'reject' && ! reason ) {
33- return NextResponse . json (
34- { success : false , error : 'Rejection reason is required' } ,
35- { status : 400 }
36- )
37- }
32+ if ( action === 'reject' && ! reason ) {
33+ return NextResponse . json (
34+ { success : false , error : 'Rejection reason is required' } ,
35+ { status : 400 }
36+ )
37+ }
3838
39- const supabase = await createClient ( )
40- const { data : { user } } = await supabase . auth . getUser ( )
39+ const supabase = await createClient ( )
40+ const { data : { user } } = await supabase . auth . getUser ( )
4141
42- if ( ! user ) {
43- return NextResponse . json (
44- { success : false , error : 'Unauthorized' } ,
45- { status : 401 }
46- )
47- }
42+ if ( ! user ) {
43+ return NextResponse . json (
44+ { success : false , error : 'Unauthorized' } ,
45+ { status : 401 }
46+ )
47+ }
4848
49- // Get the hackathon
50- const { data : hackathon , error : fetchError } = await supabase
51- . from ( 'hackathons' )
52- . select ( '*' )
53- . eq ( 'id' , id )
54- . single ( )
49+ // Get the hackathon
50+ const { data : hackathon , error : fetchError } = await supabase
51+ . from ( 'hackathons' )
52+ . select ( '*' )
53+ . eq ( 'id' , id )
54+ . single ( )
5555
56- if ( fetchError || ! hackathon ) {
57- return NextResponse . json (
58- { success : false , error : 'Hackathon not found' } ,
59- { status : 404 }
60- )
61- }
56+ if ( fetchError || ! hackathon ) {
57+ return NextResponse . json (
58+ { success : false , error : 'Hackathon not found' } ,
59+ { status : 404 }
60+ )
61+ }
6262
63- // Update hackathon based on action
64- const updateData : {
65- updated_at : string
66- approval_status ?: string
67- approved_by ?: string
68- approved_at ?: string
69- status ?: string
70- rejection_reason ?: string | null
71- } = {
72- updated_at : new Date ( ) . toISOString ( ) ,
73- }
63+ // Update hackathon based on action
64+ const updateData : {
65+ updated_at : string
66+ approval_status ?: string
67+ approved_by ?: string
68+ approved_at ?: string
69+ status ?: string
70+ rejection_reason ?: string | null
71+ } = {
72+ updated_at : new Date ( ) . toISOString ( ) ,
73+ }
7474
75- if ( action === 'approve' ) {
76- updateData . approval_status = 'approved'
77- updateData . approved_by = user . id
78- updateData . approved_at = new Date ( ) . toISOString ( )
79- updateData . status = 'live'
80- updateData . rejection_reason = null
81- } else if ( action === 'reject' ) {
82- updateData . approval_status = 'rejected'
83- updateData . rejection_reason = reason
84- updateData . status = 'draft'
85- }
75+ if ( action === 'approve' ) {
76+ updateData . approval_status = 'approved'
77+ updateData . approved_by = user . id
78+ updateData . approved_at = new Date ( ) . toISOString ( )
79+ updateData . status = 'live'
80+ updateData . rejection_reason = null
81+ } else if ( action === 'reject' ) {
82+ updateData . approval_status = 'rejected'
83+ updateData . rejection_reason = reason
84+ updateData . status = 'draft'
85+ } else if ( action === 'delete' ) {
86+ // Permanently delete the hackathon
87+ const { error : deleteError } = await supabase
88+ . from ( 'hackathons' )
89+ . delete ( )
90+ . eq ( 'id' , id )
8691
87- const { error : updateError } = await supabase
88- . from ( 'hackathons' )
89- . update ( updateData )
90- . eq ( 'id' , id )
92+ if ( deleteError ) {
93+ throw deleteError
94+ }
9195
92- if ( updateError ) {
93- throw updateError
94- }
96+ // Invalidate caches
97+ await UnifiedCache . purgeByTags ( [ 'content' , 'api' ] )
98+
99+ return NextResponse . json ( {
100+ success : true ,
101+ message : 'Hackathon permanently deleted' ,
102+ } )
103+ }
104+
105+ const { error : updateError } = await supabase
106+ . from ( 'hackathons' )
107+ . update ( updateData )
108+ . eq ( 'id' , id )
95109
96- // Invalidate caches
97- await UnifiedCache . purgeByTags ( [ 'content' , 'api' ] )
98-
99- return NextResponse . json ( {
100- success : true ,
101- message : `Hackathon ${ action } d successfully` ,
102- } )
103- } catch ( error ) {
104- console . error ( 'Error in hackathon moderation action:' , error )
105- return NextResponse . json (
106- {
107- success : false ,
108- error : error instanceof Error ? error . message : 'Failed to execute action' ,
109- } ,
110- { status : 500 }
111- )
112- }
110+ if ( updateError ) {
111+ throw updateError
112+ }
113+
114+ // Invalidate caches
115+ await UnifiedCache . purgeByTags ( [ 'content' , 'api' ] )
116+
117+ return NextResponse . json ( {
118+ success : true ,
119+ message : `Hackathon ${ action } d successfully` ,
120+ } )
121+ } catch ( error ) {
122+ console . error ( 'Error in hackathon moderation action:' , error )
123+ return NextResponse . json (
124+ {
125+ success : false ,
126+ error : error instanceof Error ? error . message : 'Failed to execute action' ,
127+ } ,
128+ { status : 500 }
129+ )
130+ }
113131 } ) ( request )
114132}
0 commit comments