feat: resend document via API (#1226)
Allow users to re-send documents via the API.
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
|||||||
ZGetDocumentsQuerySchema,
|
ZGetDocumentsQuerySchema,
|
||||||
ZGetTemplatesQuerySchema,
|
ZGetTemplatesQuerySchema,
|
||||||
ZNoBodyMutationSchema,
|
ZNoBodyMutationSchema,
|
||||||
|
ZResendDocumentForSigningMutationSchema,
|
||||||
ZSendDocumentForSigningMutationSchema,
|
ZSendDocumentForSigningMutationSchema,
|
||||||
ZSuccessfulDeleteTemplateResponseSchema,
|
ZSuccessfulDeleteTemplateResponseSchema,
|
||||||
ZSuccessfulDocumentResponseSchema,
|
ZSuccessfulDocumentResponseSchema,
|
||||||
@@ -25,6 +26,7 @@ import {
|
|||||||
ZSuccessfulGetTemplateResponseSchema,
|
ZSuccessfulGetTemplateResponseSchema,
|
||||||
ZSuccessfulGetTemplatesResponseSchema,
|
ZSuccessfulGetTemplatesResponseSchema,
|
||||||
ZSuccessfulRecipientResponseSchema,
|
ZSuccessfulRecipientResponseSchema,
|
||||||
|
ZSuccessfulResendDocumentResponseSchema,
|
||||||
ZSuccessfulResponseSchema,
|
ZSuccessfulResponseSchema,
|
||||||
ZSuccessfulSigningResponseSchema,
|
ZSuccessfulSigningResponseSchema,
|
||||||
ZUnsuccessfulResponseSchema,
|
ZUnsuccessfulResponseSchema,
|
||||||
@@ -161,6 +163,20 @@ export const ApiContractV1 = c.router(
|
|||||||
summary: 'Send a document for signing',
|
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: {
|
deleteDocument: {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
path: '/api/v1/documents/:id',
|
path: '/api/v1/documents/:id',
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import { createDocument } from '@documenso/lib/server-only/document/create-docum
|
|||||||
import { deleteDocument } from '@documenso/lib/server-only/document/delete-document';
|
import { deleteDocument } from '@documenso/lib/server-only/document/delete-document';
|
||||||
import { findDocuments } from '@documenso/lib/server-only/document/find-documents';
|
import { findDocuments } from '@documenso/lib/server-only/document/find-documents';
|
||||||
import { getDocumentById } from '@documenso/lib/server-only/document/get-document-by-id';
|
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 { sendDocument } from '@documenso/lib/server-only/document/send-document';
|
||||||
import { updateDocument } from '@documenso/lib/server-only/document/update-document';
|
import { updateDocument } from '@documenso/lib/server-only/document/update-document';
|
||||||
import { createField } from '@documenso/lib/server-only/field/create-field';
|
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) => {
|
createRecipient: authenticatedMiddleware(async (args, user, team) => {
|
||||||
const { id: documentId } = args.params;
|
const { id: documentId } = args.params;
|
||||||
const { name, email, role } = args.body;
|
const { name, email, role } = args.body;
|
||||||
|
|||||||
@@ -57,6 +57,20 @@ export const ZSendDocumentForSigningMutationSchema = z
|
|||||||
|
|
||||||
export type TSendDocumentForSigningMutationSchema = typeof ZSendDocumentForSigningMutationSchema;
|
export 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({
|
export const ZUploadDocumentSuccessfulSchema = z.object({
|
||||||
url: z.string(),
|
url: z.string(),
|
||||||
key: z.string(),
|
key: z.string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user