Skip to content

Commit

Permalink
added categories to get requests
Browse files Browse the repository at this point in the history
  • Loading branch information
synan798 committed Nov 29, 2024
1 parent f0ac62d commit 7c5d310
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 7 additions & 3 deletions server/api/v1/playlist/[uid].get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
14 changes: 11 additions & 3 deletions server/api/v1/playlist/index.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})

0 comments on commit 7c5d310

Please sign in to comment.