feat: update createFields api endpoint (#1311)

Allow users to add 1 or more fields to a document via the /document/<id>/fields API Endpoint.
This commit is contained in:
Catalin Pit
2024-09-02 14:16:48 +03:00
committed by GitHub
parent d599ab0630
commit 4c13176c52
5 changed files with 200 additions and 97 deletions

View File

@@ -293,7 +293,7 @@ export type TSuccessfulRecipientResponseSchema = z.infer<typeof ZSuccessfulRecip
/**
* Fields
*/
export const ZCreateFieldMutationSchema = z.object({
const ZCreateFieldSchema = z.object({
recipientId: z.number(),
type: z.nativeEnum(FieldType),
pageNumber: z.number(),
@@ -301,12 +301,17 @@ export const ZCreateFieldMutationSchema = z.object({
pageY: z.number(),
pageWidth: z.number(),
pageHeight: z.number(),
fieldMeta: ZFieldMetaSchema,
fieldMeta: ZFieldMetaSchema.openapi({}),
});
export const ZCreateFieldMutationSchema = z.union([
ZCreateFieldSchema,
z.array(ZCreateFieldSchema).min(1),
]);
export type TCreateFieldMutationSchema = z.infer<typeof ZCreateFieldMutationSchema>;
export const ZUpdateFieldMutationSchema = ZCreateFieldMutationSchema.partial();
export const ZUpdateFieldMutationSchema = ZCreateFieldSchema.partial();
export type TUpdateFieldMutationSchema = z.infer<typeof ZUpdateFieldMutationSchema>;
@@ -314,6 +319,26 @@ export const ZDeleteFieldMutationSchema = null;
export type TDeleteFieldMutationSchema = typeof ZDeleteFieldMutationSchema;
const ZSuccessfulFieldSchema = z.object({
id: z.number(),
documentId: z.number(),
recipientId: z.number(),
type: z.nativeEnum(FieldType),
pageNumber: z.number(),
pageX: z.number(),
pageY: z.number(),
pageWidth: z.number(),
pageHeight: z.number(),
customText: z.string(),
fieldMeta: ZFieldMetaSchema,
inserted: z.boolean(),
});
export const ZSuccessfulFieldCreationResponseSchema = z.object({
fields: z.union([ZSuccessfulFieldSchema, z.array(ZSuccessfulFieldSchema)]),
documentId: z.number(),
});
export const ZSuccessfulFieldResponseSchema = z.object({
id: z.number(),
documentId: z.number(),