Skip to content

Commit

Permalink
added categories to post request (getPlaylistCover doesn't work)
Browse files Browse the repository at this point in the history
  • Loading branch information
synan798 committed Nov 30, 2024
1 parent 7c5d310 commit 3d511f3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion server/api/v1/playlist/index.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const schema = z.object({
* @returns {Object} - Created playlist
*/
export default defineEventHandler(async (event) => {
// fix coverUrl and delete test.vue
const result = await readValidatedBody(event, body => schema.safeParse(body))

if (!result.success) {
Expand All @@ -36,11 +37,18 @@ export default defineEventHandler(async (event) => {
name: result.data.name,
spotifyId: result.data.spotifyId,
cover: coverUrl
//cover: "https://i.scdn.co/image/ab67706f000000024d183558628c25f8cb314eea"
}

const client = serverSupabaseServiceRole(event)
const categoriesInsert = result.data.categories.map((category) => ({
playlistId: result.data.id,
name: category,
}));

const client = serverSupabaseServiceRole(event);
const {data, error} = await client.from('playlists').insert(playlistInsert as never).select().single(); //todo: fix type error!


if (error) {
setResponseStatus(event, 400);
if (error.code === UNIQUE_VIOLATION)
Expand All @@ -49,6 +57,15 @@ export default defineEventHandler(async (event) => {
return {error: error.message};
}

const { data: categoriesData, error: categoriesError } = await client

Check failure on line 60 in server/api/v1/playlist/index.post.ts

View workflow job for this annotation

GitHub Actions / eslint

'categoriesData' is assigned a value but never used. Allowed unused vars must match /^_/u
.from('categories')
.insert(categoriesInsert as never);

if (categoriesError) {
setResponseStatus(event, 500);
return { error: `Error inserting categories: ${categoriesError.message}` };
}


setResponseStatus(event, 201);
return data;
Expand Down

0 comments on commit 3d511f3

Please sign in to comment.