Configure initial bank history in the connection UI
This commit is contained in:
+10
-4
@@ -92,9 +92,12 @@ func (a *App) ImportCSV(ctx context.Context, rev, accountID string, r io.Reader)
|
||||
}
|
||||
return ImportResult{}, errors.New("unknown account")
|
||||
}
|
||||
func (a *App) Authorize(ctx context.Context, institution, country string) (string, error) {
|
||||
func (a *App) Authorize(ctx context.Context, institution, country string, historyMonths int) (string, error) {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
if historyMonths < 1 || historyMonths > 120 {
|
||||
return "", errors.New("history_months must be an integer between 1 and 120")
|
||||
}
|
||||
if a.bank == nil {
|
||||
return "", errors.New("Enable Banking is not configured")
|
||||
}
|
||||
@@ -114,7 +117,7 @@ func (a *App) Authorize(ctx context.Context, institution, country string) (strin
|
||||
state := domain.NewID("auth")
|
||||
url, err := a.bank.Authorize(ctx, institution, country, state)
|
||||
if err == nil {
|
||||
a.authStates[state] = authorization{time.Now().Add(15 * time.Minute), institution, country}
|
||||
a.authStates[state] = authorization{Expires: time.Now().Add(15 * time.Minute), Institution: institution, Country: country, HistoryMonths: historyMonths}
|
||||
}
|
||||
return url, err
|
||||
}
|
||||
@@ -165,7 +168,7 @@ func (a *App) Callback(ctx context.Context, code, state string) error {
|
||||
return err
|
||||
}
|
||||
a.ops.Sessions = append(a.ops.Sessions, session)
|
||||
a.ops.Consents[session.ID] = Consent{Institution: auth.Institution, Country: auth.Country}
|
||||
a.ops.Consents[session.ID] = Consent{Institution: auth.Institution, Country: auth.Country, HistoryMonths: auth.HistoryMonths}
|
||||
if err = a.saveOps(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -301,9 +304,12 @@ func (a *App) Sync(ctx context.Context) (State, error) {
|
||||
failures = append(failures, account.DisplayName+": bank connection unavailable")
|
||||
continue
|
||||
}
|
||||
from := now.AddDate(0, 0, -90).Format("2006-01-02")
|
||||
var from string
|
||||
if last, e := time.Parse(time.RFC3339, a.ops.AccountSync[account.ID]); e == nil {
|
||||
from = last.AddDate(0, 0, -14).Format("2006-01-02")
|
||||
} else {
|
||||
months := a.ops.Consents[accountSession[account.ID]].historyMonths()
|
||||
from = now.AddDate(0, -months, 0).Format("2006-01-02")
|
||||
}
|
||||
facts, e := a.bank.Transactions(ctx, account, from, to)
|
||||
if e != nil {
|
||||
|
||||
Reference in New Issue
Block a user