diff options
| author | dtsdujinkim <141381630+dtsdujinkim@users.noreply.github.com> | 2025-03-27 11:58:14 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-27 11:58:14 +0900 |
| commit | a2bb2de8aa7534b7b89993c395808b4b2b0b9f5d (patch) | |
| tree | 932095e15eedbcf726b407470b98e6e332256a8b /lib/po/service.ts | |
| parent | 2ca4c91514feadb5edd0c9411670c7d9964d21e3 (diff) | |
| parent | 23db698279eb8ea5f73f678ce6deb93267c4705e (diff) | |
Merge pull request #3 from DTS-Development/kiman
Vendor Data Report Viewer, PO DocuSign
Diffstat (limited to 'lib/po/service.ts')
| -rw-r--r-- | lib/po/service.ts | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/lib/po/service.ts b/lib/po/service.ts index dc398201..0653c11a 100644 --- a/lib/po/service.ts +++ b/lib/po/service.ts @@ -1,5 +1,6 @@ "use server"; - +import path from "path"; +import { v4 as uuidv4 } from "uuid"; import { headers } from "next/headers"; import db from "@/db/db"; import { GetPOSchema } from "./validations"; @@ -323,13 +324,26 @@ Remarks:${contract.remarks}`, const { success: sendDocuSignResult, envelopeId } = sendDocuSign; + await tx + .update(contracts) + .set({ + status: sendDocuSignResult ? "PENDING_SIGNATURE" : "Docu Sign Failed", + }) + .where(eq(contracts.id, validatedData.contractId)); + if (!sendDocuSignResult) { return { success: false, - message: "DocuSign 전자 서명 발송에 실패하였습니다.", + message: "DocuSign Mail 발송에 실패하였습니다.", }; } + // Update contract status to indicate pending signatures + + const fileName = `${contractNo}-signature.pdf`; + const ext = path.extname(fileName); + const uniqueName = uuidv4() + ext; + // Create a single envelope for all signers const [newEnvelope] = await tx .insert(contractEnvelopes) @@ -338,7 +352,7 @@ Remarks:${contract.remarks}`, envelopeId: envelopeId, envelopeStatus: "sent", fileName: `${contractNo}-signature.pdf`, // Required field - filePath: `/contracts/${validatedData.contractId}/signatures`, // Required field + filePath: `/contracts/${validatedData.contractId}/signatures/${uniqueName}`, // Required field // Add any other required fields based on your schema }) .returning(); @@ -368,25 +382,6 @@ Remarks:${contract.remarks}`, }); } - // Update contract status to indicate pending signatures - await tx - .update(contracts) - .set({ status: "PENDING_SIGNATURE" }) - .where(eq(contracts.id, validatedData.contractId)); - - // In a real implementation, you would send the envelope to DocuSign or similar service - // For example: - // const docusignResult = await docusignClient.createEnvelope({ - // recipients: validatedData.signers.map(signer => ({ - // email: signer.signerEmail, - // name: signer.signerName, - // recipientType: signer.signerType === "REQUESTER" ? "signer" : "cc", - // routingOrder: signer.signerType === "REQUESTER" ? 1 : 2, - // })), - // documentId: `contract-${validatedData.contractId}`, - // // other DocuSign-specific parameters - // }); - // Revalidate the path to refresh the data revalidatePath("/po"); |
