17 lines
519 B
TypeScript
17 lines
519 B
TypeScript
import { getRequestEvent, query } from '$app/server';
|
|
import { authorQuerySchema } from '$lib/schema/author';
|
|
import { createQueryParams } from '$lib/utils';
|
|
import { error } from '@sveltejs/kit';
|
|
|
|
export const listAuthors = query(authorQuerySchema, async (data) => {
|
|
const { locals } = getRequestEvent();
|
|
|
|
const params = createQueryParams(data);
|
|
|
|
const response = await locals.api.get(`/authors?${params.toString()}`);
|
|
|
|
if (!response.ok) error(500, 'An unkown error occurred');
|
|
|
|
return await response.json();
|
|
});
|