makes plaid really usable, allowing choosing on bank screen, and searchable on vendors page.

This commit is contained in:
Bryce
2023-07-22 21:33:06 -07:00
parent ff2d64fee5
commit dfd1af77c4
15 changed files with 101 additions and 21 deletions

View File

@@ -16,12 +16,16 @@
assert-can-see-client
assert-present
attach-tracing-resolvers
cleanse-query
limited-clients]]
[auto-ap.plaid.core :as p]
[clj-time.coerce :as coerce]
[clj-time.core :as time]
[clojure.tools.logging :as log]
[datomic.api :as dc]))
[datomic.api :as dc]
[auto-ap.solr :as solr]
[manifold.deferred :as de]
[manifold.executor :as ex]))
(defn plaid-link-token [context value _]
(when-not (:client_id value)
@@ -128,6 +132,30 @@
@(dc/transact conn [[:db/retractEntity (:id args)]])
{:message "Item deleted."})
(defn search-merchants [context args _]
(if-let [query (not-empty (cleanse-query (:query args)))]
(let [search-query (str "name:(" query ")")]
(for [{:keys [id name]} (solr/query solr/impl "plaid_merchants" {"query" search-query
"fields" "id, name"})]
{:id (Long/parseLong id)
:name (first name)}))
[]))
(def single-thread (ex/fixed-thread-executor 1))
(defn rebuild-search-index []
(de/future-with
single-thread
(auto-ap.solr/index-documents-raw
auto-ap.solr/impl
"plaid_merchants"
(for [[result] (dc/qseq {:query '[:find (pull ?v [:plaid-merchant/name :db/id])
:in $
:where [?v :plaid-merchant/name]]
:args [(dc/db conn)]})]
{"id" (:db/id result)
"name" (:plaid-merchant/name result)}))))
(defn attach [schema]
(->
(merge-with merge schema
@@ -162,7 +190,10 @@
:sort {:type '(list :sort_item)}
:start {:type 'Int}
:per_page {:type 'Int}}
:resolve :get-plaid-item-page}}
:resolve :get-plaid-item-page}
:search_plaid_merchants {:type '(list :plaid_merchant)
:args {:query {:type 'String}}
:resolve :search-plaid-merchants}}
:mutations {:link_plaid {:type :message
:args {:client_code {:type 'String}
:public_token {:type 'String}}
@@ -171,6 +202,7 @@
:args {:id {:type :id}}
:resolve :mutation/delete-plaid-item}}})
(attach-tracing-resolvers {:plaid-link-token plaid-link-token
:search-plaid-merchants search-merchants
:get-plaid-item-page get-plaid-item-page
:mutation/link-plaid link-plaid
:mutation/delete-plaid-item delete-plaid-item})))