Adding transaction approval status to transaction page
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(ns auto-ap.graphql.transactions
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin]]
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin ident->enum-f snake->kebab]]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
@@ -17,11 +17,17 @@
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[clj-time.coerce :as coerce]))
|
||||
(defn prn-each [xs]
|
||||
(doseq [x xs]
|
||||
(println x))
|
||||
xs)
|
||||
|
||||
(def approval-status->graphql (ident->enum-f :transaction/approval-status))
|
||||
|
||||
(defn get-transaction-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[transactions transactions-count] (d-transactions/get-graphql (<-graphql args))
|
||||
transactions (map ->graphql transactions)]
|
||||
transactions (map ->graphql (map approval-status->graphql transactions))]
|
||||
[{:transactions transactions
|
||||
:total transactions-count
|
||||
:count (count transactions)
|
||||
@@ -45,7 +51,7 @@
|
||||
set)]
|
||||
(set/difference existing-ids specified-ids)))
|
||||
|
||||
(defn edit-transaction [context {{:keys [id exclude_from_ledger accounts vendor_id] :as transaction} :transaction} value]
|
||||
(defn edit-transaction [context {{:keys [id exclude_from_ledger accounts vendor_id approval_status] :as transaction} :transaction} value]
|
||||
(let [existing-transaction (d-transactions/get-by-id id)
|
||||
_ (assert-can-see-client (:id context) (:transaction/client existing-transaction) )
|
||||
deleted (deleted-accounts existing-transaction accounts)
|
||||
@@ -69,13 +75,19 @@
|
||||
@(d/transact (d/connect uri)
|
||||
(concat [(remove-nils {:db/id id
|
||||
:transaction/vendor vendor_id
|
||||
:transaction/approval-status (some->> approval_status
|
||||
name
|
||||
snake->kebab
|
||||
(keyword "transaction-approval-status"))
|
||||
:transaction/exclude-from-ledger exclude_from_ledger
|
||||
:transaction/accounts (map transaction-account->entity accounts)
|
||||
})]
|
||||
(map (fn [d]
|
||||
[:db/retract id :transaction/accounts d])
|
||||
deleted)))
|
||||
(->graphql (d-transactions/get-by-id id))))
|
||||
(-> (d-transactions/get-by-id id)
|
||||
approval-status->graphql
|
||||
->graphql)))
|
||||
|
||||
(defn match-transaction [context {:keys [transaction_id payment_id]} value]
|
||||
(let [transaction (d-transactions/get-by-id transaction_id)
|
||||
@@ -103,7 +115,9 @@
|
||||
:transaction-account/amount (Math/abs (:transaction/amount transaction))}]}]
|
||||
(map (fn [x] [:db/retractEntity (:db/id x)] )
|
||||
(:transaction/accounts transaction)))))
|
||||
(->graphql (d-transactions/get-by-id transaction_id)))
|
||||
(-> (d-transactions/get-by-id transaction_id)
|
||||
approval-status->graphql
|
||||
->graphql))
|
||||
|
||||
(defn match-transaction-rule [context {:keys [transaction_id transaction_rule_id]} value]
|
||||
(let [_ (assert-admin (:id context))
|
||||
@@ -122,4 +136,6 @@
|
||||
|
||||
;; TODO use bank account locations as well
|
||||
(-> transaction :transaction/client :client/locations))]))
|
||||
(->graphql (d-transactions/get-by-id transaction_id)))
|
||||
(-> (d-transactions/get-by-id transaction_id)
|
||||
approval-status->graphql
|
||||
->graphql))
|
||||
|
||||
Reference in New Issue
Block a user