mirror of
https://github.com/documenso/documenso.git
synced 2025-11-20 11:41:44 +10:00
fix: wip
This commit is contained in:
@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user