2024-03-26 21:12:41 +08:00
|
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
|
import type { DocumentWithDetails } from '@documenso/prisma/types/document';
|
|
|
|
|
|
|
|
|
|
import { getDocumentWhereInput } from './get-document-by-id';
|
|
|
|
|
|
|
|
|
|
export type GetDocumentWithDetailsByIdOptions = {
|
2024-12-10 16:11:20 +09:00
|
|
|
documentId: number;
|
2024-03-26 21:12:41 +08:00
|
|
|
userId: number;
|
|
|
|
|
teamId?: number;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getDocumentWithDetailsById = async ({
|
2024-12-10 16:11:20 +09:00
|
|
|
documentId,
|
2024-03-26 21:12:41 +08:00
|
|
|
userId,
|
|
|
|
|
teamId,
|
|
|
|
|
}: GetDocumentWithDetailsByIdOptions): Promise<DocumentWithDetails> => {
|
|
|
|
|
const documentWhereInput = await getDocumentWhereInput({
|
2024-12-10 16:11:20 +09:00
|
|
|
documentId,
|
2024-03-26 21:12:41 +08:00
|
|
|
userId,
|
|
|
|
|
teamId,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return await prisma.document.findFirstOrThrow({
|
|
|
|
|
where: documentWhereInput,
|
|
|
|
|
include: {
|
|
|
|
|
documentData: true,
|
|
|
|
|
documentMeta: true,
|
|
|
|
|
Recipient: true,
|
|
|
|
|
Field: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|