makes cloud search possible.
This commit is contained in:
@@ -42,137 +42,143 @@
|
||||
([args] (raw-graphql-ids (dc/db conn) args))
|
||||
([db args]
|
||||
(let [potential-duplicates (potential-duplicate-ids db args)
|
||||
query (cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
query
|
||||
(if (:exact-match-id args)
|
||||
(cond-> {:query {:find '[?e]
|
||||
:in '[$ ?e]
|
||||
:where '[[?e :transaction/client ?c]]}
|
||||
:args [db
|
||||
(:exact-match-id args)]}
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :transaction/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
||||
(cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
|
||||
(:potential-duplicates args)
|
||||
(merge-query {:query {:in '[[?e ...]]}
|
||||
:args [potential-duplicates]})
|
||||
|
||||
(:exact-match-id args)
|
||||
(merge-query {:query {:in ['?e]
|
||||
:where []}
|
||||
:args [(:exact-match-id args)]})
|
||||
(:potential-duplicates args)
|
||||
(merge-query {:query {:in '[[?e ...]]}
|
||||
:args [potential-duplicates]})
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :transaction/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :transaction/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
(:bank-account-id args)
|
||||
(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||
:args [(:bank-account-id args)]})
|
||||
|
||||
(:bank-account-id args)
|
||||
(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||
:args [(:bank-account-id args)]})
|
||||
(:import-batch-id args)
|
||||
(merge-query {:query {:in ['?import-batch-id]
|
||||
:where ['[?import-batch-id :import-batch/entry ?e]]}
|
||||
:args [(:import-batch-id args)]})
|
||||
|
||||
(:import-batch-id args)
|
||||
(merge-query {:query {:in ['?import-batch-id]
|
||||
:where ['[?import-batch-id :import-batch/entry ?e]]}
|
||||
:args [(:import-batch-id args)]})
|
||||
(:account-id args)
|
||||
(merge-query {:query {:in ['?account-id]
|
||||
:where ['[?e :transaction/accounts ?accounts]
|
||||
'[?accounts :transaction-account/account ?account-id]]}
|
||||
:args [(:account-id args)]})
|
||||
|
||||
(:account-id args)
|
||||
(merge-query {:query {:in ['?account-id]
|
||||
:where ['[?e :transaction/accounts ?accounts]
|
||||
'[?accounts :transaction-account/account ?account-id]]}
|
||||
:args [(:account-id args)]})
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :transaction/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
|
||||
(:client-id args)
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :transaction/client ?client-id]]}
|
||||
:args [(:client-id args)]})
|
||||
(:vendor-id args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :transaction/vendor ?vendor-id]]}
|
||||
:args [(:vendor-id args)]})
|
||||
|
||||
(:vendor-id args)
|
||||
(merge-query {:query {:in ['?vendor-id]
|
||||
:where ['[?e :transaction/vendor ?vendor-id]]}
|
||||
:args [(:vendor-id args)]})
|
||||
|
||||
(:amount-gte args)
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :transaction/amount ?a]
|
||||
'[(>= ?a ?amount-gte)]]}
|
||||
:args [(:amount-gte args)]})
|
||||
|
||||
|
||||
(:amount-gte args)
|
||||
(merge-query {:query {:in ['?amount-gte]
|
||||
:where ['[?e :transaction/amount ?a]
|
||||
'[(>= ?a ?amount-gte)]]}
|
||||
:args [(:amount-gte args)]})
|
||||
(:amount-lte args)
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :transaction/amount ?a]
|
||||
'[(<= ?a ?amount-lte)]]}
|
||||
:args [(:amount-lte args)]})
|
||||
|
||||
(:amount-lte args)
|
||||
(merge-query {:query {:in ['?amount-lte]
|
||||
:where ['[?e :transaction/amount ?a]
|
||||
'[(<= ?a ?amount-lte)]]}
|
||||
:args [(:amount-lte args)]})
|
||||
(:start (:date-range args))
|
||||
(merge-query {:query {:in ['?start-date]
|
||||
:where ['[?e :transaction/date ?date]
|
||||
'[(>= ?date ?start-date)]]}
|
||||
:args [(coerce/to-date (:start (:date-range args)))]})
|
||||
|
||||
(:start (:date-range args))
|
||||
(merge-query {:query {:in ['?start-date]
|
||||
:where ['[?e :transaction/date ?date]
|
||||
'[(>= ?date ?start-date)]]}
|
||||
:args [(coerce/to-date (:start (:date-range args)))]})
|
||||
(:end (:date-range args))
|
||||
(merge-query {:query {:in ['?end-date]
|
||||
:where ['[?e :transaction/date ?date]
|
||||
'[(<= ?date ?end-date)]]}
|
||||
:args [(coerce/to-date (:end (:date-range args)))]})
|
||||
|
||||
(:end (:date-range args))
|
||||
(merge-query {:query {:in ['?end-date]
|
||||
:where ['[?e :transaction/date ?date]
|
||||
'[(<= ?date ?end-date)]]}
|
||||
:args [(coerce/to-date (:end (:date-range args)))]})
|
||||
(:approval-status args)
|
||||
(merge-query {:query {:in ['?approval-status]
|
||||
:where ['[?e :transaction/approval-status ?approval-status]]}
|
||||
:args [(:approval-status args)]})
|
||||
|
||||
(:approval-status args)
|
||||
(merge-query {:query {:in ['?approval-status]
|
||||
:where ['[?e :transaction/approval-status ?approval-status]]}
|
||||
:args [(:approval-status args)]})
|
||||
(:client-code args)
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :transaction/client ?client-id]
|
||||
'[?client-id :client/code ?client-code]]}
|
||||
:args [(:client-code args)]})
|
||||
|
||||
(:original-id args)
|
||||
(merge-query {:query {:in ['?original-id]
|
||||
:where ['[?e :transaction/client ?c]
|
||||
'[?c :client/original-id ?original-id]]}
|
||||
:args [(:original-id args)]})
|
||||
|
||||
(:client-code args)
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :transaction/client ?client-id]
|
||||
'[?client-id :client/code ?client-code]]}
|
||||
:args [(:client-code args)]})
|
||||
|
||||
(:original-id args)
|
||||
(merge-query {:query {:in ['?original-id]
|
||||
:where ['[?e :transaction/client ?c]
|
||||
'[?c :client/original-id ?original-id]]}
|
||||
:args [(:original-id args)]})
|
||||
(seq (:location args))
|
||||
(merge-query {:query {:in ['?location]
|
||||
:where ['[?e :transaction/accounts ?tas]
|
||||
'[?tas :transaction-account/location ?location]]}
|
||||
:args [(:location args)]})
|
||||
|
||||
(seq (:location args))
|
||||
(merge-query {:query {:in ['?location]
|
||||
:where ['[?e :transaction/accounts ?tas]
|
||||
'[?tas :transaction-account/location ?location]]}
|
||||
:args [(:location args)]})
|
||||
(:unresolved args)
|
||||
(merge-query {:query {:where ['[?e :transaction/date]
|
||||
'(or-join [?e]
|
||||
(not [?e :transaction/accounts])
|
||||
(and [?e :transaction/accounts ?tas]
|
||||
(not [?tas :transaction-account/account])))]}})
|
||||
|
||||
(:unresolved args)
|
||||
(merge-query {:query {:where ['[?e :transaction/date]
|
||||
'(or-join [?e]
|
||||
(not [?e :transaction/accounts])
|
||||
(and [?e :transaction/accounts ?tas]
|
||||
(not [?tas :transaction-account/account])))]}})
|
||||
(:description args)
|
||||
(merge-query {:query {:in ['?description]
|
||||
:where ['[?e :transaction/description-original ?do]
|
||||
'[(clojure.string/lower-case ?do) ?do2]
|
||||
'[(.contains ?do2 ?description)]]}
|
||||
:args [(clojure.string/lower-case (:description args))]})
|
||||
|
||||
(:description args)
|
||||
(merge-query {:query {:in ['?description]
|
||||
:where ['[?e :transaction/description-original ?do]
|
||||
'[(clojure.string/lower-case ?do) ?do2]
|
||||
'[(.contains ?do2 ?description)]]}
|
||||
:args [(clojure.string/lower-case (:description args))]})
|
||||
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :transaction/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"account" ['[?e :transaction/date]
|
||||
'(or-join [?e ?sort-account]
|
||||
(and [?e :transaction/bank-account ?c]
|
||||
[?c :bank-account/name ?sort-account])
|
||||
(and
|
||||
(not [?e :transaction/bank-account])
|
||||
[(ground "") ?sort-account]))]
|
||||
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
|
||||
"date" ['[?e :transaction/date ?sort-date]]
|
||||
"vendor" ['(or-join [?e ?sort-vendor]
|
||||
(and [(missing? $ ?e :transaction/vendor)]
|
||||
[?e :transaction/description-original ?sort-vendor])
|
||||
(and [?e :transaction/vendor ?v]
|
||||
[?v :vendor/name ?sort-vendor]))]
|
||||
"amount" ['[?e :transaction/amount ?sort-amount]]
|
||||
"status" ['[?e :transaction/status ?sort-status]]}
|
||||
args)
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e]
|
||||
:where ['[?e :transaction/id]
|
||||
'[?e :transaction/date ?sort-default]
|
||||
'(not [?e :transaction/approval-status :transaction-approval-status/suppressed])]}}))]
|
||||
(:sort args) (add-sorter-fields {"client" ['[?e :transaction/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"account" ['[?e :transaction/date]
|
||||
'(or-join [?e ?sort-account]
|
||||
(and [?e :transaction/bank-account ?c]
|
||||
[?c :bank-account/name ?sort-account])
|
||||
(and
|
||||
(not [?e :transaction/bank-account])
|
||||
[(ground "") ?sort-account]))]
|
||||
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
|
||||
"date" ['[?e :transaction/date ?sort-date]]
|
||||
"vendor" ['(or-join [?e ?sort-vendor]
|
||||
(and [(missing? $ ?e :transaction/vendor)]
|
||||
[?e :transaction/description-original ?sort-vendor])
|
||||
(and [?e :transaction/vendor ?v]
|
||||
[?v :vendor/name ?sort-vendor]))]
|
||||
"amount" ['[?e :transaction/amount ?sort-amount]]
|
||||
"status" ['[?e :transaction/status ?sort-status]]}
|
||||
args)
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e]
|
||||
:where ['[?e :transaction/id]
|
||||
'[?e :transaction/date ?sort-default]
|
||||
'(not [?e :transaction/approval-status :transaction-approval-status/suppressed])]}})))]
|
||||
(log/info "query is" query)
|
||||
(cond->> (query2 query)
|
||||
true (apply-sort-3 (assoc args :default-asc? false))
|
||||
|
||||
Reference in New Issue
Block a user