reject supported.

This commit is contained in:
Bryce Covert
2017-12-09 13:33:03 -08:00
parent bc6db905a5
commit 749b7b9633
4 changed files with 26 additions and 1 deletions

View File

@@ -14,6 +14,9 @@
(defn approve [] (defn approve []
(map db->clj (j/update! conn :invoices {:imported true} [] ))) (map db->clj (j/update! conn :invoices {:imported true} [] )))
(defn reject []
(j/delete! conn :invoices ["imported = false"]))
(defn get-unpaid [] (defn get-unpaid []
(map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true"))) (map db->clj (j/query conn "SELECT * FROM invoices WHERE imported=true")))

View File

@@ -41,6 +41,12 @@
{:status 200 {:status 200
:body (pr-str (invoices/get-pending)) :body (pr-str (invoices/get-pending))
:headers {"Content-Type" "application/edn"}}) :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" (POST "/pdf-upload"
{{ files "file"} :params :as params} {{ files "file"} :params :as params}
(let [{:keys [filename tempfile]} files] (let [{:keys [filename tempfile]} files]
@@ -56,4 +62,4 @@
(route/not-found "Not Found")) (route/not-found "Not Found"))
(def app (def app
(wrap-edn-params (mp/wrap-multipart-params (wrap-reload app-routes)))) (wrap-edn-params (mp/wrap-multipart-params (wrap-reload #'app-routes))))

View File

@@ -26,6 +26,11 @@
(fn [db [_ new-invoices]] (fn [db [_ new-invoices]]
(assoc-in db [:invoices :pending] 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 (re-frame/reg-event-fx
::approve-invoices ::approve-invoices
(fn [cofx [_]] (fn [cofx [_]]
@@ -34,6 +39,14 @@
:on-success ::invoices-approved :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 (re-frame/reg-event-db
::received-invoices ::received-invoices
(fn [db [_ type new-invoices]] (fn [db [_ type new-invoices]]

View File

@@ -121,6 +121,9 @@
(re-frame/dispatch [::events/approve-invoices]))} (re-frame/dispatch [::events/approve-invoices]))}
"Approve all"] "Approve all"]
[:a.card-footer-item [:a.card-footer-item
{:on-click (fn [e]
(.preventDefault e)
(re-frame/dispatch [::events/reject-invoices]))}
"Reject all"] "Reject all"]
]]])) ]]]))
{:component-did-mount (fn [] {:component-did-mount (fn []