uup
This commit is contained in:
20
app/routes/api.customers.search.tsx
Normal file
20
app/routes/api.customers.search.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { LoaderFunctionArgs } from "@remix-run/node";
|
||||
import { json } from "@remix-run/node";
|
||||
import { requireUser } from "~/lib/auth.server";
|
||||
import { searchCustomers } from "~/lib/customer-management.server";
|
||||
|
||||
export async function loader({ request }: LoaderFunctionArgs) {
|
||||
await requireUser(request);
|
||||
|
||||
const url = new URL(request.url);
|
||||
const query = url.searchParams.get("q") || "";
|
||||
const limit = parseInt(url.searchParams.get("limit") || "10");
|
||||
|
||||
if (!query || query.trim().length < 2) {
|
||||
return json({ customers: [] });
|
||||
}
|
||||
|
||||
const customers = await searchCustomers(query, limit);
|
||||
|
||||
return json({ customers });
|
||||
}
|
||||
Reference in New Issue
Block a user