mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
feat: add trpc openapi (#1535)
This commit is contained in:
@ -1,4 +1,9 @@
|
||||
import type { z } from 'zod';
|
||||
|
||||
import { prisma } from '@documenso/prisma';
|
||||
import { FieldSchema } from '@documenso/prisma/generated/zod';
|
||||
|
||||
import { AppError, AppErrorCode } from '../../errors/app-error';
|
||||
|
||||
export type GetFieldByIdOptions = {
|
||||
userId: number;
|
||||
@ -8,13 +13,17 @@ export type GetFieldByIdOptions = {
|
||||
templateId?: number;
|
||||
};
|
||||
|
||||
export const ZGetFieldByIdResponseSchema = FieldSchema;
|
||||
|
||||
export type TGetFieldByIdResponse = z.infer<typeof ZGetFieldByIdResponseSchema>;
|
||||
|
||||
export const getFieldById = async ({
|
||||
userId,
|
||||
teamId,
|
||||
fieldId,
|
||||
documentId,
|
||||
templateId,
|
||||
}: GetFieldByIdOptions) => {
|
||||
}: GetFieldByIdOptions): Promise<TGetFieldByIdResponse> => {
|
||||
const field = await prisma.field.findFirst({
|
||||
where: {
|
||||
id: fieldId,
|
||||
@ -45,5 +54,11 @@ export const getFieldById = async ({
|
||||
},
|
||||
});
|
||||
|
||||
if (!field) {
|
||||
throw new AppError(AppErrorCode.NOT_FOUND, {
|
||||
message: 'Field not found',
|
||||
});
|
||||
}
|
||||
|
||||
return field;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user