Configure initial bank history in the connection UI
This commit is contained in:
+23
-10
@@ -8,30 +8,42 @@ import (
|
||||
"finance-duck/internal/domain"
|
||||
)
|
||||
|
||||
const defaultHistoryMonths = 12
|
||||
|
||||
type authorization struct {
|
||||
Expires time.Time
|
||||
Institution string
|
||||
Country string
|
||||
Expires time.Time
|
||||
Institution string
|
||||
Country string
|
||||
HistoryMonths int
|
||||
}
|
||||
type Consent struct {
|
||||
Institution string `json:"institution"`
|
||||
Country string `json:"country"`
|
||||
HistoryMonths int `json:"history_months"`
|
||||
Error string `json:"error,omitempty"`
|
||||
NeedsReconnect bool `json:"needs_reconnect"`
|
||||
}
|
||||
type Connection struct {
|
||||
AccountID string `json:"account_id"`
|
||||
Institution string `json:"institution"`
|
||||
Country string `json:"country"`
|
||||
Status string `json:"status"`
|
||||
ValidUntil string `json:"valid_until"`
|
||||
Error string `json:"error"`
|
||||
AccountID string `json:"account_id"`
|
||||
Institution string `json:"institution"`
|
||||
Country string `json:"country"`
|
||||
HistoryMonths int `json:"history_months"`
|
||||
Status string `json:"status"`
|
||||
ValidUntil string `json:"valid_until"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
func (c Consent) historyMonths() int {
|
||||
if c.HistoryMonths == 0 {
|
||||
return defaultHistoryMonths
|
||||
}
|
||||
return c.HistoryMonths
|
||||
}
|
||||
|
||||
func (a *App) connections(d domain.Dataset) []Connection {
|
||||
out := make([]Connection, 0, len(d.Accounts))
|
||||
for _, account := range d.Accounts {
|
||||
c := Connection{AccountID: account.ID, Institution: account.Institution, Country: "DE", Status: "local"}
|
||||
c := Connection{AccountID: account.ID, Institution: account.Institution, Country: "DE", HistoryMonths: defaultHistoryMonths, Status: "local"}
|
||||
if account.ExternalAccountID != "" {
|
||||
c.Status = "reconnect_required"
|
||||
c.Error = "No saved bank consent; reconnect this account"
|
||||
@@ -42,6 +54,7 @@ func (a *App) connections(d domain.Dataset) []Connection {
|
||||
continue
|
||||
}
|
||||
meta := a.ops.Consents[session.ID]
|
||||
c.HistoryMonths = meta.historyMonths()
|
||||
if meta.Institution != "" {
|
||||
c.Institution = meta.Institution
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user