Hopefully makes yodlee less busy.

This commit is contained in:
2022-01-09 08:34:20 -08:00
parent 51e9e6a83b
commit 6c83b40d95
5 changed files with 302 additions and 356 deletions

View File

@@ -174,14 +174,13 @@
(lc/with-context {:area "upload-invoice"}
(log/info "Number of invoices to import is" (count imports) "sample: " (first imports))
(let [clients (d-clients/get-all)
transactions (reduce (fn [result {:keys [invoice-number customer-identifier account-number total date vendor-code text full-text] :as info}]
transactions (reduce (fn [result {:keys [invoice-number customer-identifier account-number total date vendor-code text full-text]}]
(let [
matching-client (or (and account-number
(parse/best-match clients account-number 0.0))
(and customer-identifier
(parse/best-match clients customer-identifier))
(if client
(when client
(first (filter (fn [c]
(= (:db/id c) (Long/parseLong client)))
clients))))

View File

@@ -1,99 +1,83 @@
(ns auto-ap.routes.yodlee
(:require
[auto-ap.graphql :as graphql]
[clj-http.client :as http]
[auto-ap.yodlee.core :as yodlee]
[auto-ap.graphql.utils :refer [->graphql assert-admin]]
(:require
[auto-ap.graphql.utils :refer [assert-admin]]
[auto-ap.routes.utils :refer [wrap-secure]]
[clj-time.coerce :refer [to-date]]
[ring.middleware.json :refer [wrap-json-response]]
[compojure.core :refer [GET POST context defroutes wrap-routes]]
[clojure.string :as str]
[config.core :refer [env]]
[clojure.tools.logging :as log]))
[auto-ap.yodlee.core :as yodlee]
[clojure.tools.logging :as log]
[compojure.core :refer [context defroutes GET POST wrap-routes]]
[config.core :refer [env]]))
(defroutes routes
(wrap-routes
(context "/yodlee" []
(GET "/fastlink" {:keys [query-params identity] :as request}
(assert-admin identity)
(let [[session token] (yodlee/get-access-token)]
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str {:session session
:token token
:app (:yodlee-app env)
:url (:yodlee-fastlink env)
(GET "/fastlink" {:keys [identity]}
(assert-admin identity)
(let [[session token] (yodlee/get-access-token)]
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str {:session session
:token token
:app (:yodlee-app env)
}) }))
(GET "/accounts" {:keys [query-params identity] :as request}
(assert-admin identity)
(let [[session token] (yodlee/get-access-token)]
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/get-accounts)) }))
:url (:yodlee-fastlink env)})}))
(GET "/provider-accounts" {:keys [query-params identity] :as request}
(assert-admin identity)
(log/info "working on provider accounts...")
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str @yodlee/in-memory-cache) })
(POST "/reauthenticate/:id" {:keys [query-params identity] {:keys [id]} :route-params
data :edn-params
:as request}
(assert-admin identity)
(try
(let [[session token] (yodlee/get-access-token)]
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/reauthenticate (Long/parseLong id) data)) })
(catch Exception e
(log/error e)
{:status 500
: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
(let [[session token] (yodlee/get-access-token)]
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/update-yodlee (Long/parseLong id))) })
(catch Exception e
{:status 400
:headers {"Content-Type" "application/edn"}
:body (pr-str e)}))))
(GET "/accounts" {:keys [identity]}
(assert-admin identity)
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/get-accounts (yodlee/get-auth-header)))})
(GET "/provider-accounts" {:keys [identity]}
(assert-admin identity)
(log/info "working on provider accounts...")
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str @yodlee/in-memory-cache)})
(POST "/reauthenticate/:id" {:keys [identity] {:keys [id]} :route-params
data :edn-params}
(assert-admin identity)
(try
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/reauthenticate-and-recache (Long/parseLong id) data (yodlee/get-auth-header)))}
(catch Exception e
(log/error e)
{:status 500
:headers {"Content-Type" "application/edn"}
:body (pr-str {:message (.getMessage e)
:error (.toString e)})})))
(POST "/provider-accounts/refresh/:id" {:keys [identity] {:keys [id]} :route-params}
(assert-admin identity)
(try
(yodlee/refresh-provider-account (Long/parseLong id) (yodlee/get-auth-header))
{: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 [identity] {:keys [id]} :route-params}
(assert-admin identity)
(try
(yodlee/delete-and-uncache-provider-account (Long/parseLong id) (yodlee/get-auth-header))
{: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 [identity] {:keys [id]} :route-params}
(assert-admin identity)
(try
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/update-yodlee (Long/parseLong id) (yodlee/get-auth-header)))}
(catch Exception e
{:status 400
:headers {"Content-Type" "application/edn"}
:body (pr-str e)}))))
wrap-secure))