mirror of
https://github.com/documenso/documenso.git
synced 2025-11-16 01:32:06 +10:00
feat: extend use envelope response (#2192)
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { updateDocumentMeta } from '@documenso/lib/server-only/document-meta/upsert-document-meta';
|
||||
import { sendDocument } from '@documenso/lib/server-only/document/send-document';
|
||||
import { formatSigningLink } from '@documenso/lib/utils/recipients';
|
||||
|
||||
import { ZGenericSuccessResponse } from '../schema';
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import {
|
||||
ZDistributeEnvelopeRequestSchema,
|
||||
@ -45,7 +45,7 @@ export const distributeEnvelopeRoute = authenticatedProcedure
|
||||
});
|
||||
}
|
||||
|
||||
await sendDocument({
|
||||
const envelope = await sendDocument({
|
||||
userId: ctx.user.id,
|
||||
id: {
|
||||
type: 'envelopeId',
|
||||
@ -55,5 +55,17 @@ export const distributeEnvelopeRoute = authenticatedProcedure
|
||||
requestMetadata: ctx.metadata,
|
||||
});
|
||||
|
||||
return ZGenericSuccessResponse;
|
||||
return {
|
||||
success: true,
|
||||
id: envelope.id,
|
||||
recipients: envelope.recipients.map((recipient) => ({
|
||||
id: recipient.id,
|
||||
name: recipient.name,
|
||||
email: recipient.email,
|
||||
token: recipient.token,
|
||||
role: recipient.role,
|
||||
signingOrder: recipient.signingOrder,
|
||||
signingUrl: formatSigningLink(recipient.token),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
@ -4,6 +4,7 @@ import { ZDocumentMetaUpdateSchema } from '@documenso/lib/types/document-meta';
|
||||
|
||||
import { ZSuccessResponseSchema } from '../schema';
|
||||
import type { TrpcRouteMeta } from '../trpc';
|
||||
import { ZRecipientWithSigningUrlSchema } from './schema';
|
||||
|
||||
export const distributeEnvelopeMeta: TrpcRouteMeta = {
|
||||
openapi: {
|
||||
@ -31,7 +32,10 @@ export const ZDistributeEnvelopeRequestSchema = z.object({
|
||||
}).optional(),
|
||||
});
|
||||
|
||||
export const ZDistributeEnvelopeResponseSchema = ZSuccessResponseSchema;
|
||||
export const ZDistributeEnvelopeResponseSchema = ZSuccessResponseSchema.extend({
|
||||
id: z.string().describe('The ID of the envelope that was sent.'),
|
||||
recipients: ZRecipientWithSigningUrlSchema.array(),
|
||||
});
|
||||
|
||||
export type TDistributeEnvelopeRequest = z.infer<typeof ZDistributeEnvelopeRequestSchema>;
|
||||
export type TDistributeEnvelopeResponse = z.infer<typeof ZDistributeEnvelopeResponseSchema>;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { resendDocument } from '@documenso/lib/server-only/document/resend-document';
|
||||
import { formatSigningLink } from '@documenso/lib/utils/recipients';
|
||||
|
||||
import { ZGenericSuccessResponse } from '../schema';
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import {
|
||||
ZRedistributeEnvelopeRequestSchema,
|
||||
@ -23,7 +23,7 @@ export const redistributeEnvelopeRoute = authenticatedProcedure
|
||||
},
|
||||
});
|
||||
|
||||
await resendDocument({
|
||||
const envelope = await resendDocument({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
id: {
|
||||
@ -34,5 +34,17 @@ export const redistributeEnvelopeRoute = authenticatedProcedure
|
||||
requestMetadata: ctx.metadata,
|
||||
});
|
||||
|
||||
return ZGenericSuccessResponse;
|
||||
return {
|
||||
success: true,
|
||||
id: envelope.id,
|
||||
recipients: envelope.recipients.map((recipient) => ({
|
||||
id: recipient.id,
|
||||
name: recipient.name,
|
||||
email: recipient.email,
|
||||
token: recipient.token,
|
||||
role: recipient.role,
|
||||
signingOrder: recipient.signingOrder,
|
||||
signingUrl: formatSigningLink(recipient.token),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
@ -2,6 +2,7 @@ import { z } from 'zod';
|
||||
|
||||
import { ZSuccessResponseSchema } from '../schema';
|
||||
import type { TrpcRouteMeta } from '../trpc';
|
||||
import { ZRecipientWithSigningUrlSchema } from './schema';
|
||||
|
||||
export const redistributeEnvelopeMeta: TrpcRouteMeta = {
|
||||
openapi: {
|
||||
@ -22,7 +23,10 @@ export const ZRedistributeEnvelopeRequestSchema = z.object({
|
||||
.describe('The IDs of the recipients to redistribute the envelope to.'),
|
||||
});
|
||||
|
||||
export const ZRedistributeEnvelopeResponseSchema = ZSuccessResponseSchema;
|
||||
export const ZRedistributeEnvelopeResponseSchema = ZSuccessResponseSchema.extend({
|
||||
id: z.string().describe('The ID of the envelope that was redistributed.'),
|
||||
recipients: ZRecipientWithSigningUrlSchema.array(),
|
||||
});
|
||||
|
||||
export type TRedistributeEnvelopeRequest = z.infer<typeof ZRedistributeEnvelopeRequestSchema>;
|
||||
export type TRedistributeEnvelopeResponse = z.infer<typeof ZRedistributeEnvelopeResponseSchema>;
|
||||
|
||||
16
packages/trpc/server/envelope-router/schema.ts
Normal file
16
packages/trpc/server/envelope-router/schema.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import RecipientSchema from '@documenso/prisma/generated/zod/modelSchema/RecipientSchema';
|
||||
|
||||
// Common schemas between envelope routes.
|
||||
|
||||
export const ZRecipientWithSigningUrlSchema = RecipientSchema.pick({
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
token: true,
|
||||
role: true,
|
||||
signingOrder: true,
|
||||
}).extend({
|
||||
signingUrl: z.string().describe('The URL which the recipient uses to sign the document.'),
|
||||
});
|
||||
@ -6,6 +6,7 @@ import { sendDocument } from '@documenso/lib/server-only/document/send-document'
|
||||
import { getEnvelopeById } from '@documenso/lib/server-only/envelope/get-envelope-by-id';
|
||||
import { createDocumentFromTemplate } from '@documenso/lib/server-only/template/create-document-from-template';
|
||||
import { putNormalizedPdfFileServerSide } from '@documenso/lib/universal/upload/put-file.server';
|
||||
import { formatSigningLink } from '@documenso/lib/utils/recipients';
|
||||
|
||||
import { authenticatedProcedure } from '../trpc';
|
||||
import {
|
||||
@ -26,7 +27,7 @@ export const useEnvelopeRoute = authenticatedProcedure
|
||||
const {
|
||||
envelopeId,
|
||||
externalId,
|
||||
recipients,
|
||||
recipients = [],
|
||||
distributeDocument,
|
||||
customDocumentData = [],
|
||||
folderId,
|
||||
@ -166,5 +167,14 @@ export const useEnvelopeRoute = authenticatedProcedure
|
||||
|
||||
return {
|
||||
id: createdEnvelope.id,
|
||||
recipients: createdEnvelope.recipients.map((recipient) => ({
|
||||
id: recipient.id,
|
||||
name: recipient.name,
|
||||
email: recipient.email,
|
||||
token: recipient.token,
|
||||
role: recipient.role,
|
||||
signingOrder: recipient.signingOrder,
|
||||
signingUrl: formatSigningLink(recipient.token),
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
@ -19,6 +19,7 @@ import { ZFieldMetaPrefillFieldsSchema } from '@documenso/lib/types/field-meta';
|
||||
|
||||
import { zodFormData } from '../../utils/zod-form-data';
|
||||
import type { TrpcRouteMeta } from '../trpc';
|
||||
import { ZRecipientWithSigningUrlSchema } from './schema';
|
||||
|
||||
export const useEnvelopeMeta: TrpcRouteMeta = {
|
||||
openapi: {
|
||||
@ -44,7 +45,8 @@ export const ZUseEnvelopePayloadSchema = z.object({
|
||||
signingOrder: z.number().optional(),
|
||||
}),
|
||||
)
|
||||
.describe('The information of the recipients to create the document with.'),
|
||||
.describe('The information of the recipients to create the document with.')
|
||||
.optional(),
|
||||
distributeDocument: z
|
||||
.boolean()
|
||||
.describe('Whether to create the document as pending and distribute it to recipients.')
|
||||
@ -114,6 +116,7 @@ export const ZUseEnvelopeRequestSchema = zodFormData({
|
||||
|
||||
export const ZUseEnvelopeResponseSchema = z.object({
|
||||
id: z.string().describe('The ID of the created envelope.'),
|
||||
recipients: ZRecipientWithSigningUrlSchema.array(),
|
||||
});
|
||||
|
||||
export type TUseEnvelopePayload = z.infer<typeof ZUseEnvelopePayloadSchema>;
|
||||
|
||||
Reference in New Issue
Block a user