mirror of
https://github.com/documenso/documenso.git
synced 2025-11-17 18:21:32 +10:00
send sign request, sign status
This commit is contained in:
@ -19,10 +19,18 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
let document = await prisma.document.findFirst({
|
||||
const document = await prisma.document.findFirstOrThrow({
|
||||
where: {
|
||||
id: +documentId,
|
||||
},
|
||||
include: {
|
||||
User: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
Recipient: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!document)
|
||||
@ -35,14 +43,17 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
});
|
||||
|
||||
(await recipients).forEach(async (recipient) => {
|
||||
sendSigningRequestMail(recipient, document);
|
||||
await prisma.recipient.update({
|
||||
where: { id: recipient.id },
|
||||
await sendSigningRequestMail(recipient, document);
|
||||
await prisma.recipient.updateMany({
|
||||
where: {
|
||||
id: recipient.id,
|
||||
sendStatus: SendStatus.NOT_SENT,
|
||||
},
|
||||
data: { sendStatus: SendStatus.SENT },
|
||||
});
|
||||
});
|
||||
|
||||
res.status(200);
|
||||
return res.status(200).end();
|
||||
}
|
||||
|
||||
export default defaultHandler({
|
||||
|
||||
@ -5,32 +5,45 @@ import {
|
||||
} from "@documenso/lib/server";
|
||||
import prisma from "@documenso/prisma";
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { SigningStatus } from "@prisma/client";
|
||||
|
||||
async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const existingUser = await getUserFromToken(req, res);
|
||||
const { id: documentId } = req.query;
|
||||
const { token: recipientToken } = req.query;
|
||||
|
||||
if (!documentId) {
|
||||
res.status(400).send("Missing parameter documentId.");
|
||||
if (!recipientToken) {
|
||||
res.status(401).send("Missing recipient token.");
|
||||
return;
|
||||
}
|
||||
|
||||
const recipient = await prisma.recipient.findFirstOrThrow({
|
||||
where: { token: recipientToken?.toString() },
|
||||
});
|
||||
|
||||
if (!recipient) {
|
||||
res.status(401).send("Recipient not found.");
|
||||
return;
|
||||
}
|
||||
|
||||
let document = await prisma.document.findFirst({
|
||||
where: {
|
||||
id: +documentId,
|
||||
id: recipient.documentId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!document)
|
||||
res.status(404).end(`No document with id ${documentId} found.`);
|
||||
if (!document) res.status(404).end(`No document found.`);
|
||||
|
||||
const recipients = prisma.recipient.findMany({
|
||||
where: { documentId: +documentId },
|
||||
// todo sign ui
|
||||
|
||||
await prisma.recipient.update({
|
||||
where: {
|
||||
id: recipient.id,
|
||||
},
|
||||
data: {
|
||||
signingStatus: SigningStatus.SIGNED,
|
||||
},
|
||||
});
|
||||
|
||||
// todo sign stuff
|
||||
|
||||
return res.status(200).end();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user