A bunch of bug fixes.
This commit is contained in:
@@ -164,3 +164,26 @@
|
||||
#_(process-all)
|
||||
|
||||
#_(reset! break true)
|
||||
|
||||
|
||||
|
||||
(defn keep-up-to-date []
|
||||
(while (and (not @break)
|
||||
(not (Thread/interrupted)))
|
||||
(try
|
||||
@(d/transact
|
||||
(d/connect uri)
|
||||
(mapv
|
||||
#(auto-ap.ledger/entity-change->ledger (d/db (d/connect uri)) [:transaction %])
|
||||
(concat
|
||||
(->>
|
||||
(d/query {:query {:find ['?t ]
|
||||
:in ['$]
|
||||
:where ['[?t :transaction/date]
|
||||
'(not [?t :transaction/approval-status :transaction-approval-status/excluded])
|
||||
'(not-join [?t] [?e :journal-entry/original-entity ?t])]}
|
||||
:args [(d/db (d/connect uri))]})
|
||||
(map first)))))
|
||||
(Thread/sleep 60000)
|
||||
(catch Exception e
|
||||
(println (.toString e))))))
|
||||
|
||||
@@ -58,6 +58,32 @@
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/refresh/:id" {:keys [query-params identity] {:keys [id]} :route-params :as request}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
(yodlee/refresh-provider-account (Long/parseLong id))
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache) })
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/delete/:id" {:keys [query-params identity] {:keys [id]} :route-params :as request}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
(let [[session token] (yodlee/get-access-token)]
|
||||
(yodlee/delete-provider-account (Long/parseLong id))
|
||||
{:status 200
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str @yodlee/in-memory-cache) })
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:body (pr-str {:message (.getMessage e)
|
||||
:error (.toString e)})})))
|
||||
(POST "/provider-accounts/:id" {:keys [query-params identity] {:keys [id]} :route-params :as request}
|
||||
(assert-admin identity)
|
||||
(try
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
(ns auto-ap.server
|
||||
(:require #_[auto-ap.background.mail :refer [always-process-sqs]]
|
||||
[auto-ap.handler :refer [app]]
|
||||
[auto-ap.ledger :refer [process-all]]
|
||||
[auto-ap.ledger :refer [process-all keep-up-to-date]]
|
||||
[auto-ap.yodlee.core :refer [load-in-memory-cache]]
|
||||
[nrepl.server :refer [start-server stop-server]]
|
||||
[config.core :refer [env]]
|
||||
@@ -17,5 +17,6 @@
|
||||
(let [port (Integer/parseInt (or (env :port) "3000"))]
|
||||
(future (process-all))
|
||||
(future (load-in-memory-cache))
|
||||
(future (keep-up-to-date))
|
||||
#_(future (always-process-sqs))
|
||||
(run-jetty app {:port port :join? false})))
|
||||
|
||||
@@ -52,6 +52,15 @@
|
||||
:body
|
||||
:account)))
|
||||
|
||||
(defn get-accounts-for-provider-account [provider-account-id]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
(-> (str (:yodlee-base-url env) "/accounts?providerAccountId=" provider-account-id)
|
||||
(client/get {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json})
|
||||
:body
|
||||
:account)))
|
||||
|
||||
(defn get-account [i]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)]
|
||||
@@ -252,7 +261,7 @@
|
||||
(future
|
||||
(loop []
|
||||
(try
|
||||
(reset! in-memory-cache (get-provider-accounts-with-accounts))
|
||||
(reset! in-memory-cache (get-provider-accounts-with-accounts))
|
||||
(catch Exception e
|
||||
(println e)))
|
||||
(Thread/sleep (* 30 1000 5))
|
||||
@@ -260,10 +269,29 @@
|
||||
(recur)))))
|
||||
|
||||
(defn refresh-provider-account [id]
|
||||
(swap! in-memory-cache
|
||||
(swap! in-memory-cache
|
||||
(fn [i]
|
||||
(-> (by :id i)
|
||||
(update id merge (get-provider-account-detail id))
|
||||
(assoc id (assoc (get-provider-account-detail id)
|
||||
:accounts (get-accounts-for-provider-account id)))
|
||||
vals))))
|
||||
|
||||
(defn delete-provider-account [id]
|
||||
(let [cob-session (login-cobrand)
|
||||
user-session (login-user cob-session)
|
||||
batch-size 100]
|
||||
|
||||
(-> (str (:yodlee-base-url env) "/providerAccounts/" id )
|
||||
|
||||
(client/delete {:headers (merge base-headers {"Authorization" (auth-header cob-session user-session)})
|
||||
:as :json})
|
||||
:body
|
||||
:providerAccount
|
||||
first))
|
||||
(swap! in-memory-cache
|
||||
(fn [i]
|
||||
(-> (by :id i)
|
||||
(dissoc id)
|
||||
vals))))
|
||||
|
||||
(defn update-yodlee [id]
|
||||
|
||||
@@ -287,7 +287,7 @@
|
||||
'[?e :transaction/client ?c]
|
||||
'[?c :client/code ?client-code]
|
||||
]}
|
||||
:args [(d/db (d/connect uri)) client-code]})
|
||||
:args [(d/db (d/connect uri)) client-code]})
|
||||
(mapcat
|
||||
(fn [[{:transaction/keys [accounts]}]]
|
||||
(mapv
|
||||
@@ -300,3 +300,48 @@
|
||||
)
|
||||
vec))
|
||||
|
||||
(defn patch-missing-ledger-entries []
|
||||
@(d/transact
|
||||
(d/connect uri)
|
||||
(mapv
|
||||
#(auto-ap.ledger/entity-change->ledger (d/db (d/connect uri)) [:transaction %])
|
||||
(concat
|
||||
(->>
|
||||
(d/query {:query {:find ['?t ]
|
||||
:in ['$]
|
||||
:where ['[?t :transaction/date]
|
||||
'(not [?t :transaction/approval-status :transaction-approval-status/excluded])
|
||||
'(not-join [?t] [?e :journal-entry/original-entity ?t])]}
|
||||
:args [(d/db (d/connect uri))]})
|
||||
(map first))))))
|
||||
|
||||
|
||||
|
||||
(defn check-for-out-of-date-ledger [?code]
|
||||
[(d/query {:query {:find ['(count ?e)]
|
||||
:in ['$ '?code]
|
||||
:where ['[?e :transaction/accounts ?ta]
|
||||
'[?e :transaction/matched-rule]
|
||||
'[?e :transaction/approval-status :transaction-approval-status/approved]
|
||||
'(not [?ta :transaction-account/location])
|
||||
'[?e :transaction/client ?c]
|
||||
'[?c :client/code ?code]
|
||||
]}
|
||||
:args [(d/db (d/connect uri)) ?code]})
|
||||
|
||||
(d/query {:query {:find ['?t ]
|
||||
:in ['$]
|
||||
:where ['[?t :transaction/date]
|
||||
'(not [?t :transaction/approval-status :transaction-approval-status/excluded])
|
||||
'(not-join [?t] [?e :journal-entry/original-entity ?t])]}
|
||||
:args [(d/db (d/connect uri))]})
|
||||
|
||||
(d/query {:query {:find ['?t ]
|
||||
:in ['$]
|
||||
:where ['[?t :transaction/date]
|
||||
'(not [?t :transaction/approval-status :transaction-approval-status/excluded])
|
||||
'[?t :transaction/vendor ?v]
|
||||
'[?j :journal-entry/original-entity ?t]
|
||||
'(not [?j :journal-entry/vendor ?v])
|
||||
#_'(not-join [?t] [?e :journal-entry/original-entity ?t])]}
|
||||
:args [(d/db (d/connect uri))]})])
|
||||
|
||||
Reference in New Issue
Block a user