mirror of
https://github.com/documenso/documenso.git
synced 2025-11-18 02:32:00 +10:00
🚧 signign workflow
This commit is contained in:
@ -14,8 +14,7 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { token: recipientToken } = req.query;
|
||||
|
||||
if (!recipientToken) {
|
||||
res.status(401).send("Missing recipient token.");
|
||||
return;
|
||||
return res.status(401).send("Missing recipient token.");
|
||||
}
|
||||
|
||||
const recipient = await prisma.recipient.findFirstOrThrow({
|
||||
@ -23,36 +22,18 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
});
|
||||
|
||||
if (!recipient) {
|
||||
res.status(401).send("Recipient not found.");
|
||||
return;
|
||||
return res.status(401).send("Recipient not found.");
|
||||
}
|
||||
|
||||
const document: PrismaDocument = await getDocument(
|
||||
recipient.documentId,
|
||||
res,
|
||||
req
|
||||
req,
|
||||
res
|
||||
);
|
||||
|
||||
if (!document) res.status(404).end(`No document found.`);
|
||||
|
||||
// todo sign stuff
|
||||
|
||||
const unsignedRecipients = await prisma.recipient.findMany({
|
||||
where: {
|
||||
signingStatus: SigningStatus.NOT_SIGNED,
|
||||
},
|
||||
});
|
||||
|
||||
if (unsignedRecipients.length === 0) {
|
||||
await prisma.document.update({
|
||||
where: {
|
||||
id: recipient.documentId,
|
||||
},
|
||||
data: {
|
||||
status: DocumentStatus.COMPLETED,
|
||||
},
|
||||
});
|
||||
}
|
||||
// save signature to db for later use
|
||||
|
||||
await prisma.recipient.update({
|
||||
where: {
|
||||
@ -63,6 +44,35 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) {
|
||||
},
|
||||
});
|
||||
|
||||
const unsignedRecipients = await prisma.recipient.findMany({
|
||||
where: {
|
||||
documentId: recipient.documentId,
|
||||
signingStatus: SigningStatus.NOT_SIGNED,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.document.update({
|
||||
where: {
|
||||
id: recipient.documentId,
|
||||
},
|
||||
data: {
|
||||
status: DocumentStatus.COMPLETED,
|
||||
},
|
||||
});
|
||||
|
||||
if (unsignedRecipients.length === 0) {
|
||||
// if everybody signed insert images and create signature
|
||||
await prisma.document.update({
|
||||
where: {
|
||||
id: recipient.documentId,
|
||||
},
|
||||
data: {
|
||||
status: DocumentStatus.COMPLETED,
|
||||
},
|
||||
});
|
||||
// send notifications
|
||||
}
|
||||
|
||||
return res.status(200).end();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user