2023-02-01 18:32:59 +01:00
|
|
|
import { getUserFromToken } from "@documenso/lib/server";
|
|
|
|
|
import prisma from "@documenso/prisma";
|
|
|
|
|
import { Document as PrismaDocument } from "@prisma/client";
|
|
|
|
|
|
|
|
|
|
export const getDocument = async (
|
|
|
|
|
documentId: number,
|
2023-02-01 19:15:43 +01:00
|
|
|
req: any,
|
|
|
|
|
res: any
|
2023-02-01 18:32:59 +01:00
|
|
|
): Promise<PrismaDocument> => {
|
2023-02-01 19:15:43 +01:00
|
|
|
const user = await getUserFromToken(req, res);
|
2023-02-01 18:32:59 +01:00
|
|
|
if (!user) return Promise.reject("Invalid user or token.");
|
|
|
|
|
if (!documentId) Promise.reject("No documentId");
|
2023-02-01 19:15:43 +01:00
|
|
|
if (!req || !res) Promise.reject("No res or req");
|
2023-02-01 18:32:59 +01:00
|
|
|
|
|
|
|
|
const document: PrismaDocument = await prisma.document.findFirstOrThrow({
|
|
|
|
|
where: {
|
|
|
|
|
id: documentId,
|
|
|
|
|
userId: user.id,
|
|
|
|
|
},
|
|
|
|
|
include: {
|
|
|
|
|
Recipient: true,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return document;
|
|
|
|
|
};
|