Migrates back to datomic on-prem

This commit is contained in:
2023-04-29 07:12:51 -07:00
parent aca8f7c92c
commit b2ad7790cf
88 changed files with 2289 additions and 2286 deletions

View File

@@ -1,10 +1,16 @@
(ns auto-ap.datomic.accounts
(:require
[auto-ap.datomic
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query conn pull-many]]
:refer [add-sorter-fields
apply-pagination
apply-sort-3
conn
merge-query
pull-many
query2]]
[clojure.string :as str]
[datomic.client.api :as dc]
[clojure.tools.logging :as log]))
[clojure.tools.logging :as log]
[datomic.api :as dc]))
(defn <-datomic [a]
(-> a
@@ -42,19 +48,19 @@
:where [['?e :account/account-set '?account-set]]}
:args [(:account-set args)]}))]
(->>
(dc/q query)
(query2 query)
(map first)
(map <-datomic)))))
(defn get-by-id [id]
(let [query {:query {:find [(list 'pull '?e default-read)]
:in ['$ '?e]}
:args [(dc/db conn ) id]}]
(->>
(dc/q query)
(map first)
(map <-datomic)
first)))
(->>
(dc/q {:find [(list 'pull '?e default-read)]
:in ['$ '?e]}
(dc/db conn )
id)
(map first)
(map <-datomic)
first))
(defn get-for-vendor [vendor-id client-id]
(if client-id
@@ -87,15 +93,14 @@
default-read))))
(defn get-account-by-numeric-code-and-sets [numeric-code _]
(let [query (cond-> {:query {:find ['(pull ?e [* {:account/type [:db/ident :db/id]}])]
:in ['$ '?numeric-code]
:where ['[?e :account/numeric-code ?numeric-code]]}
:args [(dc/db conn) numeric-code]})]
(->>
(dc/q query)
(map first)
(map <-datomic)
(first))))
(->>
(dc/q {:find ['(pull ?e [* {:account/type [:db/ident :db/id]}])]
:in ['$ '?numeric-code]
:where ['[?e :account/numeric-code ?numeric-code]]}
(dc/db conn) numeric-code)
(map first)
(map <-datomic)
(first)))
(defn raw-graphql-ids [db args]
(let [query (cond-> {:query {:find []
@@ -122,8 +127,7 @@
'[?e :account/numeric-code ?sort-default]]}}))]
(cond->> query
true (dc/q)
(cond->> (query2 query)
true (apply-sort-3 args)
true (apply-pagination args))))

View File

@@ -1,7 +1,7 @@
(ns auto-ap.datomic.bank-accounts
(:require
[auto-ap.datomic :refer [conn]]
[datomic.client.api :as dc]))
[datomic.api :as dc]))
(defn add-arg [query name value where & rest]
(let [query (-> query
@@ -20,15 +20,9 @@
(defn get-by-id [id]
(->>
(dc/q (-> {:query {:find [default-read]
:in ['$]
:where []}
:args [(dc/db conn)]}
(add-arg '?e id ['?e])))
(map first)
(<-datomic)
(first)))
(->> [(dc/pull (dc/db conn default-read id))]
(<-datomic)
(first)))

View File

@@ -6,12 +6,13 @@
apply-sort-3
conn
merge-query
pull-many]]
pull-many
query2]]
[auto-ap.graphql.utils :refer [limited-clients]]
[clj-time.coerce :as c]
[datomic.client.api :as dc]
[clojure.set :refer [rename-keys]]
[clojure.tools.logging :as log]))
[clojure.tools.logging :as log]
[datomic.api :as dc]))
(defn <-datomic [result]
(-> result
@@ -154,8 +155,7 @@
(log/info query)
(cond->> query
true (dc/q)
(cond->> (query2 query)
true (apply-sort-3 (assoc args :default-asc? false))
true (apply-pagination args)))))
@@ -178,11 +178,10 @@
(defn filter-ids [ids]
(if ids
(->> {:query {:find ['?e]
:in ['$ '[?e ...]]
:where ['[?e :payment/date]]}
:args [(dc/db conn) ids]}
(dc/q)
(->> (dc/q {:find ['?e]
:in ['$ '[?e ...]]
:where ['[?e :payment/date]]}
(dc/db conn) ids)
(map first)
vec)
[]))

View File

@@ -1,17 +1,19 @@
(ns auto-ap.datomic.clients
(:require
[auto-ap.datomic :refer [add-sorter-fields
apply-pagination
apply-sort-3
conn
merge-query
pull-many]]
[auto-ap.graphql.utils :refer [can-see-client? limited-clients]]
[auto-ap.datomic
:refer [add-sorter-fields
apply-pagination
apply-sort-3
conn
merge-query
pull-many
query2]]
[auto-ap.graphql.utils :refer [limited-clients]]
[auto-ap.search :as search]
[clj-time.coerce :as coerce]
[clojure.string :as str]
[datomic.client.api :as dc]
[com.brunobonacci.mulog :as mu]))
[com.brunobonacci.mulog :as mu]
[datomic.api :as dc]))
(def full-read '[*
{:client/square-integration-status [:integration-status/message
@@ -97,10 +99,10 @@
(defn code->id [code]
(->>
(dc/q (-> {:query {:find ['?e]
:in ['$ '?code]
:where [['?e :client/code '?code ]]}
:args [(dc/db conn) code]}))
(dc/q (-> {:find ['?e]
:in ['$ '?code]
:where [['?e :client/code '?code ]]}
(dc/db conn) code))
(first)
(first)))
@@ -155,8 +157,7 @@
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :client/name ?sort-default]]}}))]
(mu/log ::q
:query query)
(->> query
(dc/q)
(->> (query2 query)
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
(apply-pagination args))))

View File

@@ -1,10 +1,16 @@
(ns auto-ap.datomic.expected-deposit
(:require
[auto-ap.datomic
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query pull-many]]
:refer [add-sorter-fields
apply-pagination
apply-sort-3
conn
merge-query
pull-many
query2]]
[auto-ap.graphql.utils :refer [limited-clients]]
[clj-time.coerce :as c]
[datomic.client.api :as dc]))
[datomic.api :as dc]))
(defn <-datomic [result]
(let [transaction (first (:transaction/_expected-deposit result))
@@ -87,8 +93,7 @@
(merge-query {:query {:find ['?sort-default '?e]
:where ['[?e :expected-deposit/date ?sort-default]]}}))]
(cond->> query
true (dc/q)
(cond->> (query2 query)
true (apply-sort-3 args)
true (apply-pagination args))))

View File

@@ -3,6 +3,7 @@
[auto-ap.datomic
:refer [add-sorter-fields
apply-pagination
query2
apply-sort-3
conn
merge-query
@@ -14,7 +15,7 @@
[clj-time.coerce :as coerce]
[clj-time.core :as time]
[clojure.set :refer [rename-keys]]
[datomic.client.api :as dc]
[datomic.api :as dc]
[iol-ion.tx :refer [random-tempid]]))
(def default-read '[*
@@ -45,134 +46,134 @@
([args]
(raw-graphql-ids (dc/db conn) args))
([db args]
(->> (cond-> {:query {:find []
:in ['$]
:where ['[?e :invoice/client]]}
:args [db]}
(let [query (cond-> {:query {:find []
:in ['$]
:where ['[?e :invoice/client]]}
:args [db]}
(:exact-match-id args)
(merge-query {:query {:in ['?e]
:where []}
:args [(:exact-match-id args)]})
(limited-clients (:id args))
(merge-query {:query {:in ['[?xx ...]]
:where ['[?e :invoice/client ?xx]]}
:args [ (set (map :db/id (limited-clients (:id args))))]})
(:client-id args)
(merge-query {:query {:in ['?client-id]
:where ['[?e :invoice/client ?client-id]]}
:args [ (:client-id args)]})
(:exact-match-id args)
(merge-query {:query {:in ['?e]
:where []}
:args [(:exact-match-id args)]})
(limited-clients (:id args))
(merge-query {:query {:in ['[?xx ...]]
:where ['[?e :invoice/client ?xx]]}
:args [ (set (map :db/id (limited-clients (:id args))))]})
(:client-id args)
(merge-query {:query {:in ['?client-id]
:where ['[?e :invoice/client ?client-id]]}
:args [ (:client-id args)]})
(:client-code args)
(merge-query {:query {:in ['?client-code]
:where ['[?e :invoice/client ?client-id]
'[?client-id :client/code ?client-code]]}
:args [ (:client-code args)]})
(:client-code args)
(merge-query {:query {:in ['?client-code]
:where ['[?e :invoice/client ?client-id]
'[?client-id :client/code ?client-code]]}
:args [ (:client-code args)]})
(:original-id args)
(merge-query {:query {:in ['?original-id]
:where [
'[?e :invoice/client ?c]
'[?c :client/original-id ?original-id]]}
:args [ (cond-> (:original-id args)
(string? (:original-id args)) Long/parseLong )]})
(:original-id args)
(merge-query {:query {:in ['?original-id]
:where [
'[?e :invoice/client ?c]
'[?c :client/original-id ?original-id]]}
:args [ (cond-> (:original-id args)
(string? (:original-id args)) Long/parseLong )]})
(:start (:date-range args)) (merge-query {:query {:in '[?start-date]
:where ['[?e :invoice/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 :invoice/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 :invoice/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 :invoice/date ?date]
'[(<= ?date ?end-date)]]}
:args [(coerce/to-date (:end (:date-range args)))]})
(:start (:due-range args)) (merge-query {:query {:in '[?start-due]
:where ['[?e :invoice/due ?due]
'[(>= ?due ?start-due)]]}
:args [(coerce/to-date (:start (:due-range args)))]})
(:start (:due-range args)) (merge-query {:query {:in '[?start-due]
:where ['[?e :invoice/due ?due]
'[(>= ?due ?start-due)]]}
:args [(coerce/to-date (:start (:due-range args)))]})
(:end (:due-range args)) (merge-query {:query {:in '[?end-due]
:where ['[?e :invoice/due ?due]
'[(<= ?due ?end-due)]]}
:args [(coerce/to-date (:end (:due-range args)))]})
(:end (:due-range args)) (merge-query {:query {:in '[?end-due]
:where ['[?e :invoice/due ?due]
'[(<= ?due ?end-due)]]}
:args [(coerce/to-date (:end (:due-range args)))]})
(:import-status args)
(merge-query {:query {:in ['?import-status]
:where ['[?e :invoice/import-status ?import-status]]}
:args [ (keyword "import-status" (:import-status args))]})
(:status args)
(merge-query {:query {:in ['?status]
:where ['[?e :invoice/status ?status]]}
:args [ (:status args)]})
(:vendor-id args)
(merge-query {:query {:in ['?vendor-id]
:where ['[?e :invoice/vendor ?vendor-id]]}
:args [ (:vendor-id args)]})
(:import-status args)
(merge-query {:query {:in ['?import-status]
:where ['[?e :invoice/import-status ?import-status]]}
:args [ (keyword "import-status" (:import-status args))]})
(:status args)
(merge-query {:query {:in ['?status]
:where ['[?e :invoice/status ?status]]}
:args [ (:status args)]})
(:vendor-id args)
(merge-query {:query {:in ['?vendor-id]
:where ['[?e :invoice/vendor ?vendor-id]]}
:args [ (:vendor-id args)]})
(:account-id args)
(merge-query {:query {:in ['?account-id]
:where ['[?e :invoice/expense-accounts ?iea ?]
'[?iea :invoice-expense-account/account ?account-id]]}
:args [ (:account-id args)]})
(:account-id args)
(merge-query {:query {:in ['?account-id]
:where ['[?e :invoice/expense-accounts ?iea ?]
'[?iea :invoice-expense-account/account ?account-id]]}
:args [ (:account-id args)]})
(:amount-gte args)
(merge-query {:query {:in ['?amount-gte]
:where ['[?e :invoice/total ?total-filter]
'[(>= ?total-filter ?amount-gte)]]}
:args [(:amount-gte args)]})
(:amount-gte args)
(merge-query {:query {:in ['?amount-gte]
:where ['[?e :invoice/total ?total-filter]
'[(>= ?total-filter ?amount-gte)]]}
:args [(:amount-gte args)]})
(:amount-lte args)
(merge-query {:query {:in ['?amount-lte]
:where ['[?e :invoice/total ?total-filter]
'[(<= ?total-filter ?amount-lte)]]}
:args [(:amount-lte args)]})
(:amount-lte args)
(merge-query {:query {:in ['?amount-lte]
:where ['[?e :invoice/total ?total-filter]
'[(<= ?total-filter ?amount-lte)]]}
:args [(:amount-lte args)]})
(seq (:invoice-number-like args))
(merge-query {:query {:in ['?invoice-number-like]
:where ['[?e :invoice/invoice-number ?invoice-number]
'[(.contains ^String ?invoice-number ?invoice-number-like)]]}
:args [(:invoice-number-like args)]})
(seq (:invoice-number-like args))
(merge-query {:query {:in ['?invoice-number-like]
:where ['[?e :invoice/invoice-number ?invoice-number]
'[(.contains ^String ?invoice-number ?invoice-number-like)]]}
:args [(:invoice-number-like args)]})
(:scheduled-payments args)
(merge-query {:query {:in []
:where ['[?e :invoice/scheduled-payment]]}
:args []})
(:scheduled-payments args)
(merge-query {:query {:in []
:where ['[?e :invoice/scheduled-payment]]}
:args []})
(:unresolved args)
(merge-query {:query {:in []
:where ['(or-join [?e]
(not [?e :invoice/expense-accounts ])
(and [?e :invoice/expense-accounts ?ea]
(not [?ea :invoice-expense-account/account])))]}
:args []})
(:unresolved args)
(merge-query {:query {:in []
:where ['(or-join [?e]
(not [?e :invoice/expense-accounts ])
(and [?e :invoice/expense-accounts ?ea]
(not [?ea :invoice-expense-account/account])))]}
:args []})
(seq (:location args))
(merge-query {:query {:in ['?location]
:where ['[?e :invoice/expense-accounts ?eas]
'[?eas :invoice-expense-account/location ?location]]}
:args [(:location args)]})
(seq (:location args))
(merge-query {:query {:in ['?location]
:where ['[?e :invoice/expense-accounts ?eas]
'[?eas :invoice-expense-account/location ?location]]}
:args [(:location args)]})
(:sort args) (add-sorter-fields {"client" ['[?e :invoice/client ?c]
'[?c :client/name ?sort-client]]
"vendor" ['[?e :invoice/vendor ?v]
'[?v :vendor/name ?sort-vendor]]
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
"location" ['[?e :invoice/expense-accounts ?iea]
'[?iea :invoice-expense-account/location ?sort-location]]
"date" ['[?e :invoice/date ?sort-date]]
"due" ['[(get-else $ ?e :invoice/due #inst "2050-01-01") ?sort-due]]
"invoice-number" ['[?e :invoice/invoice-number ?sort-invoice-number]]
"total" ['[?e :invoice/total ?sort-total]]
"outstanding-balance" ['[?e :invoice/outstanding-balance ?sort-outstanding-balance]]}
args)
true
(merge-query {:query {:find ['?sort-default '?e ]
:where ['[?e :invoice/client]
'[?e :invoice/date ?sort-default]]}}) )
(dc/q)
(apply-sort-3 args)
(apply-pagination args))))
(:sort args) (add-sorter-fields {"client" ['[?e :invoice/client ?c]
'[?c :client/name ?sort-client]]
"vendor" ['[?e :invoice/vendor ?v]
'[?v :vendor/name ?sort-vendor]]
"description-original" ['[?e :transaction/description-original ?sort-description-original]]
"location" ['[?e :invoice/expense-accounts ?iea]
'[?iea :invoice-expense-account/location ?sort-location]]
"date" ['[?e :invoice/date ?sort-date]]
"due" ['[(get-else $ ?e :invoice/due #inst "2050-01-01") ?sort-due]]
"invoice-number" ['[?e :invoice/invoice-number ?sort-invoice-number]]
"total" ['[?e :invoice/total ?sort-total]]
"outstanding-balance" ['[?e :invoice/outstanding-balance ?sort-outstanding-balance]]}
args)
true
(merge-query {:query {:find ['?sort-default '?e ]
:where ['[?e :invoice/client]
'[?e :invoice/date ?sort-default]]}}) )]
(->> (query2 query)
(apply-sort-3 args)
(apply-pagination args)))))
(defn graphql-results [ids db _]
@@ -188,12 +189,11 @@
(defn sum-outstanding [ids]
(->>
(dc/q {:query {:find ['?id '?o]
:in ['$ '[?id ...]]
:where ['[?id :invoice/outstanding-balance ?o]]
}
:args [(dc/db conn)
ids]})
(dc/q {:find ['?id '?o]
:in ['$ '[?id ...]]
:where ['[?id :invoice/outstanding-balance ?o]]}
(dc/db conn)
ids)
(map last)
(reduce
+
@@ -202,12 +202,12 @@
(defn sum-total-amount [ids]
(->>
(dc/q {:query {:find ['?id '?o]
:in ['$ '[?id ...]]
:where ['[?id :invoice/total ?o]]
}
:args [(dc/db conn)
ids]})
(dc/q {:find ['?id '?o]
:in ['$ '[?id ...]]
:where ['[?id :invoice/total ?o]]
}
(dc/db conn)
ids)
(map last)
(reduce
+
@@ -240,38 +240,35 @@
(defn find-conflicting [{:keys [:invoice/invoice-number :invoice/vendor :invoice/client :db/id]}]
(->> (dc/q
(cond-> {:query {:find [(list 'pull '?e default-read)]
:in ['$ '?invoice-number '?vendor '?client '?invoice-id]
:where '[[?e :invoice/invoice-number ?invoice-number]
[?e :invoice/vendor ?vendor]
[?e :invoice/client ?client]
(not [?e :invoice/status :invoice-status/voided])
[(not= ?e ?invoice-id)]]}
:args [(dc/db conn) invoice-number vendor client (or id 0)]}))
{:find [(list 'pull '?e default-read)]
:in ['$ '?invoice-number '?vendor '?client '?invoice-id]
:where '[[?e :invoice/invoice-number ?invoice-number]
[?e :invoice/vendor ?vendor]
[?e :invoice/client ?client]
(not [?e :invoice/status :invoice-status/voided])
[(not= ?e ?invoice-id)]]}
(dc/db conn) invoice-number vendor client (or id 0))
(map first)
(map <-datomic)))
(defn get-existing-set []
(let [vendored-results (set (dc/q {:query {:find ['?vendor '?client '?invoice-number]
:in ['$]
:where '[[?e :invoice/invoice-number ?invoice-number]
[?e :invoice/vendor ?vendor]
[?e :invoice/client ?client]
(not [?e :invoice/status :invoice-status/voided])
]}
:args [(dc/db conn)]}))
vendorless-results (->> (dc/q {:query {:find ['?client '?invoice-number]
:in ['$]
:where '[[?e :invoice/invoice-number ?invoice-number]
(not [?e :invoice/vendor])
[?e :invoice/client ?client]
(not [?e :invoice/status :invoice-status/voided])
]}
:args [(dc/db conn)]})
(let [vendored-results (set (dc/q {:find ['?vendor '?client '?invoice-number]
:in ['$]
:where '[[?e :invoice/invoice-number ?invoice-number]
[?e :invoice/vendor ?vendor]
[?e :invoice/client ?client]
(not [?e :invoice/status :invoice-status/voided])
]}
(dc/db conn)))
vendorless-results (->> (dc/q {:find ['?client '?invoice-number]
:in ['$]
:where '[[?e :invoice/invoice-number ?invoice-number]
(not [?e :invoice/vendor])
[?e :invoice/client ?client]
(not [?e :invoice/status :invoice-status/voided])
]}
(dc/db conn))
(mapv (fn [[client invoice-number]]
[nil client invoice-number]) )
set)]
@@ -279,13 +276,13 @@
(defn filter-ids [ids]
(if ids
(->> {:query {:find ['?e]
:in ['$ '[?e ...]]
:where ['[?e :invoice/date]]}
:args [(dc/db conn) ids]}
(dc/q)
(map first)
vec)
(->>
(dc/q {:find ['?e]
:in ['$ '[?e ...]]
:where ['[?e :invoice/date]]}
(dc/db conn) ids)
(map first)
vec)
[]))
(defn code-invoice [invoice]

View File

@@ -6,11 +6,12 @@
apply-sort-3
conn
merge-query
pull-many]]
pull-many
query2]]
[auto-ap.datomic.accounts :as d-accounts]
[auto-ap.graphql.utils :refer [limited-clients]]
[clj-time.coerce :as c]
[datomic.client.api :as dc]))
[datomic.api :as dc]))
(defn raw-graphql-ids [db args]
(let [query (cond-> {:query {:find []
@@ -126,8 +127,7 @@
true
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :journal-entry/date ?sort-default]]}}))]
(->> query
(dc/q)
(->> (query2 query)
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
(apply-pagination args))))
@@ -168,11 +168,10 @@
(defn filter-ids [ids]
(if ids
(->> {:query {:find ['?e]
:in ['$ '[?e ...]]
:where ['[?e :journal-entry/date]]}
:args [(dc/db conn) ids]}
(dc/q)
(->> (dc/q {:find ['?e]
:in ['$ '[?e ...]]
:where ['[?e :journal-entry/date]]}
(dc/db conn) ids)
(map first)
vec)
[]))

View File

@@ -6,10 +6,11 @@
apply-sort-3
conn
merge-query
pull-many]]
pull-many
query2]]
[auto-ap.graphql.utils :refer [can-see-client? limited-clients]]
[clj-time.coerce :as c]
[datomic.client.api :as dc]))
[datomic.api :as dc]))
(defn raw-graphql-ids [db args]
(let [query (cond-> {:query {:find []
@@ -37,8 +38,7 @@
true
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :report/created ?sort-default]]}}))]
(->> query
(dc/q)
(->> (query2 query)
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
(apply-pagination args))))

View File

@@ -4,18 +4,18 @@
:refer [add-sorter-fields-2
apply-pagination
apply-sort-3
pull-id
conn
merge-query
pull-id
pull-many
visible-clients
conn]]
[iol-ion.query]
query2
visible-clients]]
[clj-time.coerce :as c]
[clj-time.core :as time]
[clojure.set :as set]
[datomic.client.api :as dc]
[com.brunobonacci.mulog :as mu]
))
[datomic.api :as dc]
[iol-ion.query]))
(defn <-datomic [result]
(-> result
@@ -115,8 +115,7 @@
:stats (:query-stats (dc/q (assoc query :query-stats true)))
:q (str query))
(cond->> query
true (dc/q)
(cond->> (query2 query)
true (apply-sort-3 (assoc args :default-asc? false))
true (apply-pagination args))))
@@ -132,14 +131,14 @@
(defn summarize-orders [ids]
(let [[total tax] (->>
(dc/q {:query {:find ['(sum ?t) '(sum ?tax)]
:with ['?id]
:in ['$ '[?id ...]]
:where ['[?id :sales-order/total ?t]
'[?id :sales-order/tax ?tax]]}
:args [(dc/db conn)
ids]})
first)]
(dc/q {:find ['(sum ?t) '(sum ?tax)]
:with ['?id]
:in ['$ '[?id ...]]
:where ['[?id :sales-order/total ?t]
'[?id :sales-order/tax ?tax]]}
(dc/db conn)
ids)
first)]
{:total total
:tax tax}))

View File

@@ -6,10 +6,11 @@
apply-sort-3
conn
merge-query
pull-many]]
pull-many
query2]]
[auto-ap.graphql.utils :refer [limited-clients]]
[clojure.string :as str]
[datomic.client.api :as dc]))
[datomic.api :as dc]))
(defn <-datomic [result]
result)
@@ -82,8 +83,7 @@
:where ['[?e :transaction-rule/transaction-approval-status]]}}))]
(cond->> query
true (dc/q)
(cond->> (query2 query)
true (apply-sort-3 args)
true (apply-pagination args))))
@@ -109,10 +109,10 @@
(defn get-all []
(mapv first
(dc/q {:query {:find [(list 'pull '?e default-read )]
:in ['$]
:where ['[?e :transaction-rule/transaction-approval-status]]}
:args [(dc/db conn)]})))
(dc/q {:find [(list 'pull '?e default-read )]
:in ['$]
:where ['[?e :transaction-rule/transaction-approval-status]]}
(dc/db conn))))
(defn get-all-for-client [client-id]
(mapv first

View File

@@ -1,13 +1,19 @@
(ns auto-ap.datomic.transactions
(:require
[auto-ap.datomic
:refer [add-sorter-fields apply-pagination apply-sort-3 conn merge-query conn pull-many]]
:refer [add-sorter-fields
apply-pagination
apply-sort-3
conn
merge-query
pull-many
query2]]
[auto-ap.datomic.accounts :as d-accounts]
[auto-ap.graphql.utils :refer [limited-clients]]
[clj-time.coerce :as coerce]
[clojure.string :as str]
[clojure.tools.logging :as log]
[datomic.client.api :as dc]))
[datomic.api :as dc]))
(defn potential-duplicate-ids [db args]
(when (and (:potential-duplicates args)
@@ -168,8 +174,7 @@
'[?e :transaction/date ?sort-default]
'(not [?e :transaction/approval-status :transaction-approval-status/suppressed])]}}))]
(log/info "query is" query)
(cond->> query
true (dc/q)
(cond->> (query2 query)
true (apply-sort-3 (assoc args :default-asc? false))
true (apply-pagination args)))))
@@ -220,11 +225,10 @@
(defn filter-ids [ids]
(if ids
(->> {:query {:find ['?e]
:in ['$ '[?e ...]]
:where ['[?e :transaction/date]]}
:args [(dc/db conn) ids]}
(dc/q)
(->> (dc/q {:find ['?e]
:in ['$ '[?e ...]]
:where ['[?e :transaction/date]]}
(dc/db conn) ids)
(map first)
vec)
[]))

View File

@@ -1,7 +1,7 @@
(ns auto-ap.datomic.users
(:require
[auto-ap.datomic :refer [conn]]
[datomic.client.api :as dc]))
[datomic.api :as dc]))
(defn add-arg [query name value where & rest]
(let [query (-> query
@@ -11,53 +11,46 @@
(reduce #(update-in %1 [:query :where] conj %2) query rest)))
(defn get-by-id [id]
(let [query (-> {:query {:find ['(pull ?e [*
{:user/clients [*]}
{:user/role [:db/ident]}])]
:in ['$]
:where []}
:args [(dc/db conn)]}
(add-arg '?e id ['?e]))]
(->> (dc/q query)
(map first)
(map #(update % :user/role :db/ident))
first)))
(->> [(dc/pull (dc/db conn)
'[*
{:user/clients [*]}
{:user/role [:db/ident]}]
id)]
(map #(update % :user/role :db/ident))
first))
(defn find-or-insert! [{:keys [:user/provider :user/provider-id] :as new-user}]
(let [is-first-user? (not (seq (dc/q {:query [:find '?e
:in '$
:where '[?e :user/provider]]
:args [(dc/db conn)]})))
user (some-> {:query [:find '(pull ?e [*
{:user/clients [*]}
{:user/role [:db/ident]}])
:in '$ '?provider '?provider-id
:where '[?e :user/provider ?provider]
'[?e :user/provider-id ?provider-id]]
:args [(dc/db conn) provider provider-id]}
(dc/q)
(let [is-first-user? (not (seq (dc/q [:find '?e
:in '$
:where '[?e :user/provider]]
(dc/db conn))))
user (some-> (dc/q [:find '(pull ?e [*
{:user/clients [*]}
{:user/role [:db/ident]}])
:in '$ '?provider '?provider-id
:where '[?e :user/provider ?provider]
'[?e :user/provider-id ?provider-id]]
(dc/db conn) provider provider-id)
first
first
(update :user/role :db/ident))]
(if user
user
(let [new-user-trans (dc/transact conn {:tx-data [(cond-> new-user
true (assoc :db/id "user")
is-first-user? (assoc :user/role :user-role/admin))]})]
(let [new-user-trans @(dc/transact conn [(cond-> new-user
true (assoc :db/id "user")
is-first-user? (assoc :user/role :user-role/admin))])]
(get-by-id (-> new-user-trans :tempids (get "user")))))))
(defn raw-graphql [_]
(let [query (cond-> {:query {:find ['(pull ?e [*
{:user/clients [*]}
{:user/role [:db/ident]}])]
:in ['$]
:where ['[?e :user/role]]}
:args [(dc/db conn)]})]
(->> (dc/q query)
(map first)
(map #(update % :user/role :db/ident))
)))
(->> (dc/q {:find ['(pull ?e [*
{:user/clients [*]}
{:user/role [:db/ident]}])]
:in ['$]
:where ['[?e :user/role]]}
(dc/db conn))
(map first)
(map #(update % :user/role :db/ident))
))
(defn sort-fn [args]
(cond

View File

@@ -1,10 +1,17 @@
(ns auto-ap.datomic.vendors
(:require
[auto-ap.datomic :refer [conn merge-query add-sorter-fields apply-pagination merge-query apply-sort-3 pull-many]]
[auto-ap.datomic
:refer [add-sorter-fields
apply-pagination
apply-sort-3
conn
merge-query
pull-many
query2]]
[auto-ap.datomic.accounts :as d-accounts]
[auto-ap.graphql.utils :refer [limited-clients]]
[clojure.string :as str]
[datomic.client.api :as dc]
[auto-ap.datomic.accounts :as d-accounts]))
[datomic.api :as dc]))
(defn <-datomic [a]
(cond-> a
@@ -63,8 +70,7 @@
:where ['[?e :vendor/name]]}}))]
(cond->> query
true (dc/q)
(cond->> (query2 query)
true (apply-sort-3 args)
true (apply-pagination args))))
@@ -102,11 +108,10 @@
)
(defn get-graphql-by-id [args id]
(->> (cond-> {:query {:find [(list 'pull '?e default-read)]
:in ['$ '?e]
:where ['[?e :vendor/name]]}
:args [(dc/db conn) id]})
(dc/q)
(->> (dc/q {:find [(list 'pull '?e default-read)]
:in ['$ '?e]
:where ['[?e :vendor/name]]}
(dc/db conn) id)
(map first)
(map #(cleanse (:id args) %))
(map <-datomic)

View File

@@ -1,10 +1,16 @@
(ns auto-ap.datomic.yodlee2
(:require
[auto-ap.datomic
:refer [add-sorter-fields apply-pagination apply-sort-3 merge-query conn pull-many]]
:refer [add-sorter-fields
apply-pagination
apply-sort-3
conn
merge-query
pull-many
query2]]
[auto-ap.graphql.utils :refer [limited-clients]]
[clj-time.coerce :as c]
[datomic.client.api :as dc]))
[datomic.api :as dc]))
(def default-read '[*])
@@ -39,7 +45,7 @@
(merge-query {:query {:find ['?e ]
:where ['[?e :yodlee-provider-account/id]]}}) )
(dc/q)
(query2)
(apply-sort-3 args)
(apply-pagination args)))

View File

@@ -1,14 +1,13 @@
(ns auto-ap.datomic.yodlee-merchants
(:require
[auto-ap.datomic :refer [conn]]
[datomic.client.api :as dc]))
[datomic.api :as dc]))
(defn get-merchants [_]
;; TODO admin?
(let [query {:query {:find ['(pull ?e [:yodlee-merchant/name :yodlee-merchant/yodlee-id :db/id])]
:in ['$]
:where [['?e :yodlee-merchant/name]]}
:args [(dc/db conn)]}]
(->>
(dc/q query)
(mapv first))))
(->>
(dc/q {:find ['(pull ?e [:yodlee-merchant/name :yodlee-merchant/yodlee-id :db/id])]
:in ['$]
:where [['?e :yodlee-merchant/name]]}
(dc/db conn))
(mapv first)))