This commit is contained in:
David Nguyen
2025-05-07 15:03:20 +10:00
parent 419bc02171
commit 7abfc9e271
390 changed files with 21254 additions and 12607 deletions

View File

@ -1,6 +1,9 @@
import type { Field } from '@prisma/client';
import { prisma } from '@documenso/prisma';
import { AppError, AppErrorCode } from '../../errors/app-error';
import { buildTeamWhereQuery } from '../../utils/teams';
export type GetFieldByIdOptions = {
userId: number;
@ -17,35 +20,31 @@ export const getFieldById = async ({
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,
},
},
},
},
],
let field: Field | null = null;
if (documentId) {
field = await prisma.field.findFirst({
where: {
id: fieldId,
document: {
id: documentId,
team: buildTeamWhereQuery(teamId, userId),
},
},
},
});
});
}
if (templateId) {
field = await prisma.field.findFirst({
where: {
id: fieldId,
template: {
id: templateId,
team: buildTeamWhereQuery(teamId, userId),
},
},
});
}
if (!field) {
throw new AppError(AppErrorCode.NOT_FOUND, {