260617_01_ENH: 배정 테스트를 위해 개발 중도 커밋
This commit is contained in:
116
src/app/api/assign/[[...slug]]/route.ts
Normal file
116
src/app/api/assign/[[...slug]]/route.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import {NextRequest, NextResponse} from "next/server";
|
||||
import {RouteContext} from "@/types/common";
|
||||
import {errorToResponse} from "@/lib/http-util";
|
||||
import {createBackApi} from "@/lib/server-api";
|
||||
import {ExcelUploadResult} from "@/types/common";
|
||||
import {AssignUserCount, MonitoringApplyUser, PerformanceApplyCount, PerformanceAssign} from "@/types/gwcf";
|
||||
|
||||
export const GET = async (
|
||||
req: NextRequest,
|
||||
context: RouteContext
|
||||
) => {
|
||||
try {
|
||||
void req;
|
||||
const {slug = []} = await context.params;
|
||||
const [action, subAction, performanceId] = slug;
|
||||
const backApi = await createBackApi();
|
||||
|
||||
if (action === "monitoring" && subAction === "apply-users" && performanceId === "count" && slug.length === 3) {
|
||||
const result = await backApi.get<PerformanceApplyCount[]>("/assign/monitoring/apply-users/count");
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if (action === "monitoring" && subAction === "apply-users" && performanceId && slug.length === 3) {
|
||||
const result = await backApi.get<MonitoringApplyUser[]>(`/assign/monitoring/apply-users/${encodeURIComponent(performanceId)}`);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if (action === "users" && subAction === "count" && slug.length === 2) {
|
||||
const result = await backApi.get<AssignUserCount[]>("/assign/users/count");
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const POST = async (
|
||||
req: NextRequest,
|
||||
context: RouteContext
|
||||
) => {
|
||||
try {
|
||||
const {slug = []} = await context.params;
|
||||
const [action, second, third] = slug;
|
||||
const backApi = await createBackApi();
|
||||
|
||||
if (action === "monitoring" && slug.length === 1) {
|
||||
const body = await req.json();
|
||||
const result = await backApi.post<PerformanceAssign[]>("/assign/monitoring", body);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if (action === "confirm" && second && third && slug.length === 3) {
|
||||
const result = await backApi.post<string>(
|
||||
`/assign/confirm/${encodeURIComponent(second)}/${encodeURIComponent(third)}`
|
||||
);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
if(action === "written" && second === "excel-template"){
|
||||
const result = await backApi.post<ArrayBuffer>(
|
||||
"/assign/written/excel/template",
|
||||
undefined,
|
||||
{ expectBinary: true }
|
||||
);
|
||||
|
||||
return new NextResponse(result, { status: 200 });
|
||||
}
|
||||
|
||||
if (action === "written" && second === "excel-upload" && slug.length === 2) {
|
||||
const formData = await req.formData();
|
||||
const file = formData.get("file") as File | null;
|
||||
|
||||
if (!file) {
|
||||
return NextResponse.json({ message: "file field is required." }, { status: 400 });
|
||||
}
|
||||
|
||||
const backendForm = new FormData();
|
||||
backendForm.append("file", file, file.name);
|
||||
|
||||
const result = await backApi.postForm<ExcelUploadResult>(
|
||||
"/assign/written/excel/upload",
|
||||
backendForm
|
||||
);
|
||||
return NextResponse.json(result, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
|
||||
export const PATCH = async (
|
||||
req: NextRequest,
|
||||
context: RouteContext
|
||||
) => {
|
||||
try {
|
||||
void req;
|
||||
const {slug = []} = await context.params;
|
||||
const [action, performanceId, userId] = slug;
|
||||
const backApi = await createBackApi();
|
||||
|
||||
if ((action === "confirm" || action === "cancel") && performanceId && userId && slug.length === 3) {
|
||||
await backApi.patch<void>(
|
||||
`/assign/${action}/${encodeURIComponent(performanceId)}/${encodeURIComponent(userId)}`
|
||||
);
|
||||
return new NextResponse(null, { status: 204 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
||||
} catch (error: unknown) {
|
||||
return errorToResponse(error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user