mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
feat: enhance document schema and update attachment handling
- Added attachments support to ZCreateDocumentMutationSchema and ZUpdateDocumentRequestSchema. - Updated ZDocumentSchema to validate attachments with specific fields. - Modified updateDocument function to handle attachment creation and deletion. - Enhanced AddSettingsFormSchema to include attachments with proper validation.
This commit is contained in:
@ -24,6 +24,7 @@ import {
|
||||
} from '@documenso/lib/types/document-auth';
|
||||
import { ZDocumentEmailSettingsSchema } from '@documenso/lib/types/document-email';
|
||||
import { ZFieldMetaPrefillFieldsSchema, ZFieldMetaSchema } from '@documenso/lib/types/field-meta';
|
||||
import { AttachmentSchema } from '@documenso/prisma/generated/zod/modelSchema/AttachmentSchema';
|
||||
|
||||
extendZodWithOpenApi(z);
|
||||
|
||||
@ -176,6 +177,13 @@ export const ZCreateDocumentMutationSchema = z.object({
|
||||
description: 'The globalActionAuth property is only available for Enterprise accounts.',
|
||||
}),
|
||||
formValues: z.record(z.string(), z.union([z.string(), z.boolean(), z.number()])).optional(),
|
||||
attachments: AttachmentSchema.pick({
|
||||
id: true,
|
||||
label: true,
|
||||
url: true,
|
||||
})
|
||||
.array()
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type TCreateDocumentMutationSchema = z.infer<typeof ZCreateDocumentMutationSchema>;
|
||||
|
||||
@ -8,6 +8,7 @@ import type { ApiRequestMetadata } from '@documenso/lib/universal/extract-reques
|
||||
import type { CreateDocumentAuditLogDataResponse } from '@documenso/lib/utils/document-audit-logs';
|
||||
import { createDocumentAuditLogData } from '@documenso/lib/utils/document-audit-logs';
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import type { Attachment } from '@documenso/prisma/generated/zod/modelSchema/AttachmentSchema';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
import type { TDocumentAccessAuthTypes, TDocumentActionAuthTypes } from '../../types/document-auth';
|
||||
@ -24,6 +25,7 @@ export type UpdateDocumentOptions = {
|
||||
globalAccessAuth?: TDocumentAccessAuthTypes | null;
|
||||
globalActionAuth?: TDocumentActionAuthTypes | null;
|
||||
useLegacyFieldInsertion?: boolean;
|
||||
attachments?: Pick<Attachment, 'id' | 'label' | 'url'>[];
|
||||
};
|
||||
requestMetadata: ApiRequestMetadata;
|
||||
};
|
||||
@ -258,6 +260,15 @@ export const updateDocument = async ({
|
||||
visibility: data.visibility as DocumentVisibility,
|
||||
useLegacyFieldInsertion: data.useLegacyFieldInsertion,
|
||||
authOptions,
|
||||
attachments: {
|
||||
deleteMany: {},
|
||||
create:
|
||||
data.attachments?.map((attachment) => ({
|
||||
type: 'LINK',
|
||||
label: attachment.label,
|
||||
url: attachment.url,
|
||||
})) || [],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@ -60,7 +60,14 @@ export const ZDocumentSchema = DocumentSchema.pick({
|
||||
}).nullable(),
|
||||
recipients: ZRecipientLiteSchema.array(),
|
||||
fields: ZFieldSchema.array(),
|
||||
attachments: AttachmentSchema.array(),
|
||||
attachments: AttachmentSchema.pick({
|
||||
id: true,
|
||||
type: true,
|
||||
label: true,
|
||||
url: true,
|
||||
})
|
||||
.array()
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type TDocument = z.infer<typeof ZDocumentSchema>;
|
||||
|
||||
@ -8,6 +8,7 @@ import {
|
||||
ZDocumentActionAuthTypesSchema,
|
||||
} from '@documenso/lib/types/document-auth';
|
||||
import { ZDocumentEmailSettingsSchema } from '@documenso/lib/types/document-email';
|
||||
import AttachmentSchema from '@documenso/prisma/generated/zod/modelSchema/AttachmentSchema';
|
||||
|
||||
import type { TrpcRouteMeta } from '../trpc';
|
||||
import {
|
||||
@ -45,6 +46,13 @@ export const ZUpdateDocumentRequestSchema = z.object({
|
||||
globalAccessAuth: ZDocumentAccessAuthTypesSchema.nullish(),
|
||||
globalActionAuth: ZDocumentActionAuthTypesSchema.nullish(),
|
||||
useLegacyFieldInsertion: z.boolean().optional(),
|
||||
attachments: AttachmentSchema.pick({
|
||||
id: true,
|
||||
label: true,
|
||||
url: true,
|
||||
})
|
||||
.array()
|
||||
.optional(),
|
||||
})
|
||||
.optional(),
|
||||
meta: z
|
||||
|
||||
@ -147,6 +147,8 @@ export const AddSettingsFormPartial = ({
|
||||
formId: nanoid(12),
|
||||
label: '',
|
||||
url: '',
|
||||
// fix this
|
||||
id: '',
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
ZDocumentActionAuthTypesSchema,
|
||||
} from '@documenso/lib/types/document-auth';
|
||||
import { isValidRedirectUrl } from '@documenso/lib/utils/is-valid-redirect-url';
|
||||
import { AttachmentSchema } from '@documenso/prisma/generated/zod/modelSchema/AttachmentSchema';
|
||||
import {
|
||||
ZDocumentMetaDateFormatSchema,
|
||||
ZDocumentMetaTimezoneSchema,
|
||||
@ -58,13 +59,16 @@ export const ZAddSettingsFormSchema = z.object({
|
||||
message: msg`At least one signature type must be enabled`.id,
|
||||
}),
|
||||
}),
|
||||
attachments: z.array(
|
||||
z.object({
|
||||
attachments: AttachmentSchema.pick({
|
||||
id: true,
|
||||
label: true,
|
||||
url: true,
|
||||
})
|
||||
.extend({
|
||||
formId: z.string().min(1),
|
||||
label: z.string(),
|
||||
link: z.string(),
|
||||
}),
|
||||
),
|
||||
})
|
||||
.array()
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type TAddSettingsFormSchema = z.infer<typeof ZAddSettingsFormSchema>;
|
||||
|
||||
Reference in New Issue
Block a user