mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
feat: add formdata endpoints for documents,envelopes,templates
Adds the missing endpoints for documents, envelopes and templates supporting file uploads in a singular request. Also updates frontend components that would use the prior hidden endpoints.
This commit is contained in:
@ -21,6 +21,7 @@ import { deleteTemplateDirectLink } from '@documenso/lib/server-only/template/de
|
||||
import { findTemplates } from '@documenso/lib/server-only/template/find-templates';
|
||||
import { getTemplateById } from '@documenso/lib/server-only/template/get-template-by-id';
|
||||
import { toggleTemplateDirectLink } from '@documenso/lib/server-only/template/toggle-template-direct-link';
|
||||
import { putNormalizedPdfFileServerSide } from '@documenso/lib/universal/upload/put-file.server';
|
||||
import { getPresignPostUrl } from '@documenso/lib/universal/upload/server-actions';
|
||||
import { mapSecondaryIdToTemplateId } from '@documenso/lib/utils/envelope';
|
||||
import { mapFieldToLegacyField } from '@documenso/lib/utils/fields';
|
||||
@ -159,20 +160,27 @@ export const templateRouter = router({
|
||||
* @private
|
||||
*/
|
||||
createTemplate: authenticatedProcedure
|
||||
// .meta({ // Note before releasing this to public, update the response schema to be correct.
|
||||
// openapi: {
|
||||
// method: 'POST',
|
||||
// path: '/template/create',
|
||||
// summary: 'Create template',
|
||||
// description: 'Create a new template',
|
||||
// tags: ['Template'],
|
||||
// },
|
||||
// })
|
||||
.meta({
|
||||
// Note before releasing this to public, update the response schema to be correct.
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/template/create',
|
||||
contentTypes: ['multipart/form-data'],
|
||||
summary: 'Create template',
|
||||
description: 'Create a new template',
|
||||
tags: ['Template'],
|
||||
},
|
||||
})
|
||||
.input(ZCreateTemplateMutationSchema)
|
||||
.output(ZCreateTemplateResponseSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { teamId } = ctx;
|
||||
const { title, templateDocumentDataId, folderId } = input;
|
||||
|
||||
const { payload, file } = input;
|
||||
|
||||
const { title, folderId } = payload;
|
||||
|
||||
const { id: templateDocumentDataId } = await putNormalizedPdfFileServerSide(file);
|
||||
|
||||
ctx.logger.info({
|
||||
input: {
|
||||
@ -198,6 +206,7 @@ export const templateRouter = router({
|
||||
});
|
||||
|
||||
return {
|
||||
envelopeId: envelope.id,
|
||||
legacyTemplateId: mapSecondaryIdToTemplateId(envelope.secondaryId),
|
||||
};
|
||||
}),
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { DocumentSigningOrder, DocumentVisibility, TemplateType } from '@prisma/client';
|
||||
import { z } from 'zod';
|
||||
import { zfd } from 'zod-form-data';
|
||||
|
||||
import { ZDocumentSchema } from '@documenso/lib/types/document';
|
||||
import {
|
||||
@ -29,6 +30,7 @@ import {
|
||||
} from '@documenso/lib/types/template';
|
||||
import { LegacyTemplateDirectLinkSchema } from '@documenso/prisma/types/template-legacy-schema';
|
||||
|
||||
import { zodFormData } from '../../utils/zod-form-data';
|
||||
import { ZSignFieldWithTokenMutationSchema } from '../field-router/schema';
|
||||
|
||||
export const MAX_TEMPLATE_PUBLIC_TITLE_LENGTH = 50;
|
||||
@ -77,12 +79,16 @@ export const ZTemplateMetaUpsertSchema = z.object({
|
||||
allowDictateNextSigner: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const ZCreateTemplateMutationSchema = z.object({
|
||||
export const ZCreateTemplatePayloadSchema = z.object({
|
||||
title: z.string().min(1).trim(),
|
||||
templateDocumentDataId: z.string().min(1),
|
||||
folderId: z.string().optional(),
|
||||
});
|
||||
|
||||
export const ZCreateTemplateMutationSchema = zodFormData({
|
||||
payload: zfd.json(ZCreateTemplatePayloadSchema),
|
||||
file: zfd.file(),
|
||||
});
|
||||
|
||||
export const ZCreateDocumentFromDirectTemplateRequestSchema = z.object({
|
||||
directRecipientName: z.string().max(255).optional(),
|
||||
directRecipientEmail: z.string().email().max(254),
|
||||
@ -224,6 +230,7 @@ export const ZCreateTemplateV2ResponseSchema = z.object({
|
||||
});
|
||||
|
||||
export const ZCreateTemplateResponseSchema = z.object({
|
||||
envelopeId: z.string(),
|
||||
legacyTemplateId: z.number(),
|
||||
});
|
||||
|
||||
@ -273,6 +280,7 @@ export const ZBulkSendTemplateMutationSchema = z.object({
|
||||
sendImmediately: z.boolean(),
|
||||
});
|
||||
|
||||
export type TCreateTemplatePayloadSchema = z.infer<typeof ZCreateTemplatePayloadSchema>;
|
||||
export type TCreateTemplateMutationSchema = z.infer<typeof ZCreateTemplateMutationSchema>;
|
||||
export type TDuplicateTemplateMutationSchema = z.infer<typeof ZDuplicateTemplateMutationSchema>;
|
||||
export type TDeleteTemplateMutationSchema = z.infer<typeof ZDeleteTemplateMutationSchema>;
|
||||
|
||||
Reference in New Issue
Block a user