Makes accounts not loaded.

This commit is contained in:
2022-04-19 15:05:05 -07:00
parent f51f3450d6
commit cae28589d2
7 changed files with 169 additions and 175 deletions

View File

@@ -1,7 +1,11 @@
(ns auto-ap.datomic.accounts
(:require [datomic.api :as d]
[auto-ap.graphql.utils :refer [->graphql]]
[auto-ap.datomic :refer [uri merge-query conn]]))
(:require
[auto-ap.datomic
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query uri]]
[clojure.string :as str]
[datomic.api :as d]
[clojure.tools.logging :as log]))
(defn <-datomic [a]
(update a :account/applicability :db/ident))
@@ -86,4 +90,50 @@
(map <-datomic)
(first))))
#_(get-account-by-numeric-code-and-sets 5110 nil)
(defn raw-graphql-ids [db args]
(println args)
(let [query (cond-> {:query {:find []
:in ['$]
:where []}
:args [db]}
(:sort args) (add-sorter-fields {"name" ['[?e :account/name ?sort-name]]}
args)
(:numeric-code args)
(merge-query {:query {:in ['?numeric-code]
:where ['[?e :account/numeric-code ?numeric-code]]}
:args [(:numeric-code args)]})
(not (str/blank? (:name-like args)))
(merge-query {:query {:in ['?name-like]
:where ['[?e :account/name ?n]
'[(re-find ?name-like ?n)]]}
:args [(re-pattern (str "(?i)" (:name-like args)))]})
true
(merge-query {:query {:find ['?sort-default '?e ]
:where ['[?e :account/name]
'[?e :account/numeric-code ?sort-default]]}}))]
(cond->> query
true (d/query)
true (apply-sort-3 args)
true (apply-pagination args))))
(defn graphql-results [ids db args]
(let [results (->> (d/pull-many db default-read ids)
(group-by :db/id))
accounts (->> ids
(map results)
(map first)
(map <-datomic))]
accounts))
(defn get-graphql [args]
(log/info "ARGS" args)
(let [db (d/db conn)
{ids-to-retrieve :ids matching-count :count} (raw-graphql-ids db args)]
[(->> (graphql-results ids-to-retrieve db args))
matching-count]))

View File

@@ -305,6 +305,12 @@
:start {:type 'Int}
:end {:type 'Int}}}
:account_page {:fields {:accounts {:type '(list :account)}
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}
:end {:type 'Int}}}
:reminder_page {:fields {:reminders {:type '(list :reminder)}
:count {:type 'Int}
:total {:type 'Int}
@@ -358,9 +364,13 @@
:args {:client_id {:type :id}}
:resolve :get-yodlee-provider-account-page}
:accounts {:type '(list :account)
:args {:account_set {:type 'String}}
:resolve :get-accounts}
:account_page {:type :account_page
:args {:name_like {:type 'String}
:numeric_code {:type 'Int}
:start {:type 'Int}
:per_page {:type 'Int}
:sort {:type '(list :sort_item)}}
:resolve :get-accounts}
:search_vendor {:type '(list :search_result)
:args {:query {:type 'String}}
@@ -409,10 +419,6 @@
:per_page {:type 'Int}
:sort {:type '(list :sort_item)}}
:resolve :get-sales-order-page}
:vendor {:type :vendor_page
:args {:name_like {:type 'String}
:start {:type 'Int}
@@ -803,7 +809,7 @@
(attach-resolvers {
:get-yodlee-provider-account-page gq-yodlee2/get-yodlee-provider-account-page
:get-all-sales-orders get-all-sales-orders
:get-accounts gq-accounts/get-accounts
:get-accounts gq-accounts/get-graphql
:get-sales-order-page gq-sales-orders/get-sales-orders-page
:get-transaction-rule-page gq-transaction-rules/get-transaction-rule-page
:get-transaction-rule-matches gq-transaction-rules/get-transaction-rule-matches

View File

@@ -1,16 +1,21 @@
(ns auto-ap.graphql.accounts
(:require
[auto-ap.datomic :refer [audit-transact remove-nils conn]]
[auto-ap.datomic :refer [audit-transact conn remove-nils]]
[auto-ap.datomic.accounts :as d-accounts]
[auto-ap.graphql.utils
:refer [->graphql <-graphql assert-can-see-client enum->keyword]]
[datomic.api :as d]
[clojure.tools.logging :as log]))
(defn get-accounts [_ args _]
(->graphql (d-accounts/get-accounts (<-graphql args))))
:refer [->graphql
<-graphql
assert-admin
assert-can-see-client
enum->keyword
result->page]]
[datomic.api :as d]))
(defn get-graphql [context args _]
(assert-admin (:id context))
(let [args (assoc args :id (:id context))
[accounts accounts-count ] (d-accounts/get-graphql (<-graphql args))]
(result->page accounts accounts-count :accounts args)))
(defn default-for-vendor [context args _]
(assert-can-see-client (:id context) (:client_id args))