basic ability to test.
This commit is contained in:
@@ -300,6 +300,10 @@
|
||||
:args {:client_id {:type :id}}
|
||||
:resolve :get-expense-account-stats}
|
||||
|
||||
:test_transaction_rule {:type '(list :transaction)
|
||||
:args {:transaction_rule {:type :edit_transaction_rule}}
|
||||
:resolve :test-transaction-rule}
|
||||
|
||||
:invoice_stats {:type '(list :invoice_stat)
|
||||
:args {:client_id {:type :id}}
|
||||
:resolve :get-invoice-stats}
|
||||
@@ -760,6 +764,7 @@
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
:mutation/edit-transaction gq-transactions/edit-transaction
|
||||
:mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule
|
||||
:test-transaction-rule gq-transaction-rules/test-transaction-rule
|
||||
:mutation/match-transaction gq-transactions/match-transaction
|
||||
:mutation/edit-client gq-clients/edit-client
|
||||
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
(ns auto-ap.graphql.transaction-rules
|
||||
(:require [auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.datomic.transactions :as t]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [remove-nils uri]]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]))
|
||||
[auto-ap.datomic :refer [remove-nils uri merge-query]]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]
|
||||
[clj-time.coerce :as c]))
|
||||
|
||||
(defn get-transaction-rule-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql args))]
|
||||
(result->page journal-entries journal-entries-count :transaction_rules args)))
|
||||
|
||||
;; TODO ASSERT ADMIN
|
||||
(defn upsert-transaction-rule [context {{:keys [id description note client_id bank_account_id amount_lte amount_gte ]} :transaction_rule :as z} value]
|
||||
(let [transaction [(remove-nils #:transaction-rule {:db/id (if id
|
||||
id
|
||||
@@ -21,8 +24,41 @@
|
||||
:amount-gte amount_gte})]
|
||||
_ (println transaction)
|
||||
transaction-result @(d/transact (d/connect uri) transaction)]
|
||||
(println "HI" (or (-> transaction-result )
|
||||
id))
|
||||
(-> (tr/get-by-id (or (-> transaction-result :tempids (get "transaction-rule"))
|
||||
id))
|
||||
(->graphql))))
|
||||
|
||||
(defn test-transaction-rule [{:keys [id]} {{:keys [description note client_id bank_account_id amount_lte amount_gte ]} :transaction_rule :as z} value]
|
||||
(->>
|
||||
(d/query
|
||||
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||
:transaction/bank-account [:bank-account/name]}
|
||||
])]
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [(d/db (d/connect uri))]}
|
||||
|
||||
(limited-clients id)
|
||||
(merge-query {:query {:in ['[?xx ...]]
|
||||
:where ['[?e :transaction/client ?xx]]}
|
||||
:args [(set (map :db/id (limited-clients id)))]})
|
||||
|
||||
bank_account_id
|
||||
(merge-query {:query {:in ['?bank-account-id]
|
||||
:where ['[?e :transaction/bank-account ?bank-account-id]]}
|
||||
:args [bank_account_id]})
|
||||
|
||||
client_id
|
||||
(merge-query {:query {:in ['?client-id]
|
||||
:where ['[?e :transaction/client ?client-id]]}
|
||||
:args [client_id]})
|
||||
true
|
||||
(merge-query {:query {:where ['[?e :transaction/id]]}})))
|
||||
(transduce (comp
|
||||
(take 15)
|
||||
(map first)
|
||||
(map (fn [x]
|
||||
(update x :transaction/date c/from-date)))
|
||||
(map ->graphql))
|
||||
conj
|
||||
[])))
|
||||
|
||||
Reference in New Issue
Block a user