Skip to content

Commit 51defe7

Browse files
Add remote functions to dashboard
1 parent c29d95e commit 51defe7

27 files changed

+632
-524
lines changed

api/package-lock.json

Lines changed: 12 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/src/routes/artists/[slug]/+server.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { TABLES } from '../../../../../shared/config';
22
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
33
import type { Artist } from '../../../../../shared/types/core';
44
import type { ArtistHydrated } from '../../../../../shared/types/hydrated';
5+
import { json } from '@sveltejs/kit';
56

67
export async function GET({ params }) {
78
return handlePostgrestQuery<ArtistHydrated>(
@@ -12,8 +13,9 @@ export async function GET({ params }) {
1213

1314
export async function PATCH({ request, params }) {
1415
const body: Partial<Artist> = await request.json();
15-
return handlePostgrestQuery<Artist>(
16-
async () => await supabase.from(TABLES.artists).update(body).eq('id', params.slug),
17-
{ errorMessage: 'Failed to update artist details' }
18-
);
16+
const { error } = await supabase.from(TABLES.artists).update(body).eq('id', params.slug);
17+
if (error) {
18+
return json({ error: 'Failed to update artist details' }, { status: 500 });
19+
}
20+
return json({ success: true });
1921
}

api/src/routes/releases/[slug]/+server.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { handlePostgrestQuery, supabase } from '$lib/server/supabase';
2+
import { json } from '@sveltejs/kit';
23
import { TABLES } from '../../../../../shared/config';
34
import type { ReleaseHydrated } from '../../../../../shared/types/hydrated';
45

@@ -8,3 +9,14 @@ export async function GET({ params }) {
89
{ errorMessage: 'Failed to fetch release' }
910
);
1011
}
12+
13+
export async function DELETE({ params }) {
14+
const { error } = await supabase.from(TABLES.releases).delete().eq('id', params.slug);
15+
16+
if (error) {
17+
console.error('Error deleting release:', error);
18+
return json({ error: 'Failed to delete release' }, { status: 500 });
19+
}
20+
21+
return json({ success: true });
22+
}

api/src/routes/tracks/+server.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { json, type RequestHandler } from '@sveltejs/kit';
22
import { supabase } from '$lib/server/supabase';
33
import { pinata } from '$lib/server/pinata';
44
import { TABLES } from '../../../../shared/config';
5-
import { formFieldNames } from '../../../../shared/types/forms';
65
import { parseFile } from 'music-metadata';
76
import fs from 'fs/promises';
87

@@ -26,11 +25,11 @@ export const POST: RequestHandler = async ({ request }) => {
2625
try {
2726
const formData = await request.formData();
2827

29-
const file = formData.get(formFieldNames.track.file) as File;
30-
const artistId = formData.get(formFieldNames.track.artistID) as string;
31-
const title = formData.get(formFieldNames.track.title) as string;
32-
const artistName = formData.get(formFieldNames.track.artistName) as string;
33-
const artistGroup = formData.get(formFieldNames.track.artistGroup) as string;
28+
const file = formData.get('file') as File;
29+
const artistId = formData.get('artistId') as string;
30+
const title = formData.get('title') as string;
31+
const artistName = formData.get('artistName') as string;
32+
const artistGroup = formData.get('artistGroup') as string;
3433

3534
if (!file || !artistId || !title) {
3635
return json({ error: 'Missing required fields' }, { status: 400 });
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { supabase } from '$lib/server/supabase';
2+
import { json, type RequestHandler } from '@sveltejs/kit';
3+
import { TABLES } from '../../../../../shared/config';
4+
5+
export const DELETE: RequestHandler = async ({ params }) => {
6+
const { error } = await supabase.from(TABLES.tracks).delete().eq('id', params.slug);
7+
8+
if (error) {
9+
console.error('Error deleting track:', error);
10+
return json({ error: 'Failed to delete track' }, { status: 500 });
11+
}
12+
13+
return json({ success: true });
14+
};

app/package-lock.json

Lines changed: 15 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)