feat: return fields in GET /documents/:id endpoint (#1317)

To be able to use the PATCH `/api/v1/documents/{id}/fields/{fieldId}`
endpoint, we need to know the fields ID of a particular document. The
issue #1178 suggested to create a new endpoint for this. To be
consistent with the `/templates` endpoint, I propose in this PR to
directly add the `fields` field to the `/documents/:id` endpoint.
This commit is contained in:
Etrenak
2024-12-05 23:03:32 +01:00
committed by GitHub
parent 9f45fe62e4
commit 67e49c82a3
2 changed files with 43 additions and 1 deletions

View File

@ -58,6 +58,22 @@ export const ZSuccessfulDocumentResponseSchema = z.object({
export const ZSuccessfulGetDocumentResponseSchema = ZSuccessfulDocumentResponseSchema.extend({
recipients: z.lazy(() => z.array(ZSuccessfulRecipientResponseSchema)),
fields: z.lazy(() =>
ZFieldSchema.pick({
id: true,
recipientId: true,
type: true,
page: true,
positionX: true,
positionY: true,
width: true,
height: true,
})
.extend({
fieldMeta: ZFieldMetaSchema.nullish(),
})
.array(),
),
});
export type TSuccessfulGetDocumentResponseSchema = z.infer<
@ -424,7 +440,7 @@ export const ZSuccessfulSigningResponseSchema = z
.object({
message: z.string(),
})
.and(ZSuccessfulGetDocumentResponseSchema);
.and(ZSuccessfulGetDocumentResponseSchema.omit({ fields: true }));
export type TSuccessfulSigningResponseSchema = z.infer<typeof ZSuccessfulSigningResponseSchema>;