Merge branch 'master' into fix-dates
This commit is contained in:
@@ -3,33 +3,37 @@
|
||||
[auto-ap.graphql :as ql]
|
||||
[buddy.auth :refer [throw-unauthorized]]
|
||||
[clojure.edn :as edn]
|
||||
[compojure.core :refer [GET PUT context defroutes
|
||||
[compojure.core :refer [GET POST PUT context defroutes
|
||||
wrap-routes]]))
|
||||
(defn handle-graphql [{:keys [request-method query-params body edn-params method] :as r}]
|
||||
(when (= "none" (:user/role (:identity r)))
|
||||
(throw-unauthorized))
|
||||
|
||||
(try
|
||||
(let [variables (some-> (query-params "variables")
|
||||
edn/read-string)
|
||||
body (some-> r :body slurp)]
|
||||
(println "BODY" body)
|
||||
{:status 200
|
||||
:body (pr-str (ql/query (:identity r) (doto (if (= request-method :get) (query-params "query") body) println) variables ))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(catch Exception e
|
||||
(if-let [result (:result (ex-data e))]
|
||||
{:status 400
|
||||
:body (pr-str result)
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
(if-let [message (:validation-error (ex-data e) )]
|
||||
{:status 400
|
||||
:body (pr-str {:errors [(merge {:message message} (ex-data e))]})
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
{:status 500
|
||||
:body (pr-str {:errors [(merge {:message (.getMessage e)} (ex-data e))]})
|
||||
:headers {"Content-Type" "application/edn"}})))))
|
||||
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
(context "/graphql" []
|
||||
(GET "/" {:keys [query-params] :as r}
|
||||
(when (= "none" (:user/role (:identity r)))
|
||||
(throw-unauthorized))
|
||||
|
||||
(try
|
||||
(let [variables (some-> (query-params "variables")
|
||||
edn/read-string)]
|
||||
{:status 200
|
||||
:body (pr-str (ql/query (:identity r) (query-params "query") variables ))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(catch Exception e
|
||||
(if-let [result (:result (ex-data e))]
|
||||
{:status 400
|
||||
:body (pr-str result)
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
(if-let [message (:validation-error (ex-data e) )]
|
||||
{:status 400
|
||||
:body (pr-str {:errors [(merge {:message message} (ex-data e))]})
|
||||
:headers {"Content-Type" "application/edn"}}
|
||||
{:status 500
|
||||
:body (pr-str {:errors [(merge {:message (.getMessage e)} (ex-data e))]})
|
||||
:headers {"Content-Type" "application/edn"}}))))))
|
||||
(GET "/" x (handle-graphql x))
|
||||
(POST "/" x (handle-graphql x)))
|
||||
wrap-secure))
|
||||
|
||||
@@ -140,10 +140,20 @@
|
||||
(let [headers (if token
|
||||
{"Authorization" (str "Token " token)}
|
||||
{})
|
||||
|
||||
method (if (= (get-in query-obj [:venia/operation :operation/type]) :mutation)
|
||||
:post
|
||||
:get)
|
||||
headers (if (= method :post)
|
||||
(assoc headers "Content-Type" "text/plain")
|
||||
headers
|
||||
)
|
||||
query (or query (v/graphql-query (->graphql query-obj)))
|
||||
response (<! (http/request {:method :get
|
||||
response (<! (http/request {:method method
|
||||
:headers headers
|
||||
:url (str "/api/graphql?query=" (js/encodeURIComponent query)
|
||||
|
||||
:body (when = (:post method) query)
|
||||
:url (str "/api/graphql?query=" (when (= :get method) (js/encodeURIComponent query))
|
||||
"&variables=" (pr-str (or variables {})))}))]
|
||||
(if (>= (:status response) 400)
|
||||
(when on-error
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
:graphql {:token token
|
||||
:query-obj {:venia/queries [[:client
|
||||
|
||||
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible] ]
|
||||
[:id :name :code :email :locations [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]
|
||||
[:address [:street1 :street2 :city :state :zip]]]]
|
||||
[:vendor
|
||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
||||
@@ -65,7 +65,7 @@
|
||||
(fn [{:keys [db]} [_ token user]]
|
||||
{:graphql {:token token
|
||||
:query-obj {:venia/queries [[:client
|
||||
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible] ]]]
|
||||
[:id :name :code [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id] ]]]
|
||||
[:vendor
|
||||
[:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
::new
|
||||
(fn [db [_ client-id]]
|
||||
(-> db
|
||||
(forms/start-form ::new-client {}))))
|
||||
(forms/start-form ::new-client {:bank-accounts []}))))
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
:city (:city (:address new-client-data))
|
||||
:state (:state (:address new-client-data))
|
||||
:zip (:zip (:address new-client-data))}
|
||||
:bank-accounts (map (fn [{:keys [number name check-number type id code bank-name routing bank-code new? sort-order visible]}]
|
||||
:bank-accounts (map (fn [{:keys [number name check-number type id code bank-name routing bank-code new? sort-order visible yodlee-account-id]}]
|
||||
{:number number
|
||||
:name name
|
||||
:check-number check-number
|
||||
@@ -55,6 +55,8 @@
|
||||
:id id
|
||||
:sort-order sort-order
|
||||
:visible visible
|
||||
:yodlee-account-id (when yodlee-account-id
|
||||
(js/parseInt yodlee-account-id))
|
||||
:code (if new?
|
||||
(str (:code new-client-data) "-" code)
|
||||
code)
|
||||
@@ -83,7 +85,7 @@
|
||||
:operation/name "EditClient"}
|
||||
:venia/queries [{:query/data [:edit-client
|
||||
{:edit-client new-client-req}
|
||||
[:id :name :code :email :locations [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :sort-order]]]]}]}
|
||||
[:id :name :code :email :locations [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order]]]]}]}
|
||||
:on-success [::save-complete]
|
||||
:on-error [::forms/save-error ::new-client]}}
|
||||
{:db new-client-form}))))
|
||||
@@ -303,7 +305,7 @@
|
||||
[bind-field
|
||||
[:input.input {:placeholder "Yodlee Account #"
|
||||
:type "text"
|
||||
:field [:bank-accounts :yodlee-account-id]
|
||||
:field [:bank-accounts sort-order :yodlee-account-id]
|
||||
:event change-event
|
||||
:subscription new-client}]]]]])])
|
||||
|
||||
|
||||
@@ -958,9 +958,7 @@
|
||||
(re-frame/dispatch [::toggle-check which invoice]))
|
||||
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]
|
||||
|
||||
[print-checks-modal]
|
||||
[handwrite-checks-modal]
|
||||
[change-expense-accounts-modal {:updated-event [::expense-accounts-updated]}]
|
||||
|
||||
|
||||
|
||||
]))
|
||||
@@ -982,5 +980,8 @@
|
||||
:bottom [:div [vendor-dialog {:vendor @(re-frame/subscribe [::subs/user-editing-vendor])
|
||||
:save-event [::events/save-vendor]
|
||||
:change-event [::events/change-nested-form-state [:user-editing-vendor]] :id :auto-ap.views.main/user-editing-vendor}]
|
||||
[check-results-dialog]]
|
||||
[check-results-dialog]
|
||||
[print-checks-modal]
|
||||
[handwrite-checks-modal]
|
||||
[change-expense-accounts-modal {:updated-event [::expense-accounts-updated]}]]
|
||||
:right-side-bar [appearing-side-bar {:visible? invoice-bar-active?} [edit-invoice-form]]}]))
|
||||
|
||||
Reference in New Issue
Block a user