From 749b7b9633144b7de3348d44343cca4095dd13b2 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 9 Dec 2017 13:33:03 -0800 Subject: [PATCH] reject supported. --- src/clj/auto_ap/db/invoices.clj | 3 +++ src/clj/auto_ap/handler.clj | 8 +++++++- src/cljs/auto_ap/events.cljs | 13 +++++++++++++ src/cljs/auto_ap/views.cljs | 3 +++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/clj/auto_ap/db/invoices.clj b/src/clj/auto_ap/db/invoices.clj index aa3fde7a..279180fe 100644 --- a/src/clj/auto_ap/db/invoices.clj +++ b/src/clj/auto_ap/db/invoices.clj @@ -14,6 +14,9 @@ (defn approve [] (map db->clj (j/update! conn :invoices {:imported true} [] ))) +(defn reject [] + (j/delete! conn :invoices ["imported = false"])) + (defn get-unpaid [] (map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true"))) diff --git a/src/clj/auto_ap/handler.clj b/src/clj/auto_ap/handler.clj index 03fa829f..55abf001 100644 --- a/src/clj/auto_ap/handler.clj +++ b/src/clj/auto_ap/handler.clj @@ -41,6 +41,12 @@ {:status 200 :body (pr-str (invoices/get-pending)) :headers {"Content-Type" "application/edn"}}) + (POST "/api/invoices/reject" [] + (invoices/reject) + (println (invoices/get-pending)) + {:status 200 + :body (pr-str (invoices/get-pending)) + :headers {"Content-Type" "application/edn"}}) (POST "/pdf-upload" {{ files "file"} :params :as params} (let [{:keys [filename tempfile]} files] @@ -56,4 +62,4 @@ (route/not-found "Not Found")) (def app - (wrap-edn-params (mp/wrap-multipart-params (wrap-reload app-routes)))) + (wrap-edn-params (mp/wrap-multipart-params (wrap-reload #'app-routes)))) diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index 4d6cb78e..9b0d58e5 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -26,6 +26,11 @@ (fn [db [_ new-invoices]] (assoc-in db [:invoices :pending] new-invoices))) +(re-frame/reg-event-db + ::invoices-rejected + (fn [db [_ new-invoices]] + (assoc-in db [:invoices :pending] new-invoices))) + (re-frame/reg-event-fx ::approve-invoices (fn [cofx [_]] @@ -34,6 +39,14 @@ :on-success ::invoices-approved }})) +(re-frame/reg-event-fx + ::reject-invoices + (fn [cofx [_]] + {:http {:method :post + :uri "/api/invoices/reject" + :on-success ::invoices-rejected + }})) + (re-frame/reg-event-db ::received-invoices (fn [db [_ type new-invoices]] diff --git a/src/cljs/auto_ap/views.cljs b/src/cljs/auto_ap/views.cljs index e9fa78d0..50cdc2a9 100644 --- a/src/cljs/auto_ap/views.cljs +++ b/src/cljs/auto_ap/views.cljs @@ -121,6 +121,9 @@ (re-frame/dispatch [::events/approve-invoices]))} "Approve all"] [:a.card-footer-item + {:on-click (fn [e] + (.preventDefault e) + (re-frame/dispatch [::events/reject-invoices]))} "Reject all"] ]]])) {:component-did-mount (fn []