mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
recipients ui and api basics
This commit is contained in:
33
apps/web/pages/api/documents/[id]/recipients/[rid].ts
Normal file
33
apps/web/pages/api/documents/[id]/recipients/[rid].ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import {
|
||||||
|
defaultHandler,
|
||||||
|
defaultResponder,
|
||||||
|
getUserFromToken,
|
||||||
|
} from "@documenso/lib/server";
|
||||||
|
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 deleteHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
const user = await getUserFromToken(req, res);
|
||||||
|
const { id: documentId, rid: recipientId } = req.query;
|
||||||
|
const body = req.body;
|
||||||
|
|
||||||
|
if (!recipientId) {
|
||||||
|
res.status(400).send("Missing parameter recipientId.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await prisma.recipient.delete({
|
||||||
|
where: {
|
||||||
|
id: +recipientId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(200).send(documentId + "<- did rid ->" + recipientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defaultHandler({
|
||||||
|
DELETE: Promise.resolve({ default: defaultResponder(deleteHandler) }),
|
||||||
|
});
|
||||||
@ -32,9 +32,10 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
return res.status(401).send("User does not have access to this document.");
|
return res.status(401).send("User does not have access to this document.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const upsert = await prisma.recipient.upsert({
|
await prisma.recipient.upsert({
|
||||||
where: {
|
where: {
|
||||||
email: body.email,
|
email: body.email,
|
||||||
|
// todo id
|
||||||
},
|
},
|
||||||
update: {
|
update: {
|
||||||
email: body.email,
|
email: body.email,
|
||||||
|
|||||||
@ -11,7 +11,6 @@ export const config = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// POST /documents
|
|
||||||
async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const form = formidable();
|
const form = formidable();
|
||||||
|
|
||||||
|
|||||||
@ -180,6 +180,29 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async delete(recipient:any){
|
||||||
|
toast.promise(
|
||||||
|
fetch("/api/documents/" + recipient.documentId + "/recipients", {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(recipient),
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
loading: "Deleting...",
|
||||||
|
success: "Deleted.",
|
||||||
|
error: "Could not delete :/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "deleting",
|
||||||
|
style: {
|
||||||
|
minWidth: "200px",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function upsertRecipient(recipient: any) {
|
async function upsertRecipient(recipient: any) {
|
||||||
toast.promise(
|
toast.promise(
|
||||||
fetch("/api/documents/" + recipient.documentId + "/recipients", {
|
fetch("/api/documents/" + recipient.documentId + "/recipients", {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ export const getDocumentsForUserFromToken = async (
|
|||||||
const user = await getUserFromToken(context.req, context.res);
|
const user = await getUserFromToken(context.req, context.res);
|
||||||
if (!user) return Promise.reject("Invalid user or token.");
|
if (!user) return Promise.reject("Invalid user or token.");
|
||||||
|
|
||||||
|
// todo remove document base64 data
|
||||||
const documents: PrismaDocument[] = await prisma.document.findMany({
|
const documents: PrismaDocument[] = await prisma.document.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user