mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 16:23:06 +10:00
48 lines
981 B
TypeScript
48 lines
981 B
TypeScript
import { prisma } from '@documenso/prisma';
|
|
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
import { getDocumentWhereInput } from './get-document-by-id';
|
|
|
|
export type GetDocumentWithDetailsByIdOptions = {
|
|
documentId: number;
|
|
userId: number;
|
|
teamId?: number;
|
|
folderId?: string;
|
|
};
|
|
|
|
export const getDocumentWithDetailsById = async ({
|
|
documentId,
|
|
userId,
|
|
teamId,
|
|
folderId,
|
|
}: GetDocumentWithDetailsByIdOptions) => {
|
|
const documentWhereInput = await getDocumentWhereInput({
|
|
documentId,
|
|
userId,
|
|
teamId,
|
|
});
|
|
|
|
const document = await prisma.document.findFirst({
|
|
where: {
|
|
...documentWhereInput,
|
|
folderId,
|
|
},
|
|
include: {
|
|
documentData: true,
|
|
documentMeta: true,
|
|
recipients: true,
|
|
fields: true,
|
|
attachments: true,
|
|
folder: true,
|
|
},
|
|
});
|
|
|
|
if (!document) {
|
|
throw new AppError(AppErrorCode.NOT_FOUND, {
|
|
message: 'Document not found',
|
|
});
|
|
}
|
|
|
|
return document;
|
|
};
|