allowing users to self service delete links to payments.
This commit is contained in:
@@ -911,6 +911,10 @@
|
||||
:all {:type 'Boolean}
|
||||
:transaction_rule_id {:type :id}}
|
||||
:resolve :mutation/match-transaction-rules}
|
||||
|
||||
:unlink_transaction {:type :transaction
|
||||
:args {:transaction_id {:type :id}}
|
||||
:resolve :mutation/unlink-transaction}
|
||||
:void_invoice {:type :invoice
|
||||
:args {:invoice_id {:type :id}}
|
||||
:resolve :mutation/void-invoice}
|
||||
@@ -1183,6 +1187,7 @@
|
||||
:mutation/add-and-print-invoice gq-invoices/add-and-print-invoice
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
:mutation/edit-transaction gq-transactions/edit-transaction
|
||||
:mutation/unlink-transaction gq-transactions/unlink-transaction
|
||||
:mutation/unapprove-transactions gq-transactions/unapprove-transactions
|
||||
:mutation/delete-external-ledger gq-ledger/delete-external-ledger
|
||||
:mutation/delete-transactions gq-transactions/delete-transactions
|
||||
|
||||
@@ -80,6 +80,43 @@
|
||||
(:id context))
|
||||
{:message (str "Succesfully deleted " (count all-ids) " transactions.")}))
|
||||
|
||||
(defn unlink-transaction [context args value]
|
||||
(let [_ (assert-admin (:id context))
|
||||
args (assoc args :id (:id context))
|
||||
transaction-id (:transaction_id args)
|
||||
transaction (d/pull (d/db conn)
|
||||
[:transaction/approval-status
|
||||
:transaction/status
|
||||
:transaction/location
|
||||
:transaction/vendor
|
||||
:transaction/accounts
|
||||
|
||||
{:transaction/payment [{:payment/status [:db/ident]} :db/id]} ]
|
||||
transaction-id)
|
||||
payment (-> transaction :transaction/payment )
|
||||
]
|
||||
|
||||
(log/info "Unlinking " transaction-id " from payment " payment)
|
||||
(when (not= :payment-status/cleared (-> payment :payment/status :db/ident))
|
||||
(throw (ex-info "Payment can't be undone because it isn't cleared." {:validation-error "Payment can't be undone because it isn't cleared."})))
|
||||
(audit-transact
|
||||
(into [{:db/id (:db/id payment)
|
||||
:payment/status :payment-status/pending}
|
||||
{:db/id transaction-id
|
||||
:transaction/approval-status :transaction-approval-status/unapproved}
|
||||
[:db/retract transaction-id :transaction/payment (:db/id payment)]
|
||||
[:db/retract transaction-id :transaction/vendor (:db/id (:transaction/vendor transaction))]
|
||||
[:db/retract transaction-id :transaction/location (:transaction/location transaction)]]
|
||||
|
||||
(map (fn [a]
|
||||
[:db/retract transaction-id :transaction/accounts (:db/id a)])
|
||||
(:transaction/accounts transaction)))
|
||||
(:id context))
|
||||
(-> (d-transactions/get-by-id transaction-id)
|
||||
approval-status->graphql
|
||||
->graphql)))
|
||||
|
||||
|
||||
(defn transaction-account->entity [{:keys [id account_id amount location]}]
|
||||
(remove-nils #:transaction-account {:amount (Double/parseDouble amount)
|
||||
:db/id id
|
||||
|
||||
Reference in New Issue
Block a user