From e15245690d2b7ee7e51dab1c73f3ea35080c5794 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 9 Nov 2018 13:39:47 -0800 Subject: [PATCH] removing vestiges of http. --- src/clj/auto_ap/handler.clj | 2 -- src/clj/auto_ap/routes/reminders.clj | 16 ++++++++++ src/clj/auto_ap/routes/vendors.clj | 47 ---------------------------- src/cljs/auto_ap/events.cljs | 34 ++++++++++---------- 4 files changed, 33 insertions(+), 66 deletions(-) delete mode 100644 src/clj/auto_ap/routes/vendors.clj diff --git a/src/clj/auto_ap/handler.clj b/src/clj/auto_ap/handler.clj index fa0edbd5..be10d488 100644 --- a/src/clj/auto_ap/handler.clj +++ b/src/clj/auto_ap/handler.clj @@ -5,7 +5,6 @@ [auto-ap.routes.invoices :as invoices] [auto-ap.routes.reminders :as reminders] [auto-ap.routes.graphql :as graphql] - [auto-ap.routes.vendors :as vendors] [auto-ap.routes.yodlee :as yodlee] [auto-ap.routes.events :as events] [auto-ap.routes.checks :as checks] @@ -36,7 +35,6 @@ yodlee/routes invoices/routes companies/routes - vendors/routes reminders/routes checks/routes graphql/routes diff --git a/src/clj/auto_ap/routes/reminders.clj b/src/clj/auto_ap/routes/reminders.clj index 5cf49321..455fce97 100644 --- a/src/clj/auto_ap/routes/reminders.clj +++ b/src/clj/auto_ap/routes/reminders.clj @@ -13,6 +13,22 @@ wrap-routes]]) (:import (org.joda.time DateTime))) +#_(POST "/:id/remind" {:keys [edn-params] {:keys [id :<< as-int]} :route-params :as r} + (assert-admin (:identity r)) + (let [id (if (int? id) + id + (Integer/parseInt id)) + vendor (vendors/get-by-id id)] + (reminders/insert (assoc + (reminders/template) + :email (:primary-email vendor) + :vendor-id id + :scheduled (time/now))) + (-> (reminders/get-ready) + (reminders/send-emails)) + {:status 200 + :body "{}" + :headers {"Content-Type" "application/edn"}})) #_(defn next-sunday [] (let [sunday (->> (p/periodic-seq (time/plus (time/today) (time/days 1)) (time/days 1)) (filter pred/sunday?) diff --git a/src/clj/auto_ap/routes/vendors.clj b/src/clj/auto_ap/routes/vendors.clj deleted file mode 100644 index 63f1b3d8..00000000 --- a/src/clj/auto_ap/routes/vendors.clj +++ /dev/null @@ -1,47 +0,0 @@ -(ns auto-ap.routes.vendors - (:require [auto-ap.db.vendors :as vendors] - [auto-ap.entities.vendors :as entity] - [auto-ap.graphql.utils :refer [assert-admin]] - [auto-ap.routes.utils :refer [wrap-secure wrap-spec]] - [auto-ap.db.reminders :as reminders] - [clj-time.core :as time] - [compojure.core :refer [GET POST PUT context defroutes wrap-routes]])) - -(defroutes routes - (wrap-routes - (context "/vendors" [] - (GET "/" [] - {:status 200 - :body (pr-str (vendors/get-all)) - :headers {"Content-Type" "application/edn"}}) - (wrap-routes - (PUT "/:id" {:keys [edn-params] {:keys [id]} :route-params :as r} - (assert-admin (:identity r)) - {:status 200 - :body (pr-str (vendors/upsert id edn-params)) - :headers {"Content-Type" "application/edn"}}) - #(wrap-spec % ::entity/vendor)) - (POST "/:id/remind" {:keys [edn-params] {:keys [id :<< as-int]} :route-params :as r} - (assert-admin (:identity r)) - (let [id (if (int? id) - id - (Integer/parseInt id)) - vendor (vendors/get-by-id id)] - (reminders/insert (assoc - (reminders/template) - :email (:primary-email vendor) - :vendor-id id - :scheduled (time/now))) - (-> (reminders/get-ready) - (reminders/send-emails)) - {:status 200 - :body "{}" - :headers {"Content-Type" "application/edn"}})) - (wrap-routes - (POST "/" {:keys [edn-params] :as r} - - {:status 200 - :body (pr-str (vendors/insert edn-params)) - :headers {"Content-Type" "application/edn"}}) - #(wrap-spec % ::entity/vendor))) - wrap-secure)) diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index f95d67da..f18c623f 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -43,6 +43,12 @@ [:id :name :default-expense-account [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]]} :on-success [::received-initial]}})))) +(def vendor-query + [:id :name :default-expense-account + [:primary-contact [:name :phone :email :id]] + [:secondary-contact [:id :name :phone :email]] + :print-as :invoice-reminder-schedule :code + [:address [:street1 :street2 :city :state :zip]]]) (re-frame/reg-event-db ::toggle-menu @@ -182,26 +188,20 @@ ::save-vendor (fn [{:keys [db]} _] (let [edited-vendor (get-in db [:user-editing-vendor])] - (if (:id edited-vendor) - {:http {:method :put - :token (:user db) - :body (pr-str edited-vendor) - :headers {"Content-Type" "application/edn"} - :uri (str "/api/vendors/" (:id edited-vendor)) - :on-success [::save-complete] - :on-error [::save-error]}} - - {:http {:method :post - :token (:user db) - :body (pr-str edited-vendor) - :headers {"Content-Type" "application/edn"} - :uri (str "/api/vendors") - :on-success [::save-complete] - :on-error [::save-error]}})))) + (assoc {} :graphql + {:token (-> db :user) + :query-obj {:venia/operation {:operation/type :mutation + :operation/name "UpsertVendor"} + + :venia/queries [{:query/data [:upsert-vendor + {:vendor edited-vendor} + vendor-query]}]} + :on-success [::save-complete] + :on-error [::save-error]})))) (re-frame/reg-event-fx ::save-complete (fn [{:keys [db]} [_ vendor]] {:dispatch [::modal-completed :auto-ap.views.main/user-editing-vendor ] :db (-> db (dissoc :user-editing-vendor) - (assoc-in [:vendors (:id vendor)] vendor))})) + (assoc-in [:vendors (:id vendor)] (:upsert-vendor vendor)))}))