From cb5595ec7ce17f095c73b7e7bc7badd61a8fbf39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Gonz=C3=A1lez?= Date: Wed, 3 Apr 2024 09:03:22 -0600 Subject: [PATCH] fix from month --- projects/scrape-txs/serverless.yml | 2 +- projects/update-ynab/banks/banks.go | 17 ++++++++++++++++- projects/update-ynab/serverless.yml | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/projects/scrape-txs/serverless.yml b/projects/scrape-txs/serverless.yml index 8769d2a..e70dd7e 100644 --- a/projects/scrape-txs/serverless.yml +++ b/projects/scrape-txs/serverless.yml @@ -1,4 +1,4 @@ -service: scrape-txs-scheduled-lambda +service: scrape-txs-scheduled frameworkVersion: '3' provider: diff --git a/projects/update-ynab/banks/banks.go b/projects/update-ynab/banks/banks.go index 74edd0f..e2d4e80 100644 --- a/projects/update-ynab/banks/banks.go +++ b/projects/update-ynab/banks/banks.go @@ -2,6 +2,8 @@ package banks import ( "fmt" + "log/slog" + "slices" "time" "bank-bots/update-ynab/types" @@ -31,11 +33,13 @@ func LoadBankTxs(db *sqlx.DB) ([]types.BankAccountWithTransactions, error) { fromMonth = time.Now() } + slog.Info("loading bank txs", slog.String("fromMonth", fromMonth.Format("2006-01"))) + bankTxs := []dbBankTx{} sql := ` select * from bank_txs - where month <= $1 + where month >= $1 order by bank_key asc, account_number asc, date asc, doc_no asc` err := db.Select(&bankTxs, sql, fromMonth.Format("2006-01")) if err != nil { @@ -83,8 +87,19 @@ func LoadBankTxs(db *sqlx.DB) ([]types.BankAccountWithTransactions, error) { bankAccount.Transactions = append(bankAccount.Transactions, slice[0]) } } + slices.SortFunc(bankAccount.Transactions, func(a, b types.PreparedBankTx) int { + return a.Date.Compare(b.Date) + }) bankAccounts = append(bankAccounts, bankAccount) } + slog.Info("printing found bank txs:") + for _, bankAccount := range bankAccounts { + for _, bankTx := range bankAccount.Transactions { + slog.Info(fmt.Sprintf("account: %s, date: %s, doc_no: %s, amount: %d", bankAccount.Account.Number, + bankTx.Date.Format("2006-01-02"), bankTx.DocNo, bankTx.Amount)) + } + } + return bankAccounts, nil } diff --git a/projects/update-ynab/serverless.yml b/projects/update-ynab/serverless.yml index 26b6981..bcbb04c 100644 --- a/projects/update-ynab/serverless.yml +++ b/projects/update-ynab/serverless.yml @@ -1,4 +1,4 @@ -service: update-ynab-lambda +service: update-ynab frameworkVersion: '3' provider: