removing vestiges of http.

This commit is contained in:
Bryce Covert
2018-11-09 13:39:47 -08:00
parent 8ea4ea0c73
commit e15245690d
4 changed files with 33 additions and 66 deletions

View File

@@ -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

View File

@@ -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?)

View File

@@ -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))

View File

@@ -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)))}))