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