Files
sign/apps/web/pages/api/documents/index.ts
Timur Ercan 29f992b59c oos
2023-01-20 14:55:45 +01:00

34 lines
956 B
TypeScript

import { defaultHandler, defaultResponder } from "@documenso/lib/server";
import prisma from "@documenso/prisma";
import { NextApiRequest, NextApiResponse } from "next";
import { getUserFromToken } from "@documenso/lib/server";
async function postHandler(req: NextApiRequest, res: NextApiResponse) {
let user = await getUserFromToken(req, res);
if (!user) return;
await prisma.document
.create({
data: {
userId: user?.id,
},
})
.then(async () => {
return res.status(201).end();
});
}
async function getHandler(req: NextApiRequest, res: NextApiResponse) {
let user = await getUserFromToken(req, res);
if (!user) return;
return res
.status(200)
.json(await prisma.document.findMany({ where: { userId: user?.id } }));
}
export default defaultHandler({
GET: Promise.resolve({ default: defaultResponder(getHandler) }),
POST: Promise.resolve({ default: defaultResponder(postHandler) }),
});