From 460aef8896a0e9979b3de84654f792e6af7a7b9a Mon Sep 17 00:00:00 2001 From: Abir Stolov Date: Sat, 23 Nov 2024 22:49:53 +0200 Subject: [PATCH] added YNAB max import id const --- .../main/src/backend/export/outputVendors/ynab/ynab.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/main/src/backend/export/outputVendors/ynab/ynab.ts b/packages/main/src/backend/export/outputVendors/ynab/ynab.ts index 83dd0ba1..59b60c93 100644 --- a/packages/main/src/backend/export/outputVendors/ynab/ynab.ts +++ b/packages/main/src/backend/export/outputVendors/ynab/ynab.ts @@ -16,6 +16,7 @@ import * as ynab from 'ynab'; const YNAB_DATE_FORMAT = 'YYYY-MM-DD'; const NOW = moment(); const MIN_YNAB_ACCESS_TOKEN_LENGTH = 43; +const MAX_YNAB_IMPORT_ID_LENGTH = 36; const categoriesMap = new Map>(); const transactionsFromYnab = new Map(); @@ -118,7 +119,7 @@ function convertTransactionToYnabFormat(originalTransaction: EnrichedTransaction category_id: getYnabCategoryIdFromCategoryName(originalTransaction.category), memo: originalTransaction.memo, cleared: ynab.SaveTransaction.ClearedEnum.Cleared, - import_id: buildImportId(originalTransaction), + import_id: buildImportId(originalTransaction), // [date][amount][description] // "approved": true, // "flag_color": "red", // "import_id": buildImportId(originalTransaction.description, amount, date) // 'YNAB:[milliunit_amount]:[iso_date]:[occurrence]' @@ -126,7 +127,10 @@ function convertTransactionToYnabFormat(originalTransaction: EnrichedTransaction } function buildImportId(transaction: EnrichedTransaction): string { - return `${transaction.date.substring(0, 10)}${transaction.chargedAmount}${transaction.description}`.substring(0, 36); + return `${transaction.date.substring(0, 10)}${transaction.chargedAmount}${transaction.description}`.substring( + 0, + MAX_YNAB_IMPORT_ID_LENGTH, + ); } function getYnabAccountIdByAccountNumberFromTransaction(transactionAccountNumber: string): string {