From a78ad47fda2b8de004988bff0a2e97b0cd88b1e0 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 11 Feb 2021 19:43:31 -0800 Subject: [PATCH] Added yodlee account balances --- src/clj/auto_ap/graphql.clj | 1 + src/clj/auto_ap/graphql/clients.clj | 13 ++++++++++++- src/cljs/auto_ap/events.cljs | 2 +- .../views/components/bank_account_filter.cljs | 8 +++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index b1f6c579..d4b3c0fe 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -140,6 +140,7 @@ :bank_code {:type 'String} :bank_name {:type 'String} :current_balance {:type :money} + :yodlee_balance_old {:type :money} :yodlee_account_id {:type 'Int} :yodlee_account {:type :yodlee_account} :locations {:type '(list String)}}} diff --git a/src/clj/auto_ap/graphql/clients.clj b/src/clj/auto_ap/graphql/clients.clj index ac2a197b..5d8024e5 100644 --- a/src/clj/auto_ap/graphql/clients.clj +++ b/src/clj/auto_ap/graphql/clients.clj @@ -2,6 +2,9 @@ (:require [auto-ap.datomic :refer [audit-transact conn remove-nils]] [auto-ap.datomic.clients :as d-clients] [auto-ap.graphql.utils :refer [->graphql assert-admin can-see-client? is-admin?]] + [auto-ap.utils :refer [by]] + [auto-ap.yodlee.core :refer [in-memory-cache]] + [clj-time.coerce :as coerce] [config.core :refer [env]] [clojure.string :as str] @@ -213,4 +216,12 @@ (map (fn [c] (if (is-admin? (:id context)) c - (dissoc c :client/yodlee-provider-accounts))))))) + (dissoc c :client/yodlee-provider-accounts)))) + (map (fn [c] + (update c :client/bank-accounts + (fn [bank-accounts] + (mapv (fn [ba] + ;; TODO remove when new yodlee replaces + (assoc ba :bank-account/yodlee-balance-old (get-in (by :id (mapcat :accounts @in-memory-cache) ) + [(:bank-account/yodlee-account-id ba) :balance :amount]))) + bank-accounts)))))))) diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index f9cbec6c..b3a06c8f 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -32,7 +32,7 @@ [:location-matches [:id :location :match]] [:bank-accounts [:id :start-date :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id [:yodlee-account [:name :id :number]] - :locations :include-in-reports :current-balance] ] + :locations :include-in-reports :current-balance :yodlee-balance-old] ] [:address [:street1 :street2 :city :state :zip]] [:forecasted-transactions [:id :amount :identifier :day-of-month]]] (= "admin" (or (get (jwt->data token) "role") (get (jwt->data token) "user/role")) ) (conj [:yodlee-provider-accounts [:id [:accounts [:id :name :number :available-balance]]]]))) diff --git a/src/cljs/auto_ap/views/components/bank_account_filter.cljs b/src/cljs/auto_ap/views/components/bank_account_filter.cljs index 17315a9f..3488d8ab 100644 --- a/src/cljs/auto_ap/views/components/bank_account_filter.cljs +++ b/src/cljs/auto_ap/views/components/bank_account_filter.cljs @@ -34,4 +34,10 @@ ] (:name ba) (when (and (:current-balance ba) is-power-user?) - (str ": " (->$ (:current-balance ba))))])])) + (str ": " (->$ (:current-balance ba)))) + + (when (and (:yodlee-balance-old ba) + is-power-user?) + [:<> + [:div.tag [:img {:src "/img/yodlee.png" :style {:width "16px" :height "16px"}}] + (->$ (:yodlee-balance-old ba 0.00))]])])]))