From ad33470281d85c591132e50433aedea7955ab2c5 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Fri, 24 Feb 2023 09:24:19 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20resend=20signing=20request=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/pages/api/documents/[id]/send.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/web/pages/api/documents/[id]/send.ts b/apps/web/pages/api/documents/[id]/send.ts index 38eeeef8b..a33ad6f29 100644 --- a/apps/web/pages/api/documents/[id]/send.ts +++ b/apps/web/pages/api/documents/[id]/send.ts @@ -12,6 +12,7 @@ import { Document as PrismaDocument, SendStatus } from "@prisma/client"; async function postHandler(req: NextApiRequest, res: NextApiResponse) { const user = await getUserFromToken(req, res); const { id: documentId } = req.query; + const { resendTo: resendTo = [] } = req.body; if (!user) return; @@ -25,16 +26,25 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) { if (!document) res.status(404).end(`No document with id ${documentId} found.`); - // todo handle sending to single recipient even though more exist + let recipientCondition: any = { + documentId: +documentId, + sendStatus: SendStatus.NOT_SENT, + }; + + if (resendTo.length) { + recipientCondition = { + documentId: +documentId, + id: { in: resendTo }, + }; + } const recipients = await prisma.recipient.findMany({ where: { - documentId: +documentId, - sendStatus: SendStatus.NOT_SENT, + ...recipientCondition, }, }); - if (!recipients.length) return res.status(200).end(""); + if (!recipients.length) return res.status(200).send(recipients.length); let sentRequests = 0; recipients.forEach(async (recipient) => { @@ -45,7 +55,7 @@ async function postHandler(req: NextApiRequest, res: NextApiResponse) { sentRequests++; if (sentRequests === recipients.length) { - return res.status(200).end(); + return res.status(200).send(recipients.length); } });