-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathroute.ts
More file actions
34 lines (28 loc) · 925 Bytes
/
route.ts
File metadata and controls
34 lines (28 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use server';
import { search, searchRequestSchema } from "@/features/search";
import { apiHandler } from "@/lib/apiHandler";
import { requestBodySchemaValidationError, serviceErrorResponse } from "@/lib/serviceError";
import { isServiceError } from "@/lib/utils";
import { NextRequest } from "next/server";
export const POST = apiHandler(async (request: NextRequest) => {
const body = await request.json();
const parsed = await searchRequestSchema.safeParseAsync(body);
if (!parsed.success) {
return serviceErrorResponse(
requestBodySchemaValidationError(parsed.error)
);
}
const {
query,
...options
} = parsed.data;
const response = await search({
queryType: 'string',
query,
options,
});
if (isServiceError(response)) {
return serviceErrorResponse(response);
}
return Response.json(response);
});