graphql used for invoices
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.effects :as effects]
|
||||
[venia.core :as v]
|
||||
[bidi.bidi :as bidi]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -62,7 +63,7 @@
|
||||
(re-frame/reg-event-db
|
||||
::imported-invoices
|
||||
(fn [db [_ new-invoices]]
|
||||
(assoc-in db [:invoices] new-invoices)))
|
||||
(assoc-in db [:invoices :pending] new-invoices)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::approve-invoices
|
||||
@@ -79,23 +80,22 @@
|
||||
::view-pending-invoices
|
||||
(fn [cofx []]
|
||||
{:db (assoc-in (:db cofx) [:status :loading] true)
|
||||
:http {:method :get
|
||||
:token (-> cofx :db :user)
|
||||
:uri (str "/api/invoices/pending"
|
||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||
(str "?company=" company-id)))
|
||||
:on-success [::received-invoices :pending]}}))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:invoice
|
||||
{:imported false :company_id (:id @(re-frame/subscribe [::subs/company]))}
|
||||
[:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]]]]]}
|
||||
|
||||
:on-success [::received-invoices :pending]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::view-unpaid-invoices
|
||||
(fn [cofx []]
|
||||
{:db (assoc-in (:db cofx) [:status :loading] true)
|
||||
:http {:method :get
|
||||
:token (-> cofx :db :user)
|
||||
:uri (str "/api/invoices/unpaid"
|
||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||
(str "?company=" company-id)))
|
||||
:on-success [::received-invoices :unpaid]}}))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:invoice
|
||||
{:imported true :company_id (:id @(re-frame/subscribe [::subs/company]))}
|
||||
[:id :total :invoice-number :date [:vendor [:name :id]] [:company [:name :id]]]]]}
|
||||
:on-success [::received-invoices :unpaid]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::reject-invoices
|
||||
@@ -133,11 +133,13 @@
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received-invoices
|
||||
(fn [db [_ type new-invoices]]
|
||||
(-> db
|
||||
(assoc-in [:invoices type] new-invoices)
|
||||
(assoc-in [:status :loading] false)
|
||||
)))
|
||||
(fn [db [_ type result]]
|
||||
(let [new-invoices (if (:invoice result)
|
||||
(:invoice result)
|
||||
result)]
|
||||
(-> db
|
||||
(assoc-in [:invoices type] new-invoices)
|
||||
(assoc-in [:status :loading] false)))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-form-state
|
||||
|
||||
Reference in New Issue
Block a user