ability to approve

This commit is contained in:
Bryce Covert
2017-12-09 08:26:52 -08:00
parent 36cac4a023
commit bc6db905a5
6 changed files with 59 additions and 4 deletions

View File

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

View File

@@ -35,6 +35,12 @@
{:status 200
:body (pr-str (invoices/get-all))
:headers {"Content-Type" "application/edn"}})
(POST "/api/invoices/approve" []
(invoices/approve)
(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]

View File

@@ -5,11 +5,11 @@
[auto-ap.views :as views]
[auto-ap.config :as config]
[auto-ap.routes :as routes]
[auto-ap.effects :as effects]
[pushy.core :as pushy]
[bidi.bidi :as bidi]))
(defn- parse-url [url]
(.log js/console "test" (bidi/match-route routes/routes url))
(bidi/match-route routes/routes url))
(defn- dispatch-route [matched-route]

View File

@@ -0,0 +1,24 @@
(ns auto-ap.effects
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [re-frame.core :as re-frame]
[reagent.core :as reagent]
[auto-ap.subs :as subs]
[auto-ap.events :as events]
[cljs.reader :as edn]
[cljsjs.dropzone :as dz]
[auto-ap.routes :as routes]
[bidi.bidi :as bidi]
[cljs-http.client :as http]
[cljs.core.async :refer [<!]]))
(re-frame/reg-fx
:http
(fn [{:keys [method uri on-success]}]
(go
(->> (http/request {:method method
:url uri})
(<! )
:body
(conj [on-success])
(re-frame/dispatch)))))

View File

@@ -2,6 +2,7 @@
(:require [re-frame.core :as re-frame]
[auto-ap.db :as db]
[auto-ap.routes :as routes]
[bidi.bidi :as bidi]))
(re-frame/reg-event-db
@@ -20,6 +21,19 @@
(fn [db [_ new-invoices]]
(assoc-in db [:invoices] new-invoices)))
(re-frame/reg-event-db
::invoices-approved
(fn [db [_ new-invoices]]
(assoc-in db [:invoices :pending] new-invoices)))
(re-frame/reg-event-fx
::approve-invoices
(fn [cofx [_]]
{:http {:method :post
:uri "/api/invoices/approve"
:on-success ::invoices-approved
}}))
(re-frame/reg-event-db
::received-invoices
(fn [db [_ type new-invoices]]

View File

@@ -85,8 +85,7 @@
[:h1.title "All invoices"]])
{:component-did-mount (fn []
(go
(re-frame/dispatch [::events/received-invoices (:body (<! (http/get "/api/invoices")))]))
)})])
(re-frame/dispatch [::events/received-invoices (:body (<! (http/get "/api/invoices")))])))})])
(defmethod active-page :import-invoices []
[(with-meta
@@ -114,7 +113,16 @@
[:td customer-identifier]
[:td invoice-number]
[:td date]
[:td total]])]]]]]))
[:td total]])]]]
[:div.card-footer
[:a.card-footer-item
{:on-click (fn [e]
(.preventDefault e)
(re-frame/dispatch [::events/approve-invoices]))}
"Approve all"]
[:a.card-footer-item
"Reject all"]
]]]))
{:component-did-mount (fn []
(go
(->> (<! (http/get "/api/invoices/pending"))