progress on migrating all grids.
This commit is contained in:
@@ -9,8 +9,7 @@
|
||||
pull-attr
|
||||
pull-many-by-id
|
||||
query2]]
|
||||
[auto-ap.graphql.utils
|
||||
:refer [assert-can-see-client extract-client-ids]]
|
||||
[auto-ap.graphql.utils :refer [assert-can-see-client]]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.plaid.core :as p]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
@@ -36,43 +35,36 @@
|
||||
:plaid-account/balance
|
||||
:plaid-account/name]}])
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [valid-clients (extract-client-ids (:clients args)
|
||||
(:client-id args)
|
||||
(when (:client-code args)
|
||||
[:client/code (:client-code args)]))
|
||||
(defn fetch-ids [db request]
|
||||
(let [query-params (:parsed-query-params request)
|
||||
query (cond-> {:query {:find []
|
||||
:in ['$ '[?xx ...]]
|
||||
:where ['[?e :plaid-item/client ?xx]]}
|
||||
:args [db valid-clients]}
|
||||
:args [db (:trimmed-clients request)]}
|
||||
|
||||
(:sort args) (add-sorter-fields {"external-id" ['[?e :plaid-item/external-id ?sort-external-id]]
|
||||
(:sort query-params) (add-sorter-fields {"external-id" ['[?e :plaid-item/external-id ?sort-external-id]]
|
||||
"status" ['[?e :plaid-item/status ?sort-status]]}
|
||||
args)
|
||||
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in '[?client-id]
|
||||
:where ['[?e :plaid-item/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
query-params)
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?e]
|
||||
:where ['[?e :plaid-item/external-id]]}}))]
|
||||
|
||||
(clojure.pprint/pprint query-params)
|
||||
(cond->> (query2 query)
|
||||
true (apply-sort-3 args)
|
||||
true (apply-pagination args))))
|
||||
true (apply-sort-3 query-params)
|
||||
true (apply-pagination query-params))))
|
||||
|
||||
|
||||
(defn graphql-results [ids db _]
|
||||
(defn hydrate-results [ids db _]
|
||||
(let [results (pull-many-by-id db default-read ids)]
|
||||
(->> ids
|
||||
(map results))))
|
||||
|
||||
(defn get-page [args]
|
||||
(defn fetch-page [request]
|
||||
(let [db (dc/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
|
||||
[(graphql-results ids-to-retrieve db args)
|
||||
{ids-to-retrieve :ids matching-count :count} (fetch-ids db request)]
|
||||
[(hydrate-results ids-to-retrieve db request)
|
||||
matching-count]))
|
||||
|
||||
|
||||
@@ -138,65 +130,61 @@
|
||||
"Start relink")])))
|
||||
|
||||
|
||||
(def grid-page {:id "plaid-table"
|
||||
:nav (com/company-aside-nav)
|
||||
:id-fn :db/id
|
||||
:fetch-page (fn [user args]
|
||||
(get-page {:client (:client args)
|
||||
:clients (:clients args)
|
||||
:start (:start (:parsed-query-params args))
|
||||
:sort (:sort (:parsed-query-params args))
|
||||
:per-page (:per-page (:parsed-query-params args))
|
||||
}))
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company)}
|
||||
"My Company"]
|
||||
(def grid-page
|
||||
(helper/build
|
||||
{:id "plaid-table"
|
||||
:nav (com/company-aside-nav)
|
||||
:fetch-page fetch-page
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company)}
|
||||
"My Company"]
|
||||
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company-plaid)}
|
||||
"Plaid"]]
|
||||
:title "Plaid Accounts"
|
||||
:entity-name "Plaid accounts"
|
||||
:route :company-plaid-table
|
||||
:action-buttons (fn [user params]
|
||||
(when-let [client-code (:client/code (:client params))]
|
||||
[[:div {:hx-post (str (bidi/path-for ssr-routes/only-routes
|
||||
:company-plaid-link
|
||||
:request-method :post))
|
||||
:hx-vals (hiccup/raw (format "js:{client_code: \"%s\", public_token: event.detail.public_token}", client-code))
|
||||
:hx-trigger "linked"}
|
||||
[:script (hiccup/raw (plaid-link-script (p/get-link-token client-code)))]
|
||||
(com/button {:color :primary
|
||||
:id "link-account"
|
||||
:onClick "window.plaid.open()"}
|
||||
(com/button-icon {} svg/refresh)
|
||||
"Link new account")]]))
|
||||
:row-buttons (fn [user e]
|
||||
[[:div (com/button {:hx-put (str (bidi/path-for ssr-routes/only-routes
|
||||
:company-plaid-relink)
|
||||
"?plaid-item-id=" (:db/id e))
|
||||
:color :primary
|
||||
:hx-target "closest div"}
|
||||
"Reauthenticate")]])
|
||||
:headers [{:key "plaid-item"
|
||||
:name "Plaid Item"
|
||||
:sort-key "external-id"
|
||||
:render :plaid-item/external-id}
|
||||
{:key "status"
|
||||
:name "Status"
|
||||
:sort-key "status"
|
||||
:render #(when-let [status (:plaid-item/status %)]
|
||||
[:div [:div (com/pill {:color :primary}
|
||||
status)]
|
||||
[:div (atime/unparse-local (coerce/to-date-time (:plaid-item/last-updated %)) atime/normal-date)]])}
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company-plaid)}
|
||||
"Plaid"]]
|
||||
:title "Plaid Accounts"
|
||||
:entity-name "Plaid accounts"
|
||||
:route :company-plaid-table
|
||||
:action-buttons (fn [request]
|
||||
(when-let [client-code (:client/code (:client request))]
|
||||
[[:div {:hx-post (str (bidi/path-for ssr-routes/only-routes
|
||||
:company-plaid-link
|
||||
:request-method :post))
|
||||
:hx-vals (hiccup/raw (format "js:{client_code: \"%s\", public_token: event.detail.public_token}", client-code))
|
||||
:hx-trigger "linked"}
|
||||
[:script (hiccup/raw (plaid-link-script (p/get-link-token client-code)))]
|
||||
(com/button {:color :primary
|
||||
:id "link-account"
|
||||
:onClick "window.plaid.open()"}
|
||||
(com/button-icon {} svg/refresh)
|
||||
(format "Link %s account" client-code))]]))
|
||||
:row-buttons (fn [request e]
|
||||
[[:div (com/button {:hx-put (str (bidi/path-for ssr-routes/only-routes
|
||||
:company-plaid-relink)
|
||||
"?plaid-item-id=" (:db/id e))
|
||||
:color :primary
|
||||
:hx-target "closest div"}
|
||||
"Reauthenticate")]])
|
||||
:headers [{:key "plaid-item"
|
||||
:name "Plaid Item"
|
||||
:sort-key "external-id"
|
||||
:render :plaid-item/external-id}
|
||||
{:key "status"
|
||||
:name "Status"
|
||||
:sort-key "status"
|
||||
:render #(when-let [status (:plaid-item/status %)]
|
||||
[:div [:div (com/pill {:color :primary}
|
||||
status)]
|
||||
[:div (atime/unparse-local (coerce/to-date-time (:plaid-item/last-updated %)) atime/normal-date)]])}
|
||||
|
||||
{:key "accounts"
|
||||
:name "Accounts"
|
||||
:show-starting "md"
|
||||
:render (fn [e]
|
||||
[:ul
|
||||
(for [a (:plaid-item/accounts e)]
|
||||
[:li (:plaid-account/name a) " - " (:plaid-account/number a)])])}]})
|
||||
{:key "accounts"
|
||||
:name "Accounts"
|
||||
:show-starting "md"
|
||||
:render (fn [e]
|
||||
[:ul
|
||||
(for [a (:plaid-item/accounts e)]
|
||||
[:li (:plaid-account/name a) " - " (:plaid-account/number a)])])}]}))
|
||||
|
||||
(def page (partial helper/page grid-page))
|
||||
(def table (partial helper/table grid-page))
|
||||
|
||||
(def page (helper/page-route grid-page))
|
||||
(def table (helper/table-route grid-page))
|
||||
|
||||
Reference in New Issue
Block a user