From dbd452be97bcb27da9cc6666079109926d13b548 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Tue, 30 Apr 2024 20:53:18 +0700 Subject: [PATCH] fix: delete pending documents (#1118) ## Description Currently deleting a pending document where you are a recipient off will delete the document, but will also throw an error. This is due to the recipient being updated after the document deleted, which is only supposed to happen for completed documents. --- .../server-only/document/delete-document.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/lib/server-only/document/delete-document.ts b/packages/lib/server-only/document/delete-document.ts index a097d76e9..bf4f8aa06 100644 --- a/packages/lib/server-only/document/delete-document.ts +++ b/packages/lib/server-only/document/delete-document.ts @@ -75,18 +75,20 @@ export const deleteDocument = async ({ } // Continue to hide the document from the user if they are a recipient. + // Dirty way of doing this but it's faster than refetching the document. if (userRecipient?.documentDeletedAt === null) { - await prisma.recipient.update({ - where: { - documentId_email: { - documentId: document.id, - email: user.email, + await prisma.recipient + .update({ + where: { + id: userRecipient.id, }, - }, - data: { - documentDeletedAt: new Date().toISOString(), - }, - }); + data: { + documentDeletedAt: new Date().toISOString(), + }, + }) + .catch(() => { + // Do nothing. + }); } // Return partial document for API v1 response.