Skip to content

Commit

Permalink
added YNAB max import id const
Browse files Browse the repository at this point in the history
  • Loading branch information
Abir Stolov committed Nov 23, 2024
1 parent 28f9e84 commit 460aef8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/main/src/backend/export/outputVendors/ynab/ynab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Pick<ynab.Category, 'id' | 'name' | 'category_group_id'>>();
const transactionsFromYnab = new Map<Date, ynab.TransactionDetail[]>();
Expand Down Expand Up @@ -118,15 +119,18 @@ 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]'
};
}

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 {
Expand Down

0 comments on commit 460aef8

Please sign in to comment.