From de5ebe81086726e418c517d0442b49e0c1276777 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 19 Jan 2019 09:52:06 -0800 Subject: [PATCH] editing clients has started. --- src/clj/auto_ap/datomic.clj | 4 +++ src/clj/auto_ap/datomic/clients.clj | 2 +- src/clj/auto_ap/graphql.clj | 28 +++++++++++++++---- src/clj/auto_ap/graphql/checks.clj | 2 -- src/cljs/auto_ap/events.cljs | 4 +-- src/cljs/auto_ap/events/admin/clients.cljs | 20 +++++++------ .../auto_ap/views/pages/admin/clients.cljs | 22 ++++++++------- 7 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/clj/auto_ap/datomic.clj b/src/clj/auto_ap/datomic.clj index 6eff8426..f63d8e1d 100644 --- a/src/clj/auto_ap/datomic.clj +++ b/src/clj/auto_ap/datomic.clj @@ -117,6 +117,10 @@ :db/valueType :db.type/string :db/cardinality :db.cardinality/one :db/doc "A client's human-friendly name"} + {:db/ident :client/email + :db/valueType :db.type/string + :db/cardinality :db.cardinality/one + :db/doc "hello@example.com"} {:db/ident :client/code :db/valueType :db.type/string :db/unique :db.unique/identity diff --git a/src/clj/auto_ap/datomic/clients.clj b/src/clj/auto_ap/datomic/clients.clj index 86e5333e..e25fa9d9 100644 --- a/src/clj/auto_ap/datomic/clients.clj +++ b/src/clj/auto_ap/datomic/clients.clj @@ -4,7 +4,7 @@ (defn get-all [] - (->> (d/q '[:find (pull ?e [*]) + (->> (d/q '[:find (pull ?e [* {:client/address [*]}]) :where [?e :client/name]] (d/db (d/connect uri))) (map first) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 56a721ff..4ee85fc8 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -14,6 +14,7 @@ [auto-ap.datomic.invoices :as d-invoices] [auto-ap.datomic.vendors :as d-vendors] [auto-ap.graphql.users :as gq-users] + [auto-ap.graphql.clients :as gq-clients] [auto-ap.graphql.vendors :as gq-vendors] [auto-ap.graphql.checks :as gq-checks] [auto-ap.graphql.expense-accounts :as expense-accounts] @@ -245,6 +246,21 @@ :invoice_payment_amount {:fields {:invoice_id {:type :id} :amount {:type 'Float}}} + :edit_client {:fields {:id {:type :id} + :name {:type 'String} + :email {:type 'String} + :address {:type :add_address} + :locations {:type '(list String)} + :bank_accounts {:type '(list :edit_bank_account)}}} + :edit_bank_account + {:fields {:id {:type :id } + :type {:type :bank_account_type} + :number {:type 'String} + :check_number {:type 'Int} + :name {:type 'String} + :bank_code {:type 'String} + :bank_name {:type 'String} + :yodlee_account_id {:type 'Int}}} :edit_user {:fields {:id {:type :id} :name {:type 'String} @@ -322,6 +338,10 @@ :args {:edit_user {:type :edit_user}} :resolve :mutation/edit-user} + :edit_client {:type :client + :args {:edit_client {:type :edit_client}} + :resolve :mutation/edit-client} + :upsert_vendor {:type :vendor :args {:vendor {:type :add_vendor}} :resolve :mutation/upsert-vendor} @@ -392,10 +412,7 @@ :limit Integer/MAX_VALUE)))) -(defn get-client [context args value] - (->graphql - (filter #(can-see-client? (:id context) %) - (d-clients/get-all)))) + (defn get-user [context args value] (assert-admin (:id context)) @@ -429,13 +446,14 @@ :get-payment-page gq-checks/get-payment-page :get-transaction-page gq-transactions/get-transaction-page - :get-client get-client + :get-client gq-clients/get-client :get-user get-user :mutation/add-handwritten-check gq-checks/add-handwritten-check :mutation/print-checks print-checks :mutation/edit-user gq-users/edit-user :mutation/add-invoice gq-invoices/add-invoice :mutation/edit-invoice gq-invoices/edit-invoice + :mutation/edit-client gq-clients/edit-client :mutation/upsert-vendor gq-vendors/upsert-vendor :mutation/void-invoice gq-invoices/void-invoice :mutation/void-payment gq-checks/void-check diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index 23c96a67..11cff863 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -320,8 +320,6 @@ base-payment (base-payment [invoice] (:invoice/vendor invoice) (:invoice/client invoice) bank-account :payment-type/check 0 {(:invoice_id args) (:amount args)})] - - @(d/transact (d/connect uri) (into [(assoc base-payment :payment/type :payment-type/check diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index ac668709..5a86a0ff 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -37,7 +37,7 @@ :graphql {:token token :query-obj {:venia/queries [[:client - [:id :name :locations [:bank-accounts [:id :number :check-number :name :type] ] + [:id :name :email :locations [:bank-accounts [:id :number :check-number :name :type] ] [: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]]]} @@ -60,7 +60,7 @@ (fn [{:keys [db]} [_ token user]] {:graphql {:token token :query-obj {:venia/queries [[:client - [:id :name [:bank-accounts [:id :number :check-number :name :type]]]] + [:id :name [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :type]]]] [:vendor [:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]} diff --git a/src/cljs/auto_ap/events/admin/clients.cljs b/src/cljs/auto_ap/events/admin/clients.cljs index b08045de..d437ca83 100644 --- a/src/cljs/auto_ap/events/admin/clients.cljs +++ b/src/cljs/auto_ap/events/admin/clients.cljs @@ -10,6 +10,7 @@ (re-frame/reg-event-fx ::edit (fn [{:keys [db]} [_ client-id]] + (println "EDITING") {:dispatch [::events/modal-status :auto-ap.views.pages.admin.clients/edit {:visible? true}] :db (assoc-in db [:admin :client] (get (:clients db) client-id))})) @@ -17,17 +18,20 @@ (re-frame/reg-event-fx ::save (fn [{:keys [db]} _] + (println "saving") (let [edited-client (-> (get-in db [:admin :clients]) (dissoc :location))] - {:db (assoc-in db [:admin :client :saving?] true) - :http {:method :put - :token (:user db) - :body (pr-str edited-client) - :headers {"Content-Type" "application/edn"} - :uri (str "/api/clients/" (:id edited-client)) - :on-success [::save-complete] - :on-error [::save-error]}}))) + :graphql + {:token (-> db :user) + :query-obj {:venia/operation {:operation/type :mutation + :operation/name "EditClient"} + :venia/queries [{:query/data [:upsert-client + {:client edited-client} + [:id :name] + ]}]} + :on-success [::save-complete] + :on-error [::save-error]}}))) (re-frame/reg-event-fx ::save-complete diff --git a/src/cljs/auto_ap/views/pages/admin/clients.cljs b/src/cljs/auto_ap/views/pages/admin/clients.cljs index 14d455ea..586ff915 100644 --- a/src/cljs/auto_ap/views/pages/admin/clients.cljs +++ b/src/cljs/auto_ap/views/pages/admin/clients.cljs @@ -23,17 +23,18 @@ ::save (fn [{:keys [db]} _] (let [edited-client (-> (get-in db [:admin :client]) - (dissoc :location) - (dissoc :new-account))] - + (dissoc :location))] {:db (assoc-in db [:admin :client :saving?] true) - :http {:method :put - :token (:user db) - :body (pr-str edited-client) - :headers {"Content-Type" "application/edn"} - :uri (str "/api/clients/" (:id edited-client)) - :on-success [::save-complete] - :on-error [::save-error]}}))) + :graphql + {:token (-> db :user) + :query-obj {:venia/operation {:operation/type :mutation + :operation/name "EditClient"} + :venia/queries [{:query/data [:edit-client + {:edit-client edited-client} + [:id :name] + ]}]} + :on-success [::save-complete] + :on-error [::save-error]}}))) (re-frame/reg-event-fx ::save-complete @@ -151,6 +152,7 @@ ^{:key location} [:li location ])]]] [:h2.subtitle "Address"] + [address-field {:field [:address] :event ::change :subscription editing-client}]