From 85ef6285601b09b2819a48bb55debde1b145e6c3 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Sun, 24 Nov 2024 00:29:23 +0200 Subject: [PATCH] Add to api/[entity]/all proxy request to accept and push through all query parameters to backen --- src/lib/entities.ts | 4 ++-- src/routes/api/[entity]/all/+server.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) 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");