Files
documenso/packages/lib/server-only/document/get-document-by-id.ts
David Nguyen 9d626473c8 feat: wip
2023-12-27 13:04:24 +11:00

38 lines
673 B
TypeScript

import { prisma } from '@documenso/prisma';
export interface GetDocumentByIdOptions {
id: number;
userId: number;
}
export const getDocumentById = async ({ id, userId }: GetDocumentByIdOptions) => {
return await prisma.document.findFirstOrThrow({
where: {
id,
userId,
OR: [
{
team: {
is: null,
},
},
{
team: {
is: {
members: {
some: {
userId,
},
},
},
},
},
],
},
include: {
documentData: true,
documentMeta: true,
},
});
};