remapped routes
This commit is contained in:
@@ -16,9 +16,7 @@
|
||||
[clj-http.client :as http]
|
||||
[clj-time.core :as time]
|
||||
[config.core :refer [env]]
|
||||
|
||||
[buddy.auth :refer [authenticated?]]
|
||||
|
||||
[buddy.sign.jwt :as jwt]
|
||||
[buddy.auth.backends.token :refer [jws-backend]]
|
||||
[buddy.auth.middleware :refer [wrap-authorization wrap-authentication]]
|
||||
@@ -75,101 +73,111 @@
|
||||
(route/resources "/")
|
||||
(routes (ANY "*" [] (response/resource-response "index.html" {:root "public"}))))
|
||||
|
||||
(defroutes invoice-routes
|
||||
(context "/invoices" []
|
||||
(GET "/" []
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/unpaid" {:keys [query-params] :as r}
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-unpaid (query-params "company")))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/pending" {:keys [query-params]}
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending (query-params "company")))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/" {:keys [edn-params]}
|
||||
(invoices/insert-multi! (:rows edn-params))
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/approve" {:keys [query-params]}
|
||||
(invoices/approve)
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending (query-params "company")))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/reject" {:keys [query-params]}
|
||||
(invoices/reject)
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending (query-params "company")))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/upload"
|
||||
{{ files "file"} :params :as params}
|
||||
(let [{:keys [filename tempfile]} files
|
||||
existing-invoices (invoices/get-all)
|
||||
companies (companies/get-all)]
|
||||
(println companies)
|
||||
(invoices/insert-multi!
|
||||
(for [{:keys [total date invoice-number customer-identifier vendor] :as row}
|
||||
(parse/parse-file (.getPath tempfile) filename)]
|
||||
(assoc row
|
||||
:company-id (:id (parse/best-match companies customer-identifier))
|
||||
|
||||
:imported false
|
||||
:potential-duplicate (boolean (seq (filter #(and (= vendor (:vendor %))
|
||||
(= invoice-number (:invoice-number %)))
|
||||
existing-invoices)))
|
||||
)))
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending ((:query-params params ) "company")))
|
||||
:headers {"Content-Type" "application/edn"}}))
|
||||
|
||||
;; Removing the export view for now...
|
||||
#_(wrap-json-response (GET "/export" {:keys [query-params]}
|
||||
(println query-params)
|
||||
(doto (invoices/get-unpaid (query-params "company"))
|
||||
println)))))
|
||||
|
||||
(defroutes company-routes
|
||||
(context "/companies" []
|
||||
(GET "/" []
|
||||
{:status 200
|
||||
:body (pr-str (companies/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(PUT "/:id" {:keys [edn-params] {:keys [id]} :route-params :as r}
|
||||
{:status 200
|
||||
:body (pr-str (companies/upsert id edn-params))
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
|
||||
(defroutes vendor-routes
|
||||
(context "/vendors" []
|
||||
(GET "/" []
|
||||
{:status 200
|
||||
:body (pr-str (vendors/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(PUT "/:id" {:keys [edn-params] {:keys [id]} :route-params :as r}
|
||||
{:status 200
|
||||
:body (pr-str (vendors/upsert id edn-params))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/" {:keys [edn-params] :as r}
|
||||
{:status 200
|
||||
:body (pr-str (vendors/insert edn-params))
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
|
||||
(defroutes reminder-routes
|
||||
(context "/reminders" []
|
||||
(POST "/send" {:keys [query-params]}
|
||||
(doseq [{:keys [name email invoice-reminder-schedule]} (vendors/get-all)]
|
||||
(when (= "Weekly" invoice-reminder-schedule)
|
||||
(println "Sending email to" email)
|
||||
(ses/send-email :destination {:to-addresses [email]}
|
||||
:source "invoices@mail.integreat.aws.brycecovertoperations.com"
|
||||
:message {:subject "Reminder to send invoices"
|
||||
:body {:html (str "<h1>Hello " name ",</h1><p>This is a reminder to send this week's invoices to us. You can just reply to this email.</p> <p> - Integreat. </p>")
|
||||
:text (str "Hello " name ",\r\nThis is a reminder to send this week's invoices to us. You can just reply to this email.\r\n - Integreat.")}})))
|
||||
{:status 200
|
||||
:body "{}"
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
|
||||
(defroutes api-routes
|
||||
|
||||
(GET "/api/companies" []
|
||||
{:status 200
|
||||
:body (pr-str (companies/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/vendors" []
|
||||
{:status 200
|
||||
:body (pr-str (vendors/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/invoices" []
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/invoices/unpaid" {:keys [query-params] :as r}
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-unpaid (query-params "company")))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(GET "/api/invoices/pending" {:keys [query-params]}
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending (query-params "company")))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(POST "/api/reminders/send" {:keys [query-params]}
|
||||
(doseq [{:keys [name email invoice-reminder-schedule]} (vendors/get-all)]
|
||||
(when (= "Weekly" invoice-reminder-schedule)
|
||||
(println "Sending email to" email)
|
||||
(ses/send-email :destination {:to-addresses [email]}
|
||||
:source "invoices@mail.integreat.aws.brycecovertoperations.com"
|
||||
:message {:subject "Reminder to send invoices"
|
||||
:body {:html (str "<h1>Hello " name ",</h1><p>This is a reminder to send this week's invoices to us. You can just reply to this email.</p> <p> - Integreat. </p>")
|
||||
:text (str "Hello " name ",\r\nThis is a reminder to send this week's invoices to us. You can just reply to this email.\r\n - Integreat.")}})))
|
||||
{:status 200
|
||||
:body "{}"
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(PUT "/api/companies/:id" {:keys [edn-params] {:keys [id]} :route-params :as r}
|
||||
{:status 200
|
||||
:body (pr-str (companies/upsert id edn-params))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(PUT "/api/vendors/:id" {:keys [edn-params] {:keys [id]} :route-params :as r}
|
||||
{:status 200
|
||||
:body (pr-str (vendors/upsert id edn-params))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(POST "/api/vendors" {:keys [edn-params] :as r}
|
||||
{:status 200
|
||||
:body (pr-str (vendors/insert edn-params))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
|
||||
(POST "/api/invoices" {:keys [edn-params]}
|
||||
(invoices/insert-multi! (:rows edn-params))
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/api/invoices/approve" {:keys [query-params]}
|
||||
(invoices/approve)
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending (query-params "company")))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/api/invoices/reject" {:keys [query-params]}
|
||||
(invoices/reject)
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending (query-params "company")))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
;; Removing the export view for now...
|
||||
#_(wrap-json-response (GET "/api/export" {:keys [query-params]}
|
||||
(println query-params)
|
||||
(doto (invoices/get-unpaid (query-params "company"))
|
||||
println)))
|
||||
(POST "/pdf-upload"
|
||||
{{ files "file"} :params :as params}
|
||||
(let [{:keys [filename tempfile]} files
|
||||
existing-invoices (invoices/get-all)
|
||||
companies (companies/get-all)]
|
||||
(println companies)
|
||||
(invoices/insert-multi!
|
||||
(for [{:keys [total date invoice-number customer-identifier vendor] :as row}
|
||||
(parse/parse-file (.getPath tempfile) filename)]
|
||||
(assoc row
|
||||
:company-id (:id (parse/best-match companies customer-identifier))
|
||||
|
||||
:imported false
|
||||
:potential-duplicate (boolean (seq (filter #(and (= vendor (:vendor %))
|
||||
(= invoice-number (:invoice-number %)))
|
||||
existing-invoices)))
|
||||
)))
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-pending ((:query-params params ) "company")))
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
(context "/api" []
|
||||
invoice-routes
|
||||
company-routes
|
||||
vendor-routes
|
||||
reminder-routes))
|
||||
|
||||
(defn wrap-secure [handler]
|
||||
(fn [request]
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
token (re-frame/subscribe [::subs/token])]
|
||||
(with-meta
|
||||
(fn []
|
||||
[:form.dz {:action "/pdf-upload"}
|
||||
[:form.dz {:action "/api/invoices/upload"}
|
||||
[:div.tile.notification
|
||||
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}
|
||||
[:span
|
||||
@@ -24,7 +24,7 @@
|
||||
(re-frame/dispatch [::events/received-invoices :pending (edn/read-string files)]))))
|
||||
:paramName "file"
|
||||
:headers {"Authorization" (str "Token " @token)}
|
||||
:url (str "/pdf-upload"
|
||||
:url (str "/api/invoices/upload"
|
||||
(when-let [company-name (-> @company :id)]
|
||||
(str "?company=" company-name)))
|
||||
:previewsContainer "#dz-hidden"
|
||||
|
||||
Reference in New Issue
Block a user