From db07658d7195c290ed34de1c9b8e44436bf2ce72 Mon Sep 17 00:00:00 2001 From: Power-Maverick Date: Thu, 11 Jun 2026 10:14:21 -0400 Subject: [PATCH] refactor: streamline error response handling and include created_at in tool selection --- app/api/odata/tools/route.ts | 38 ++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/app/api/odata/tools/route.ts b/app/api/odata/tools/route.ts index 59d3629..90f0829 100644 --- a/app/api/odata/tools/route.ts +++ b/app/api/odata/tools/route.ts @@ -17,22 +17,19 @@ export async function GET(request: NextRequest) { try { const supabase = getSupabaseClient(); if (!supabase) { - return new NextResponse( - JSON.stringify({ error: { code: "500", message: "Supabase is not configured" } }), - { - status: 500, - headers: { - "Content-Type": "application/json;odata.metadata=minimal", - "OData-Version": "4.0", - }, + return new NextResponse(JSON.stringify({ error: { code: "500", message: "Supabase is not configured" } }), { + status: 500, + headers: { + "Content-Type": "application/json;odata.metadata=minimal", + "OData-Version": "4.0", }, - ); + }); } const { data, error } = await supabase .from("tools") .select( - `packagename, name, description, version, license, readmeurl, website, repository, min_api, max_api, published_at, + `packagename, name, description, version, license, readmeurl, website, repository, min_api, max_api, published_at, created_at, tool_analytics (downloads, rating, mau), tool_categories (categories (name)), tool_contributors (contributors (name))`, @@ -59,14 +56,16 @@ export async function GET(request: NextRequest) { Repository: (tool.repository as string | null) ?? null, MinAPI: (tool.min_api as string | null) ?? null, MaxAPI: (tool.max_api as string | null) ?? null, + CreatedOn: (tool.created_at as string | null) ?? null, LastPublishedOn: (tool.published_at as string | null) ?? null, Downloads: (tool.tool_analytics?.downloads as number) ?? 0, Rating: (tool.tool_analytics?.rating as number) ?? 0, MAU: (tool.tool_analytics?.mau as number) ?? 0, // eslint-disable-next-line @typescript-eslint/no-explicit-any Categories: (tool.tool_categories as any[])?.map((toolCategory: any) => toolCategory.categories?.name as string).filter((name: string | undefined): name is string => !!name) ?? [], - // eslint-disable-next-line @typescript-eslint/no-explicit-any - Contributors: (tool.tool_contributors as any[])?.map((toolContributor: any) => toolContributor.contributors?.name as string).filter((name: string | undefined): name is string => !!name) ?? [], + Contributors: + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (tool.tool_contributors as any[])?.map((toolContributor: any) => toolContributor.contributors?.name as string).filter((name: string | undefined): name is string => !!name) ?? [], })); return new NextResponse( @@ -83,15 +82,12 @@ export async function GET(request: NextRequest) { ); } catch (error) { console.error("Error fetching tools for OData feed:", error); - return new NextResponse( - JSON.stringify({ error: { code: "500", message: "Failed to fetch tools" } }), - { - status: 500, - headers: { - "Content-Type": "application/json;odata.metadata=minimal", - "OData-Version": "4.0", - }, + return new NextResponse(JSON.stringify({ error: { code: "500", message: "Failed to fetch tools" } }), { + status: 500, + headers: { + "Content-Type": "application/json;odata.metadata=minimal", + "OData-Version": "4.0", }, - ); + }); } }