diff options
| author | rlaks5757 <rlaks5757@gmail.com> | 2025-03-26 16:51:54 +0900 |
|---|---|---|
| committer | rlaks5757 <rlaks5757@gmail.com> | 2025-03-26 16:51:54 +0900 |
| commit | e0b2367d88dd80eece67390574e60c9eacdee14d (patch) | |
| tree | 5c7ec4b950f7249a40145564c6d701ed4f260c98 /pages/api | |
| parent | 2ca4c91514feadb5edd0c9411670c7d9964d21e3 (diff) | |
po, vendor-data-form-report
Diffstat (limited to 'pages/api')
| -rw-r--r-- | pages/api/po/sendDocuSign.ts | 8 | ||||
| -rw-r--r-- | pages/api/po/webhook.ts | 45 |
2 files changed, 31 insertions, 22 deletions
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' |
