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 /lib/po/service.ts | |
| parent | 2ca4c91514feadb5edd0c9411670c7d9964d21e3 (diff) | |
po, vendor-data-form-report
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"); |
