EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
route.ts
Go to the documentation of this file.
1import { NextRequest, NextResponse } from "next/server";
2import { fieldpineServerApi } from "@/lib/server/fieldpineApi";
3import { getStoredAuth } from "@/lib/server/auth";
4
5export async function GET(request: NextRequest) {
6 try {
7 const authData = await getStoredAuth();
8 if (!authData) {
9 return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
10 }
11
12 const { searchParams } = new URL(request.url);
13 const query = searchParams.get("query") || "";
14 const limit = searchParams.get("limit") || "30";
15 const ref = searchParams.get("ref") || "1";
16 const inputMethod = searchParams.get("inputMethod") || "keyboard";
17
18 const endpoint = `/OpenApi/SalesSearch?limit=${limit}&ref=${ref}&InputMethod=${inputMethod}&querytext=${encodeURIComponent(query)}`;
19
20 const result = await fieldpineServerApi.apiCall(endpoint, {
21 method: "GET",
22 cookie: authData.apiKey!,
23 });
24
25 return NextResponse.json({
26 success: true,
27 data: result,
28 source: "openapi",
29 });
30 } catch (error: any) {
31 console.error("Error searching sales:", error);
32 return NextResponse.json(
33 { success: false, error: error.message || "Failed to search sales" },
34 { status: error.status || 500 }
35 );
36 }
37}