From 8a26bf08e11ee52776418db721614f02370c8c2a Mon Sep 17 00:00:00 2001 From: Niels Saurer Date: Fri, 10 Jan 2025 14:11:14 +0100 Subject: [PATCH] Pick the first correspondent if multiple are returned --- services/paperlessService.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/services/paperlessService.js b/services/paperlessService.js index 3be2e94..b5f2cb0 100644 --- a/services/paperlessService.js +++ b/services/paperlessService.js @@ -735,8 +735,15 @@ class PaperlessService { console.log("Response Correspondent Search: ", existingCorrespondent); if (existingCorrespondent) { - console.log(`Found existing correspondent "${name}" with ID ${existingCorrespondent.id}`); - return existingCorrespondent; + // If only one result is found, return it + if (!Array.isArray(existingCorrespondent)) { + console.log(`Found existing correspondent "${name}" with ID ${existingCorrespondent.id}`); + return existingCorrespondent; + } + // If multiple results are found, return the first one + const firstResult = existingCorrespondent[0]; + console.log(`Found multiple correspondents for "${name}". Returning first one with ID ${firstResult.id}`); + return firstResult; } // Erstelle neuen Korrespondenten