-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathroute.ts
More file actions
22 lines (18 loc) · 745 Bytes
/
route.ts
File metadata and controls
22 lines (18 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use server';
import { getRefsRequestSchema } from "@/lib/schemas";
import { requestBodySchemaValidationError, serviceErrorResponse } from "@/lib/serviceError";
import { isServiceError } from "@/lib/utils";
import { NextRequest } from "next/server";
import { getRefs } from "./getRefs";
export const POST = async (request: NextRequest) => {
const body = await request.json();
const parsed = await getRefsRequestSchema.safeParseAsync(body);
if (!parsed.success) {
return serviceErrorResponse(requestBodySchemaValidationError(parsed.error));
}
const response = await getRefs(parsed.data);
if (isServiceError(response)) {
return serviceErrorResponse(response);
}
return Response.json(response);
}