The Open Source DocuSign Alternative.
TypeScript digital-signaturedocument-signingdocusign-alternativee-signatureesignesignaturenext-authnextjsopen-sourcepades-standardpdfpdf-signpdf-signaturepostgresqlprismaself-hostedsigningtypescript
feat: resend document via API (#1226)
Catalin Pit7f5b27372feb
diff --git a/packages/api/v1/contract.ts b/packages/api/v1/contract.tsindex c6c6b47f5..e8efeffe6 100644--- a/packages/api/v1/contract.ts+++ b/packages/api/v1/contract.ts@@ -17,6 +17,7 @@ import {ZGetDocumentsQuerySchema,ZGetTemplatesQuerySchema,ZNoBodyMutationSchema,+ ZResendDocumentForSigningMutationSchema,ZSendDocumentForSigningMutationSchema,ZSuccessfulDeleteTemplateResponseSchema,ZSuccessfulDocumentResponseSchema,@@ -25,6 +26,7 @@ import {ZSuccessfulGetTemplateResponseSchema,ZSuccessfulGetTemplatesResponseSchema,ZSuccessfulRecipientResponseSchema,+ ZSuccessfulResendDocumentResponseSchema,ZSuccessfulResponseSchema,ZSuccessfulSigningResponseSchema,ZUnsuccessfulResponseSchema,@@ -161,6 +163,20 @@ export const ApiContractV1 = c.router(summary: 'Send a document for signing',},+ resendDocument: {+ method: 'POST',+ path: '/api/v1/documents/:id/resend',+ body: ZResendDocumentForSigningMutationSchema,+ responses: {+ 200: ZSuccessfulResendDocumentResponseSchema,+ 400: ZUnsuccessfulResponseSchema,+ 401: ZUnsuccessfulResponseSchema,+ 404: ZUnsuccessfulResponseSchema,+ 500: ZUnsuccessfulResponseSchema,+ },+ summary: 'Re-send a document for signing',+ },+deleteDocument: {method: 'DELETE',path: '/api/v1/documents/:id',diff --git a/packages/api/v1/implementation.ts b/packages/api/v1/implementation.tsindex 1379b447c..7d4680dcc 100644--- a/packages/api/v1/implementation.ts+++ b/packages/api/v1/implementation.ts@@ -9,6 +9,7 @@ import { createDocument } from '@documenso/lib/server-only/document/create-documimport { deleteDocument } from '@documenso/lib/server-only/document/delete-document';import { findDocuments } from '@documenso/lib/server-only/document/find-documents';import { getDocumentById } from '@documenso/lib/server-only/document/get-document-by-id';+import { resendDocument } from '@documenso/lib/server-only/document/resend-document';import { sendDocument } from '@documenso/lib/server-only/document/send-document';import { updateDocument } from '@documenso/lib/server-only/document/update-document';import { createField } from '@documenso/lib/server-only/field/create-field';@@ -600,6 +601,35 @@ export const ApiContractV1Implementation = createNextRoute(ApiContractV1, {}}),+ resendDocument: authenticatedMiddleware(async (args, user, team) => {+ const { id: documentId } = args.params;+ const { recipients } = args.body;++ try {+ await resendDocument({+ userId: user.id,+ documentId: Number(documentId),+ recipients,+ teamId: team?.id,+ requestMetadata: extractNextApiRequestMetadata(args.req),+ });++ return {+ status: 200,+ body: {+ message: 'Document resend successfully initiated',+ },+ };+ } catch (err) {+ return {+ status: 500,+ body: {+ message: 'An error has occured while resending the document',+ },+ };+ }+ }),+createRecipient: authenticatedMiddleware(async (args, user, team) => {const { id: documentId } = args.params;const { name, email, role } = args.body;diff --git a/packages/api/v1/schema.ts b/packages/api/v1/schema.tsindex 5ecab08c6..ed41f5e6f 100644--- a/packages/api/v1/schema.ts+++ b/packages/api/v1/schema.ts@@ -57,6 +57,20 @@ export const ZSendDocumentForSigningMutationSchema = zexport type TSendDocumentForSigningMutationSchema = typeof ZSendDocumentForSigningMutationSchema;+export const ZResendDocumentForSigningMutationSchema = z.object({+ recipients: z.array(z.number()),+});++export type TResendDocumentForSigningMutationSchema = z.infer<+ typeof ZResendDocumentForSigningMutationSchema+>;++export const ZSuccessfulResendDocumentResponseSchema = z.object({+ message: z.string(),+});++export type TResendDocumentResponseSchema = z.infer<typeof ZSuccessfulResendDocumentResponseSchema>;+export const ZUploadDocumentSuccessfulSchema = z.object({url: z.string(),key: z.string(),