mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-14 13:25:21 +00:00
23 lines
No EOL
772 B
TypeScript
23 lines
No EOL
772 B
TypeScript
'use server';
|
|
|
|
import { search } from "@/features/search/searchApi";
|
|
import { isServiceError } from "@/lib/utils";
|
|
import { NextRequest } from "next/server";
|
|
import { schemaValidationError, serviceErrorResponse } from "@/lib/serviceError";
|
|
import { searchRequestSchema } from "@/features/search/types";
|
|
|
|
export const POST = async (request: NextRequest) => {
|
|
const body = await request.json();
|
|
const parsed = await searchRequestSchema.safeParseAsync(body);
|
|
if (!parsed.success) {
|
|
return serviceErrorResponse(
|
|
schemaValidationError(parsed.error)
|
|
);
|
|
}
|
|
|
|
const response = await search(parsed.data);
|
|
if (isServiceError(response)) {
|
|
return serviceErrorResponse(response);
|
|
}
|
|
return Response.json(response);
|
|
} |