Initial commit
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { form, getRequestEvent, query } from '$app/server';
|
||||
import { libraryCreateSchema, libraryQuerySchema } from '$lib/schema/library';
|
||||
import { createQueryParams } from '$lib/utils';
|
||||
import { error } from '@sveltejs/kit';
|
||||
|
||||
export const listLibraries = query(libraryQuerySchema, async (data) => {
|
||||
const { locals } = getRequestEvent();
|
||||
|
||||
const params = createQueryParams(data);
|
||||
|
||||
const response = await locals.api.get(`/libraries?${params.toString()}`);
|
||||
|
||||
if (!response.ok) error(500, 'An unkown error occurred');
|
||||
|
||||
return await response.json();
|
||||
});
|
||||
|
||||
export const createLibrary = form(libraryCreateSchema, async (data) => {
|
||||
const { locals } = getRequestEvent();
|
||||
|
||||
const response = await locals.api.post(`/libraries`, data);
|
||||
|
||||
if (!response.ok) error(500, 'An unknown error occurred');
|
||||
|
||||
return await response.json();
|
||||
});
|
||||
|
||||
export const deleteLibrary = query('unchecked', async (data) => {
|
||||
throw new Error('Not implemented');
|
||||
});
|
||||
Reference in New Issue
Block a user