1- import { form , query } from '$app/server' ;
2- import { API_BASE } from '$lib/global/config' ;
1+ import { form } from '$app/server' ;
2+ import { API_BASE , REQUEST_HEADER_BOILERPLATE } from '$lib/global/config' ;
33import * as z from 'zod' ;
44import { requireAuth } from './auth-check' ;
5- import { redirect } from '@sveltejs/kit' ;
65
76const MakeCollectionForm = z . object ( {
87 name : z . string ( ) . min ( 3 ) . max ( 100 ) ,
@@ -23,9 +22,7 @@ export const makeCollection = form(MakeCollectionForm, async ({ name, descriptio
2322 const userId = requireAuth ( ) . id ;
2423 await fetch ( `${ API_BASE } /collections` , {
2524 method : 'POST' ,
26- headers : {
27- 'Content-Type' : 'application/json'
28- } ,
25+ headers : REQUEST_HEADER_BOILERPLATE ,
2926 body : JSON . stringify ( { userId, name, description } )
3027 } ) ;
3128} ) ;
@@ -34,9 +31,7 @@ export const deleteCollection = form(DeleteCollectionForm, async ({ collectionId
3431 const userId = requireAuth ( ) . id ;
3532 await fetch ( `${ API_BASE } /collections/${ collectionId } ` , {
3633 method : 'DELETE' ,
37- headers : {
38- 'Content-Type' : 'application/json'
39- } ,
34+ headers : REQUEST_HEADER_BOILERPLATE ,
4035 body : JSON . stringify ( { userId } )
4136 } ) ;
4237} ) ;
@@ -46,17 +41,8 @@ export const addOrRemoveReleaseFromCollection = form(
4641 async ( { collectionId, releaseId, addOrRemove } ) => {
4742 await fetch ( `${ API_BASE } /collections/${ collectionId } ` , {
4843 method : 'PATCH' ,
49- headers : {
50- 'Content-Type' : 'application/json'
51- } ,
44+ headers : REQUEST_HEADER_BOILERPLATE ,
5245 body : JSON . stringify ( { releaseId, addOrRemove } )
5346 } ) ;
5447 }
5548) ;
56-
57- export const getCollection = query ( z . string ( ) , async ( collectionId : string ) => {
58- const response = await fetch ( `${ API_BASE } /collections/${ collectionId } ` ) ;
59- if ( ! response . ok ) throw redirect ( 302 , '/me/collections' ) ;
60- const collection = await response . json ( ) ;
61- return collection ;
62- } ) ;
0 commit comments