From 6a2bb136333044f0efbc8406ceca840d2b4189fc Mon Sep 17 00:00:00 2001 From: synan798 Date: Sat, 30 Nov 2024 16:15:27 +0100 Subject: [PATCH] added correct return statement --- server/api/v1/playlist/index.post.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/api/v1/playlist/index.post.ts b/server/api/v1/playlist/index.post.ts index d22a410..7131877 100644 --- a/server/api/v1/playlist/index.post.ts +++ b/server/api/v1/playlist/index.post.ts @@ -44,15 +44,15 @@ export default defineEventHandler(async (event) => { })); const client = serverSupabaseServiceRole(event); - const {data, error} = await client.from('playlists').insert(playlistInsert as never).select().single(); //todo: fix type error! + const {data: playlistData, error: playlistError} = await client.from('playlists').insert(playlistInsert as never).select().single(); //todo: fix type error! - if (error) { + if (playlistError) { setResponseStatus(event, 400); - if (error.code === UNIQUE_VIOLATION) + if (playlistError.code === UNIQUE_VIOLATION) return {error: 'Playlist with this ID already exists'}; setResponseStatus(event, 500); - return {error: error.message}; + return {error: playlistError.message}; } const { data: categoriesData, error: categoriesError } = await client @@ -66,5 +66,5 @@ export default defineEventHandler(async (event) => { setResponseStatus(event, 201); - return data; + return { playlist: playlistData, categories: categoriesData }; }) \ No newline at end of file