summaryrefslogtreecommitdiff
path: root/app/api
diff options
context:
space:
mode:
authordujinkim <dujin.kim@dtsolution.co.kr>2025-09-18 00:23:40 +0000
committerdujinkim <dujin.kim@dtsolution.co.kr>2025-09-18 00:23:40 +0000
commitcf8dac0c6490469dab88a560004b0c07dbd48612 (patch)
treeb9e76061e80d868331e6b4277deecb9086f845f3 /app/api
parente5745fc0268bbb5770bc14a55fd58a0ec30b466e (diff)
(대표님) rfq, 계약, 서명 등
Diffstat (limited to 'app/api')
-rw-r--r--app/api/contracts/get-template/route.ts16
-rw-r--r--app/api/upload/purchase-request/route.ts56
-rw-r--r--app/api/upload/signed-contract/route.ts3
3 files changed, 68 insertions, 7 deletions
diff --git a/app/api/contracts/get-template/route.ts b/app/api/contracts/get-template/route.ts
index ff42196f..b7965481 100644
--- a/app/api/contracts/get-template/route.ts
+++ b/app/api/contracts/get-template/route.ts
@@ -12,14 +12,18 @@ export async function POST(request: NextRequest) {
{ status: 400 }
);
}
+
+ // /api/files로 시작하는 경우 제거
+ const cleanPath = templatePath.startsWith('/api/files')
+ ? templatePath.slice('/api/files'.length)
+ : templatePath;
+
const isDev = process.env.NODE_ENV === 'development';
- const fullPath =
- isDev ?
- path.join(process.cwd(), `public`, templatePath)
- :
- path.join(`${process.env.NAS_PATH}`, templatePath);
-
+ const fullPath = isDev
+ ? path.join(process.cwd(), `public`, cleanPath)
+ : path.join(`${process.env.NAS_PATH}`, cleanPath);
+
const fileBuffer = await readFile(fullPath);
return new NextResponse(fileBuffer, {
diff --git a/app/api/upload/purchase-request/route.ts b/app/api/upload/purchase-request/route.ts
new file mode 100644
index 00000000..8e49afcd
--- /dev/null
+++ b/app/api/upload/purchase-request/route.ts
@@ -0,0 +1,56 @@
+// app/api/upload/purchase-request/route.ts
+import { NextRequest, NextResponse } from "next/server";
+import { saveDRMFile } from "@/lib/file-stroage";
+import { getServerSession } from 'next-auth/next'
+import { authOptions } from '@/app/api/auth/[...nextauth]/route'
+import { decryptWithServerAction } from '@/components/drm/drmUtils'
+
+export async function POST(request: NextRequest) {
+ try {
+ const session = await getServerSession(authOptions)
+ if (!session?.user?.id) {
+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
+ }
+
+ const formData = await request.formData();
+ const files = formData.getAll("files") as File[];
+
+ if (!files || files.length === 0) {
+ return NextResponse.json({ error: "No files provided" }, { status: 400 });
+ }
+
+ const uploadResults = [];
+
+ for (const file of files) {
+ const result = await saveDRMFile(
+ file,
+ decryptWithServerAction,
+ "purchase-requests",
+ session.user.id,
+ );
+
+ if (!result.success) {
+ return NextResponse.json(
+ { error: result.error || "파일 업로드 실패" },
+ { status: 400 }
+ );
+ }
+
+ uploadResults.push({
+ fileName: result.fileName!,
+ originalFileName: file.name,
+ filePath: result.publicPath!,
+ fileSize: result.fileSize!,
+ fileType: file.type,
+ });
+ }
+
+ return NextResponse.json({ files: uploadResults });
+ } catch (error) {
+ console.error("Upload error:", error);
+ return NextResponse.json(
+ { error: "파일 업로드 중 오류가 발생했습니다" },
+ { status: 500 }
+ );
+ }
+} \ No newline at end of file
diff --git a/app/api/upload/signed-contract/route.ts b/app/api/upload/signed-contract/route.ts
index 873f21e5..880f54b2 100644
--- a/app/api/upload/signed-contract/route.ts
+++ b/app/api/upload/signed-contract/route.ts
@@ -48,8 +48,9 @@ export async function POST(request: NextRequest) {
status: "VENDOR_SIGNED",
fileName: saveResult.originalName || originalFileName, // 원본 파일명
filePath: saveResult.publicPath, // 웹 접근 가능한 경로
+ vendorSignedAt:new Date(),
updatedAt: new Date(),
- completedAt: null
+ completedAt:templateName.includes("GTC")? null : new Date()
})
.where(eq(basicContract.id, tableRowId));
});