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

@ -5,10 +5,8 @@ import {
} from "@documenso/lib/server";
import prisma from "@documenso/prisma";
import { NextApiRequest, NextApiResponse } from "next";
import { useRouter } from "next/router";
import fs from "fs";
import { buffer } from "stream/consumers";
import { Document as PrismaDocument } from "@prisma/client";
import { getDocument } from "@documenso/lib/query";
async function getHandler(req: NextApiRequest, res: NextApiResponse) {
const user = await getUserFromToken(req, res);
@ -21,10 +19,9 @@ async function getHandler(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,
});
if (!document)