summaryrefslogtreecommitdiff
path: root/pages/api/po/webhook.ts
diff options
context:
space:
mode:
authorrlaks5757 <rlaks5757@gmail.com>2025-03-26 16:51:54 +0900
committerrlaks5757 <rlaks5757@gmail.com>2025-03-27 17:32:42 +0900
commit92ddb4f13d48cbf344dc2bf63df4457b3c713608 (patch)
tree38108e1ca08a86c1b36941d39acc47601529a14a /pages/api/po/webhook.ts
parent2ca4c91514feadb5edd0c9411670c7d9964d21e3 (diff)
feat: report batch download 기능 완료
Diffstat (limited to 'pages/api/po/webhook.ts')
-rw-r--r--pages/api/po/webhook.ts45
1 files changed, 26 insertions, 19 deletions
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'