diff options
| author | joonhoekim <26rote@gmail.com> | 2025-03-27 16:33:09 +0900 |
|---|---|---|
| committer | joonhoekim <26rote@gmail.com> | 2025-03-27 16:33:09 +0900 |
| commit | 34bbeb86c1a8d24b5f526710889b5e54d699cfd0 (patch) | |
| tree | 19eaa9b8c266a5f6bc7f7d8fb9d9f949448c6b46 /lib/po | |
| parent | e6e98a1bed7a23d148ab97b3a7414ade4b1d236b (diff) | |
| parent | a2bb2de8aa7534b7b89993c395808b4b2b0b9f5d (diff) | |
merge
Diffstat (limited to 'lib/po')
| -rw-r--r-- | lib/po/service.ts | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/lib/po/service.ts b/lib/po/service.ts index 358f23d9..f697bd58 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,14 +324,27 @@ 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 발송에 실패하였습니다.", }; } - // Create a single envelope for all signers + // 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) .values({ @@ -338,7 +352,8 @@ Remarks:${contract.remarks}`, envelopeId: envelopeId, envelopeStatus: "sent", fileName: `${contractNo}-signature.pdf`, // Required field - filePath: `/contracts/${validatedData.contractId}/signatures/${contractNo}-signature.pdf`, // Required field + + filePath: `/contracts/${validatedData.contractId}/signatures/${uniqueName}`, // Required field // Add any other required fields based on your schema }) .returning(); @@ -368,25 +383,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"); |
