mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
fix: update template field schema (#1575)
Co-authored-by: Lucas Smith <me@lucasjamessmith.me>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { createNextRoute } from '@ts-rest/next';
|
||||
import { match } from 'ts-pattern';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getServerLimits } from '@documenso/ee/server-only/limits/server';
|
||||
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
||||
@ -36,10 +37,10 @@ import { deleteTemplate } from '@documenso/lib/server-only/template/delete-templ
|
||||
import { findTemplates } from '@documenso/lib/server-only/template/find-templates';
|
||||
import { getTemplateById } from '@documenso/lib/server-only/template/get-template-by-id';
|
||||
import { extractDerivedDocumentEmailSettings } from '@documenso/lib/types/document-email';
|
||||
import { ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
||||
import {
|
||||
ZCheckboxFieldMeta,
|
||||
ZDropdownFieldMeta,
|
||||
ZFieldMetaSchema,
|
||||
ZNumberFieldMeta,
|
||||
ZRadioFieldMeta,
|
||||
ZTextFieldMeta,
|
||||
@ -62,6 +63,7 @@ import {
|
||||
|
||||
import { ApiContractV1 } from './contract';
|
||||
import { authenticatedMiddleware } from './middleware/authenticated';
|
||||
import { ZTemplateWithDataSchema } from './schema';
|
||||
|
||||
export const ApiContractV1Implementation = createNextRoute(ApiContractV1, {
|
||||
getDocuments: authenticatedMiddleware(async (args, user, team) => {
|
||||
@ -414,9 +416,11 @@ export const ApiContractV1Implementation = createNextRoute(ApiContractV1, {
|
||||
teamId: team?.id,
|
||||
});
|
||||
|
||||
const parsed = ZTemplateWithDataSchema.parse(template);
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: template,
|
||||
body: parsed,
|
||||
};
|
||||
} catch (err) {
|
||||
return AppError.toRestAPIError(err);
|
||||
@ -435,10 +439,12 @@ export const ApiContractV1Implementation = createNextRoute(ApiContractV1, {
|
||||
teamId: team?.id,
|
||||
});
|
||||
|
||||
const parsed = z.array(ZTemplateWithDataSchema).parse(templates);
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
templates,
|
||||
templates: parsed,
|
||||
totalPages,
|
||||
},
|
||||
};
|
||||
|
||||
@ -61,6 +61,7 @@ export const ZSuccessfulGetDocumentResponseSchema = ZSuccessfulDocumentResponseS
|
||||
fields: z.lazy(() =>
|
||||
ZFieldSchema.pick({
|
||||
id: true,
|
||||
documentId: true,
|
||||
recipientId: true,
|
||||
type: true,
|
||||
page: true,
|
||||
@ -68,6 +69,8 @@ export const ZSuccessfulGetDocumentResponseSchema = ZSuccessfulDocumentResponseS
|
||||
positionY: true,
|
||||
width: true,
|
||||
height: true,
|
||||
customText: true,
|
||||
fieldMeta: true,
|
||||
})
|
||||
.extend({
|
||||
fieldMeta: ZFieldMetaSchema.nullish(),
|
||||
@ -524,6 +527,7 @@ export const ZFieldSchema = z.object({
|
||||
height: z.unknown(),
|
||||
customText: z.string(),
|
||||
inserted: z.boolean(),
|
||||
fieldMeta: ZFieldMetaSchema.nullish().openapi({}),
|
||||
});
|
||||
|
||||
export const ZTemplateWithDataSchema = ZTemplateSchema.extend({
|
||||
@ -541,6 +545,8 @@ export const ZTemplateWithDataSchema = ZTemplateSchema.extend({
|
||||
}),
|
||||
Field: ZFieldSchema.pick({
|
||||
id: true,
|
||||
documentId: true,
|
||||
templateId: true,
|
||||
recipientId: true,
|
||||
type: true,
|
||||
page: true,
|
||||
@ -548,6 +554,8 @@ export const ZTemplateWithDataSchema = ZTemplateSchema.extend({
|
||||
positionY: true,
|
||||
width: true,
|
||||
height: true,
|
||||
customText: true,
|
||||
fieldMeta: true,
|
||||
}).array(),
|
||||
Recipient: ZRecipientSchema.pick({
|
||||
id: true,
|
||||
|
||||
Reference in New Issue
Block a user