mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
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:
@ -110,24 +110,21 @@ export const createField = async ({
|
||||
}
|
||||
|
||||
const result = match(type)
|
||||
.with('RADIO', () => {
|
||||
return ZRadioFieldMeta.safeParse(fieldMeta);
|
||||
})
|
||||
.with('CHECKBOX', () => {
|
||||
return ZCheckboxFieldMeta.safeParse(fieldMeta);
|
||||
})
|
||||
.with('DROPDOWN', () => {
|
||||
return ZDropdownFieldMeta.safeParse(fieldMeta);
|
||||
})
|
||||
.with('NUMBER', () => {
|
||||
return ZNumberFieldMeta.safeParse(fieldMeta);
|
||||
})
|
||||
.with('TEXT', () => {
|
||||
return ZTextFieldMeta.safeParse(fieldMeta);
|
||||
})
|
||||
.otherwise(() => {
|
||||
return { success: false, data: {} };
|
||||
});
|
||||
.with('RADIO', () => ZRadioFieldMeta.safeParse(fieldMeta))
|
||||
.with('CHECKBOX', () => ZCheckboxFieldMeta.safeParse(fieldMeta))
|
||||
.with('DROPDOWN', () => ZDropdownFieldMeta.safeParse(fieldMeta))
|
||||
.with('NUMBER', () => ZNumberFieldMeta.safeParse(fieldMeta))
|
||||
.with('TEXT', () => ZTextFieldMeta.safeParse(fieldMeta))
|
||||
.with('SIGNATURE', 'INITIALS', 'DATE', 'EMAIL', 'NAME', () => ({
|
||||
success: true,
|
||||
data: {},
|
||||
}))
|
||||
.with('FREE_SIGNATURE', () => ({
|
||||
success: false,
|
||||
error: 'FREE_SIGNATURE is not supported',
|
||||
data: {},
|
||||
}))
|
||||
.exhaustive();
|
||||
|
||||
if (!result.success) {
|
||||
throw new Error('Field meta parsing failed');
|
||||
@ -145,7 +142,7 @@ export const createField = async ({
|
||||
height: pageHeight,
|
||||
customText: '',
|
||||
inserted: false,
|
||||
fieldMeta: advancedField ? result.data : undefined,
|
||||
fieldMeta: result.data,
|
||||
},
|
||||
include: {
|
||||
Recipient: true,
|
||||
|
||||
@ -37,6 +37,10 @@ export const updateField = async ({
|
||||
requestMetadata,
|
||||
fieldMeta,
|
||||
}: UpdateFieldOptions) => {
|
||||
if (type === 'FREE_SIGNATURE') {
|
||||
throw new Error('Cannot update a FREE_SIGNATURE field');
|
||||
}
|
||||
|
||||
const oldField = await prisma.field.findFirstOrThrow({
|
||||
where: {
|
||||
id: fieldId,
|
||||
|
||||
Reference in New Issue
Block a user