mirror of
https://github.com/documenso/documenso.git
synced 2025-11-12 15:53:02 +10:00
fix: refactor routers (#1523)
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getFieldById } from '@documenso/lib/server-only/field/get-field-by-id';
|
||||
import { removeSignedFieldWithToken } from '@documenso/lib/server-only/field/remove-signed-field-with-token';
|
||||
import { setFieldsForDocument } from '@documenso/lib/server-only/field/set-fields-for-document';
|
||||
@ -15,8 +17,39 @@ import {
|
||||
} from './schema';
|
||||
|
||||
export const fieldRouter = router({
|
||||
getField: authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'GET',
|
||||
path: '/field/{fieldId}',
|
||||
summary: 'Get field',
|
||||
description: 'Returns a document or template field',
|
||||
tags: ['Fields'],
|
||||
},
|
||||
})
|
||||
.input(ZGetFieldQuerySchema)
|
||||
.output(z.unknown())
|
||||
.query(async ({ input, ctx }) => {
|
||||
const { fieldId, teamId } = input;
|
||||
|
||||
return await getFieldById({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
fieldId,
|
||||
});
|
||||
}),
|
||||
|
||||
addFields: authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/document/{documentId}/field',
|
||||
summary: 'Set document fields',
|
||||
tags: ['Fields'],
|
||||
},
|
||||
})
|
||||
.input(ZAddFieldsMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { documentId, fields } = input;
|
||||
|
||||
@ -39,7 +72,16 @@ export const fieldRouter = router({
|
||||
}),
|
||||
|
||||
addTemplateFields: authenticatedProcedure
|
||||
.meta({
|
||||
openapi: {
|
||||
method: 'POST',
|
||||
path: '/template/{templateId}/field',
|
||||
summary: 'Set template fields',
|
||||
tags: ['Fields'],
|
||||
},
|
||||
})
|
||||
.input(ZAddTemplateFieldsMutationSchema)
|
||||
.output(z.unknown())
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
const { templateId, fields } = input;
|
||||
|
||||
@ -60,6 +102,7 @@ export const fieldRouter = router({
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
signFieldWithToken: procedure
|
||||
.input(ZSignFieldWithTokenMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
@ -76,6 +119,7 @@ export const fieldRouter = router({
|
||||
});
|
||||
}),
|
||||
|
||||
// Internal endpoint for now.
|
||||
removeSignedFieldWithToken: procedure
|
||||
.input(ZRemovedSignedFieldWithTokenMutationSchema)
|
||||
.mutation(async ({ input, ctx }) => {
|
||||
@ -87,40 +131,4 @@ export const fieldRouter = router({
|
||||
requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
||||
});
|
||||
}),
|
||||
|
||||
getField: authenticatedProcedure.input(ZGetFieldQuerySchema).query(async ({ input, ctx }) => {
|
||||
const { fieldId, teamId } = input;
|
||||
|
||||
return await getFieldById({
|
||||
userId: ctx.user.id,
|
||||
teamId,
|
||||
fieldId,
|
||||
});
|
||||
}),
|
||||
|
||||
// This doesn't appear to be used anywhere, and it doesn't seem to support updating template fields
|
||||
// so commenting this out for now.
|
||||
// updateField: authenticatedProcedure
|
||||
// .input(ZUpdateFieldMutationSchema)
|
||||
// .mutation(async ({ input, ctx }) => {
|
||||
// try {
|
||||
// const { documentId, fieldId, fieldMeta, teamId } = input;
|
||||
|
||||
// return await updateField({
|
||||
// userId: ctx.user.id,
|
||||
// teamId,
|
||||
// fieldId,
|
||||
// documentId,
|
||||
// requestMetadata: extractNextApiRequestMetadata(ctx.req),
|
||||
// fieldMeta: fieldMeta,
|
||||
// });
|
||||
// } catch (err) {
|
||||
// console.error(err);
|
||||
|
||||
// throw new TRPCError({
|
||||
// code: 'BAD_REQUEST',
|
||||
// message: 'We were unable to set this field. Please try again later.',
|
||||
// });
|
||||
// }
|
||||
// }),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user