Files
documenso/packages/lib/server-only/field/get-field-by-id.ts
Catalin Pit 7b5c57e8af chore: add more field types (#1141)
Adds a number of new field types and capabilities to existing fields.

A massive change with far too many moving pieces to document in a single commit.
2024-07-18 23:45:44 +10:00

50 lines
941 B
TypeScript

import { prisma } from '@documenso/prisma';
export type GetFieldByIdOptions = {
userId: number;
teamId?: number;
fieldId: number;
documentId?: number;
templateId?: number;
};
export const getFieldById = async ({
userId,
teamId,
fieldId,
documentId,
templateId,
}: GetFieldByIdOptions) => {
const field = await prisma.field.findFirst({
where: {
id: fieldId,
documentId,
templateId,
Document: {
OR:
teamId === undefined
? [
{
userId,
teamId: null,
},
]
: [
{
teamId,
team: {
members: {
some: {
userId,
},
},
},
},
],
},
},
});
return field;
};