diff --git a/src/lib/entities.ts b/src/lib/entities.ts index ac0a3ce..f838083 100644 --- a/src/lib/entities.ts +++ b/src/lib/entities.ts @@ -142,8 +142,8 @@ export type EntityType = // -export async function getAll(groupName: string, session?: string): Promise { - const url = `${BASE_API_URL}/${groupName}/all` +export async function getAll(groupName: string, session?: string, queryParams?: string): Promise { + const url = queryParams ? `${BASE_API_URL}/${groupName}/all?${queryParams}` : `${BASE_API_URL}/${groupName}/all` const defaultHeaders = { 'Content-Type': 'application/json', }; diff --git a/src/routes/api/[entity]/all/+server.ts b/src/routes/api/[entity]/all/+server.ts index d3fae14..948bd4e 100644 --- a/src/routes/api/[entity]/all/+server.ts +++ b/src/routes/api/[entity]/all/+server.ts @@ -6,10 +6,11 @@ function isErrorMessage(value: any): value is ErrorMessage { return value && typeof value.message === 'string'; } -export const GET: RequestHandler = async ({ cookies, params }): Promise => { +export const GET: RequestHandler = async ({ cookies, params, url }): Promise => { const session = cookies.get('session'); const { entity } = params; + const queryParams = url.searchParams.toString(); // Check if the entity is valid if (!session) { return new Response(JSON.stringify("no cookies"), { status: 401 }); @@ -21,7 +22,7 @@ export const GET: RequestHandler = async ({ cookies, params }): Promise>(entityName, session); + const result = await getAll>(entityName, session, queryParams); if (isErrorMessage(result)) { console.log("ERROR");