fix: refactor api routes

This commit is contained in:
David Nguyen
2024-12-30 21:01:03 +11:00
parent df33fbf91b
commit 22665543c0
100 changed files with 2268 additions and 2303 deletions

View File

@ -0,0 +1,53 @@
import { z } from 'zod';
import { getTemplateById } from '@documenso/lib/server-only/template/get-template-by-id';
import {
DocumentDataSchema,
FieldSchema,
RecipientSchema,
TemplateDirectLinkSchema,
TemplateMetaSchema,
TemplateSchema,
UserSchema,
} from '@documenso/prisma/generated/zod';
import { authenticatedProcedure } from '../trpc';
export const ZGetTemplateRequestSchema = z.object({
templateId: z.number().min(1),
teamId: z.number().optional(),
});
export const ZGetTemplateResponseSchema = TemplateSchema.extend({
directLink: TemplateDirectLinkSchema.nullable(),
templateDocumentData: DocumentDataSchema,
templateMeta: TemplateMetaSchema.nullable(),
Recipient: RecipientSchema.array(),
Field: FieldSchema.array(),
User: UserSchema.pick({
id: true,
name: true,
email: true,
}),
});
export const getTemplateRoute = authenticatedProcedure
.meta({
openapi: {
method: 'GET',
path: '/template/{templateId}',
summary: 'Get template',
tags: ['Template'],
},
})
.input(ZGetTemplateRequestSchema)
.output(ZGetTemplateResponseSchema)
.query(async ({ input, ctx }) => {
const { templateId, teamId } = input;
return await getTemplateById({
id: templateId,
userId: ctx.user.id,
teamId,
});
});