Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/api/ao/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const rawQuery = searchParams.get("q") || "";
const q = rawQuery.trim();
const includeInactive = searchParams.get("includeInactive") === "true";

// Guardrail: do not allow overly-broad or empty searches.
if (q.length < 2) {
return NextResponse.json([], { status: 200 });
}

try {
const aos = await searchAOsByName(q, user.email);
const aos = await searchAOsByName(q, user.email, includeInactive);
return NextResponse.json(aos, { status: 200 });
} catch (err) {
console.error("AO search failed:", err);
Expand Down
3 changes: 2 additions & 1 deletion src/app/api/region/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ export async function GET(request: Request) {
const { searchParams } = new URL(request.url);
const rawQuery = searchParams.get("q") || "";
const q = rawQuery.trim();
const includeInactive = searchParams.get("includeInactive") === "true";

// Guardrail: do not allow overly-broad or empty searches.
if (q.length < 2) {
return NextResponse.json([], { status: 200 });
}

try {
const regions = await searchRegionsByName(q, user.email);
const regions = await searchRegionsByName(q, user.email, includeInactive);
return NextResponse.json(regions, { status: 200 });
} catch (err) {
console.error("Region search failed:", err);
Expand Down
33 changes: 33 additions & 0 deletions src/app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { NextResponse } from "next/server";
import { searchAll } from "@/lib/bq/search";
import { getSessionUser } from "@/lib/auth/server";

export async function GET(request: Request) {
const user = await getSessionUser();
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}

const { searchParams } = new URL(request.url);
const rawQuery = searchParams.get("q") || "";
const q = rawQuery.trim();
const includeInactive = searchParams.get("includeInactive") === "true";

if (q.length < 2) {
return NextResponse.json(
{ regions: [], aos: [], pax: [] },
{ status: 200 },
);
}

try {
const results = await searchAll(q, user.email, includeInactive);
return NextResponse.json(results, { status: 200 });
} catch (err) {
console.error("Search failed:", err);
return NextResponse.json(
{ error: "Search failed. Please try again." },
{ status: 500 },
);
}
}
2 changes: 2 additions & 0 deletions src/app/stats/region/[regionId]/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
Leaders,
RegionKotterList,
ChartData,
RegionAchievementPax,
} from "@/lib/types";
import { getPageData } from "@/lib/bq/regions";

Expand Down Expand Up @@ -72,6 +73,7 @@ export async function loadRegionData(
upcoming: (mergedPlain.upcoming ?? []) as EventUpcoming[],
kotter: (mergedPlain.kotter ?? []) as RegionKotterList[],
charts: (mergedPlain.charts ?? []) as ChartData[],
achievements: (mergedPlain.achievements ?? []) as RegionAchievementPax[],
};

mergedSafe.events = (mergedSafe.events ?? []).map((e: EventData) => ({
Expand Down
1 change: 1 addition & 0 deletions src/app/stats/region/[regionId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export default async function RegionDetailPage({
region_upcoming={regionData.upcoming || []}
region_events={regionData.events || []}
region_charts={regionData.charts || []}
region_achievements={regionData.achievements || []}
searchParams={{
categoryIds,
categoryMode,
Expand Down
Loading
Loading