-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathroute.ts
More file actions
23 lines (18 loc) · 796 Bytes
/
route.ts
File metadata and controls
23 lines (18 loc) · 796 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 { getFiles, getFilesRequestSchema } from "@/features/git/getFilesApi";
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 getFilesRequestSchema.safeParseAsync(body);
if (!parsed.success) {
return serviceErrorResponse(requestBodySchemaValidationError(parsed.error));
}
const response = await getFiles(parsed.data);
if (isServiceError(response)) {
return serviceErrorResponse(response);
}
return Response.json(response);
});