diff --git a/server/api/v1/playlist/[uid].get.ts b/server/api/v1/playlist/[uid].get.ts index b9be938..ace864b 100644 --- a/server/api/v1/playlist/[uid].get.ts +++ b/server/api/v1/playlist/[uid].get.ts @@ -25,12 +25,16 @@ export default defineEventHandler(async (event) => { } const client = serverSupabaseServiceRole(event); - const {data, error} = await client.from('playlists').select('*').eq('id', playlistId).single(); + const {data, error} = await client.from('playlists').select('*, categories (name)').eq('id', playlistId).single(); if (error) { setResponseStatus(event, 500); return {error: error.message}; + } else { + const transformedData = { + ...data, + categories: data.categories.map(category => category.name) + }; + return transformedData; } - - return data; }) \ No newline at end of file diff --git a/server/api/v1/playlist/index.get.ts b/server/api/v1/playlist/index.get.ts index 1a23cb1..c1e3d9b 100644 --- a/server/api/v1/playlist/index.get.ts +++ b/server/api/v1/playlist/index.get.ts @@ -16,12 +16,20 @@ export default defineEventHandler(async (event) => { } const client = serverSupabaseServiceRole(event); - const {data, error} = await client.from('playlists').select(); + const {data, error} = await client.from('playlists') + .select(` + *, + categories (name) + `); if (error) { setResponseStatus(event, 500); return {error: error.message}; + } else { + const transformedData = data.map(playlist => ({ + ...playlist, + categories: playlist.categories.map(category => category.name), + })); + return transformedData; } - - return data; }) \ No newline at end of file