1- import { supabase } from '$lib/server/supabase' ;
1+ import { handlePostgrestQuery , supabase } from '$lib/server/supabase' ;
22import { json } from '@sveltejs/kit' ;
33import { TABLES } from '../../../../../shared/config' ;
44
5+ export async function GET ( { params } ) {
6+ return handlePostgrestQuery (
7+ async ( ) => supabase . from ( TABLES . mixtapesRich ) . select ( '*' ) . eq ( 'id' , params . slug ) . single ( ) ,
8+ { errorMessage : 'Failed to fetch mixtape' }
9+ ) ;
10+ }
11+
512export async function PATCH ( { request, params } ) {
613 const mixtapeId = params . slug ;
714 const { trackId } = await request . json ( ) ;
@@ -21,18 +28,20 @@ export async function PATCH({ request, params }) {
2128 return json ( { success : true } ) ;
2229}
2330
24- export async function GET ( { params } ) {
31+ export const DELETE = async ( { request , params } ) => {
2532 const mixtapeId = params . slug ;
26- const { data : mixtape , error } = await supabase
27- . from ( TABLES . mixtapesRich )
28- . select ( '*' )
33+ const { userId } = await request . json ( ) ;
34+
35+ const { error } = await supabase
36+ . from ( TABLES . mixtapes )
37+ . delete ( )
2938 . eq ( 'id' , mixtapeId )
30- . single ( ) ;
39+ . eq ( 'user_id' , userId ) ;
3140
3241 if ( error ) {
33- console . error ( 'Error fetching mixtape tracks :' , error ) ;
34- return json ( { error : 'Failed to fetch mixtape tracks ' } , { status : 500 } ) ;
42+ console . error ( 'Error deleting mixtape:' , error ) ;
43+ return json ( { error : 'Failed to delete mixtape' } , { status : 500 } ) ;
3544 }
3645
37- return json ( mixtape ) ;
38- }
46+ return json ( { success : true } ) ;
47+ } ;
0 commit comments