getDocument refactor

This commit is contained in:
Timur Ercan
2023-02-01 18:32:59 +01:00
parent 99fffd1614
commit f4a6e3c8fc
9 changed files with 60 additions and 68 deletions

View File

@ -7,6 +7,7 @@ import prisma from "@documenso/prisma";
import { NextApiRequest, NextApiResponse } from "next";
import short from "short-uuid";
import { Document as PrismaDocument } from "@prisma/client";
import { getDocument } from "@documenso/lib/query";
async function postHandler(req: NextApiRequest, res: NextApiResponse) {
const user = await getUserFromToken(req, res);
@ -20,10 +21,9 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
return;
}
const document: PrismaDocument = await prisma.document.findFirstOrThrow({
where: {
id: +documentId,
},
const document: PrismaDocument = await getDocument(+documentId, {
res: res,
req: req,
});
// todo encapsulate entity ownerships