A better way to allow bulk select.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
(ns auto-ap.datomic.transactions
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-3 apply-pagination add-sorter-fields]]
|
||||
[auto-ap.datomic :refer [uri merge-query apply-sort-3 apply-pagination add-sorter-fields conn]]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[clj-time.coerce :as c]
|
||||
[clj-time.coerce :as coerce]))
|
||||
@@ -149,6 +149,17 @@
|
||||
[(->> (graphql-results ids-to-retrieve db args))
|
||||
matching-count]))
|
||||
|
||||
(defn filter-ids [ids]
|
||||
(if ids
|
||||
(->> {:query {:find ['?e]
|
||||
:in ['$ '[?e ...]]
|
||||
:where ['[?e :transaction/date]]}
|
||||
:args [(d/db conn) ids]}
|
||||
(d/query)
|
||||
(map first)
|
||||
vec)
|
||||
[]))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(->
|
||||
(d/pull (d/db (d/connect uri))
|
||||
@@ -168,9 +179,17 @@
|
||||
(dissoc :transaction/id)))
|
||||
|
||||
(defn unapprove [ids]
|
||||
(doseq [x (partition-all 1000 ids)]
|
||||
(doseq [x (partition-all 100 ids)]
|
||||
@(d/transact (d/connect uri)
|
||||
(mapv (fn [i]
|
||||
{:db/id i
|
||||
:transaction/approval-status :transaction-approval-status/unapproved})
|
||||
x))))
|
||||
|
||||
(defn delete [ids]
|
||||
(doseq [x (partition-all 100 ids)]
|
||||
@(d/transact (d/connect uri)
|
||||
(mapcat (fn [i]
|
||||
[[:db/retractEntity i]
|
||||
[:db/retractEntity [:journal-entry/original-entity i]]])
|
||||
x))))
|
||||
|
||||
@@ -64,6 +64,8 @@
|
||||
%))}}
|
||||
:objects
|
||||
{
|
||||
:message
|
||||
{:fields {:message {:type 'String}}}
|
||||
:location_match
|
||||
{:fields {:location {:type 'String}
|
||||
:match {:type 'String}
|
||||
@@ -554,6 +556,7 @@
|
||||
:resolve :get-vendor}
|
||||
:user {:type '(list :user)
|
||||
:resolve :get-user}
|
||||
|
||||
}
|
||||
|
||||
:input-objects
|
||||
@@ -781,19 +784,14 @@
|
||||
:args {:invoices {:type '(list :id)}}
|
||||
:resolve :mutation/approve-invoices}
|
||||
|
||||
:unapprove_transactions {:type '(list :transaction_page)
|
||||
:args {:client_id {:type :id}
|
||||
:vendor_id {:type :id}
|
||||
:bank_account_id {:type :id}
|
||||
:date_range {:type :date_range}
|
||||
:amount_lte {:type :money}
|
||||
:amount_gte {:type :money}
|
||||
:description {:type 'String}
|
||||
:start {:type 'Int}
|
||||
:sort {:type '(list :sort_item)}
|
||||
:approval_status {:type :transaction_approval_status}}
|
||||
|
||||
:unapprove_transactions {:type :message
|
||||
:args {:filters {:type :transaction_filters}
|
||||
:ids {:type '(list :id)}}
|
||||
:resolve :mutation/unapprove-transactions}
|
||||
:delete_transactions {:type :message
|
||||
:args {:filters {:type :transaction_filters}
|
||||
:ids {:type '(list :id)}}
|
||||
:resolve :mutation/delete-transactions}
|
||||
:delete_transaction_rule {:type :id
|
||||
:args {:transaction_rule_id {:type :id}}
|
||||
:resolve :mutation/delete-transaction-rule}
|
||||
@@ -1129,6 +1127,7 @@
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
:mutation/edit-transaction gq-transactions/edit-transaction
|
||||
:mutation/unapprove-transactions gq-transactions/unapprove-transactions
|
||||
:mutation/delete-transactions gq-transactions/delete-transactions
|
||||
:mutation/upsert-transaction-rule gq-transaction-rules/upsert-transaction-rule
|
||||
:test-transaction-rule gq-transaction-rules/test-transaction-rule
|
||||
:run-transaction-rule gq-transaction-rules/run-transaction-rule
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
[auto-ap.datomic.accounts :as a]
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[clj-time.coerce :as coerce]))
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
(def approval-status->graphql (ident->enum-f :transaction/approval-status))
|
||||
|
||||
@@ -32,10 +33,37 @@
|
||||
:end (+ (:start (:filters args) 0) (count transactions))}))
|
||||
|
||||
(defn unapprove-transactions [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
ids (:ids (d-transactions/raw-graphql-ids (update (<-graphql args) :approval-status enum->keyword "transaction-approval-status")))]
|
||||
(d-transactions/unapprove ids)
|
||||
(get-transaction-page context args value)))
|
||||
(let [_ (assert-admin (:id context))
|
||||
args (assoc args :id (:id context))
|
||||
ids (some-> (:filters args)
|
||||
(<-graphql)
|
||||
(update :approval-status enum->keyword "transaction-approval-status")
|
||||
(assoc :per-page Integer/MAX_VALUE)
|
||||
(d-transactions/raw-graphql-ids )
|
||||
:ids)
|
||||
specific-ids (d-transactions/filter-ids (:ids args))
|
||||
all-ids (into (set ids) specific-ids)]
|
||||
|
||||
(log/info "Unapproving " (count all-ids) args)
|
||||
(d-transactions/unapprove all-ids)
|
||||
{:message (str "Succesfully unapproved " (count all-ids) " transactions.")}))
|
||||
|
||||
|
||||
(defn delete-transactions [context args value]
|
||||
(let [_ (assert-admin (:id context))
|
||||
args (assoc args :id (:id context))
|
||||
ids (some-> (:filters args)
|
||||
(<-graphql)
|
||||
(update :approval-status enum->keyword "transaction-approval-status")
|
||||
(assoc :per-page Integer/MAX_VALUE)
|
||||
(d-transactions/raw-graphql-ids )
|
||||
:ids)
|
||||
specific-ids (d-transactions/filter-ids (:ids args))
|
||||
all-ids (into (set ids) specific-ids)]
|
||||
|
||||
(log/info "Deleting " (count all-ids) args)
|
||||
(d-transactions/delete all-ids)
|
||||
{:message (str "Succesfully deleted " (count all-ids) " transactions.")}))
|
||||
|
||||
(defn transaction-account->entity [{:keys [id account_id amount location]}]
|
||||
(remove-nils #:transaction-account {:amount (Double/parseDouble amount)
|
||||
|
||||
Reference in New Issue
Block a user