diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-24 11:06:32 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-07-24 11:06:32 +0000 |
| commit | 1dc24d48e52f2e490f5603ceb02842586ecae533 (patch) | |
| tree | 8fca2c5b5b52cc10557b5ba6e55b937ae3c57cf6 /app/api/basicContract/create-revision/route.ts | |
| parent | ed0d6fcc98f671280c2ccde797b50693da88152e (diff) | |
(대표님) 정기평가 피드백 반영, 설계 피드백 반영, (최겸) 기술영업 피드백 반영
Diffstat (limited to 'app/api/basicContract/create-revision/route.ts')
| -rw-r--r-- | app/api/basicContract/create-revision/route.ts | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/app/api/basicContract/create-revision/route.ts b/app/api/basicContract/create-revision/route.ts new file mode 100644 index 00000000..69dc4c8f --- /dev/null +++ b/app/api/basicContract/create-revision/route.ts @@ -0,0 +1,75 @@ +// app/api/basicContract/create-revision/route.ts +import { NextRequest, NextResponse } from "next/server"; +import { unstable_noStore } from "next/cache"; +import { z } from "zod"; +import { getErrorMessage } from "@/lib/handle-error"; +import { createBasicContractTemplateRevision } from "@/lib/basic-contract/service"; + +// 리비전 생성 스키마 +const createRevisionSchema = z.object({ + baseTemplateId: z.string().uuid(), + templateName: z.string().min(1), + revision: z.number().int().min(1), + legalReviewRequired: z.boolean(), + shipBuildingApplicable: z.boolean(), + windApplicable: z.boolean(), + pcApplicable: z.boolean(), + nbApplicable: z.boolean(), + rcApplicable: z.boolean(), + gyApplicable: z.boolean(), + sysApplicable: z.boolean(), + infraApplicable: z.boolean(), + fileName: z.string().min(1), + filePath: z.string().min(1), +}); + +export async function POST(request: NextRequest) { + unstable_noStore(); + + try { + // 요청 본문 파싱 + const body = await request.json(); + const validatedData = createRevisionSchema.parse(body); + + // 같은 템플릿 이름에 대해 리비전이 이미 존재하는지 확인하는 로직은 + // 서비스 함수에서 처리됨 + + // 새 리비전 생성 + const { data: newRevision, error } = await createBasicContractTemplateRevision(validatedData); + + if (error) { + return NextResponse.json( + { success: false, error }, + { status: 400 } + ); + } + + return NextResponse.json({ + success: true, + data: newRevision, + message: `${validatedData.templateName} v${validatedData.revision} 리비전이 성공적으로 생성되었습니다.` + }); + + } catch (error) { + console.error("Create revision API error:", error); + + if (error instanceof z.ZodError) { + return NextResponse.json( + { + success: false, + error: "입력 데이터가 올바르지 않습니다.", + details: error.errors + }, + { status: 400 } + ); + } + + return NextResponse.json( + { + success: false, + error: getErrorMessage(error) + }, + { status: 500 } + ); + } +}
\ No newline at end of file |
