summaryrefslogtreecommitdiff
path: root/pages/api
diff options
context:
space:
mode:
authordtsdujinkim <141381630+dtsdujinkim@users.noreply.github.com>2025-03-27 11:58:14 +0900
committerGitHub <noreply@github.com>2025-03-27 11:58:14 +0900
commita2bb2de8aa7534b7b89993c395808b4b2b0b9f5d (patch)
tree932095e15eedbcf726b407470b98e6e332256a8b /pages/api
parent2ca4c91514feadb5edd0c9411670c7d9964d21e3 (diff)
parent23db698279eb8ea5f73f678ce6deb93267c4705e (diff)
Merge pull request #3 from DTS-Development/kiman
Vendor Data Report Viewer, PO DocuSign
Diffstat (limited to 'pages/api')
-rw-r--r--pages/api/pdftron/createVendorDataReports.ts36
-rw-r--r--pages/api/po/sendDocuSign.ts8
-rw-r--r--pages/api/po/webhook.ts45
3 files changed, 67 insertions, 22 deletions
diff --git a/pages/api/pdftron/createVendorDataReports.ts b/pages/api/pdftron/createVendorDataReports.ts
new file mode 100644
index 00000000..47f6055d
--- /dev/null
+++ b/pages/api/pdftron/createVendorDataReports.ts
@@ -0,0 +1,36 @@
+import type { NextApiRequest, NextApiResponse } from "next";
+import formidable from "formidable";
+
+export const config = {
+ api: {
+ bodyParser: false, // ✅ 이게 false면 안 됨!
+ },
+};
+
+export default async function handler(
+ req: NextApiRequest,
+ res: NextApiResponse
+) {
+ if (req.method !== "POST") {
+ return res.status(405).end();
+ }
+
+ const form = formidable({ multiples: true });
+
+ form.parse(req, async (err, fields, files) => {
+ if (err) {
+ console.error(err);
+ return res.status(500).json({ error: "Error parsing form" });
+ }
+
+ try {
+ const additionalData = JSON.parse((fields?.additionalData ?? "") as string);
+ console.log("📦 additionalData:", additionalData);
+ console.log("📎 files:", files.files); // files.files는 array or single file
+
+ return res.status(200).json({ success: true });
+ } catch (e) {
+ return res.status(400).json({ error: "Invalid additionalData" });
+ }
+ });
+}
diff --git a/pages/api/po/sendDocuSign.ts b/pages/api/po/sendDocuSign.ts
index ccb83733..eb218c2c 100644
--- a/pages/api/po/sendDocuSign.ts
+++ b/pages/api/po/sendDocuSign.ts
@@ -5,7 +5,7 @@ export const config = {
};
import type { NextApiRequest, NextApiResponse } from "next";
-import { requestContractSign } from "@/lib/docuSign/docuSignFns";
+import { requestContractSign, getRecipients } from "@/lib/docuSign/docuSignFns";
export default async function handler(
req: NextApiRequest,
@@ -36,11 +36,13 @@ export default async function handler(
const { result, envelopeId, error } = docuSignStart;
- res.status(200).json({
+ const sendResult = {
success: result,
envelopeId,
message: error?.message,
- });
+ };
+
+ res.status(200).json(sendResult);
} catch (error: any) {
res
.status(500)
diff --git a/pages/api/po/webhook.ts b/pages/api/po/webhook.ts
index 50b3c1f4..4a9b6a29 100644
--- a/pages/api/po/webhook.ts
+++ b/pages/api/po/webhook.ts
@@ -3,15 +3,11 @@ export const config = {
bodyParser: true, // ✅ 이게 false면 안 됨!
},
};
-
import type { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import fs from "fs";
import * as z from "zod";
import db from "@/db/db";
-import { GetPOSchema } from "@/lib/po/validations";
-import { unstable_cache } from "@/lib/unstable-cache";
-import { filterColumns } from "@/lib/filter-columns";
import {
asc,
desc,
@@ -25,18 +21,15 @@ import {
eq,
count,
} from "drizzle-orm";
-import { countPos, selectPos } from "@/lib/po/repository";
import {
contractEnvelopes,
- contractsDetailView,
contractSigners,
contracts,
} from "@/db/schema/contract";
-import { vendors, vendorContacts } from "@/db/schema/vendors";
-import dayjs from "dayjs";
-
-import { POContent } from "@/lib/docuSign/types";
-import { downloadContractFile, getRecipients } from "@/lib/docuSign/docuSignFns";
+import {
+ downloadContractFile,
+ getRecipients,
+} from "@/lib/docuSign/docuSignFns";
export default async function handler(
req: NextApiRequest,
@@ -52,8 +45,8 @@ export default async function handler(
//recipientId === "1" 첫번째 서명자 서명 완료
//recipientId === "2" 두번쨰 서명자 서명 완료
const { envelopeId, recipientId } = data;
-
- console.log(req.body)
+
+ console.log(req.body);
const contractList = [
{
@@ -110,7 +103,7 @@ export default async function handler(
await tx
.update(contracts)
- .set({ status: `$FAILED_${safeRole}_SEND_MAIL(${message})` })
+ .set({ status: `FAILED_${safeRole}_SEND_MAIL(${message})` })
.where(eq(contracts.id, contractId));
await tx
@@ -133,7 +126,7 @@ export default async function handler(
// continue;
// }
- // const fullFilePath = createFolderTree(fileName, filePath);
+ // const fullFilePath = createFolderTree(filePath);
// fs.writeFileSync(fullFilePath, buffer);
}
@@ -156,6 +149,10 @@ export default async function handler(
.where(eq(dbSchma.envelopeId, envelopeId))
.limit(1);
+ if (!targetContract) {
+ continue;
+ }
+
const { id, contractId } = targetContract;
if (contractId === null || contractId === undefined) {
@@ -212,6 +209,10 @@ export default async function handler(
.where(eq(dbSchma.envelopeId, envelopeId))
.limit(1);
+ if (!targetContract) {
+ continue;
+ }
+
const { id, contractId, fileName, filePath } = targetContract;
if (contractId === null || contractId === undefined) {
@@ -229,7 +230,7 @@ export default async function handler(
continue;
}
- const fullFilePath = createFolderTree(fileName, filePath);
+ const fullFilePath = createFolderTree(filePath);
fs.writeFileSync(fullFilePath, buffer);
@@ -279,6 +280,10 @@ export default async function handler(
.where(eq(dbSchma.envelopeId, envelopeId))
.limit(1);
+ if (!targetContract) {
+ continue;
+ }
+
const { contractId, fileName, filePath } = targetContract;
if (contractId === null || contractId === undefined) {
@@ -296,7 +301,7 @@ export default async function handler(
continue;
}
- const fullFilePath = createFolderTree(fileName, filePath);
+ const fullFilePath = createFolderTree(filePath);
fs.writeFileSync(fullFilePath, buffer);
@@ -324,8 +329,10 @@ export default async function handler(
}
}
-const createFolderTree = (fileName: string, filePath: string): string => {
- const cleanedPath = filePath.replace(/^\/+/, "");
+const createFolderTree = (filePath: string): string => {
+ const fileName = path.basename(filePath);
+ const folderPath = path.dirname(filePath);
+ const cleanedPath = folderPath.replace(/^\/+/, "");
const dirPath = path.resolve(process.cwd(), "public", cleanedPath); // 예: 'contracts/185/signatures'
const fullFilePath = path.join(dirPath, fileName); // 예: 'contracts/185/signatures/xxx.pdf'