moved security.
This commit is contained in:
@@ -1,62 +1,65 @@
|
||||
(ns auto-ap.routes.invoices
|
||||
(:require [compojure.core :refer [context GET PUT POST defroutes]]
|
||||
(:require [compojure.core :refer [context GET PUT POST defroutes wrap-routes]]
|
||||
[auto-ap.db.invoices :as invoices]
|
||||
[auto-ap.db.companies :as companies]
|
||||
[auto-ap.parse :as parse]))
|
||||
[auto-ap.parse :as parse]
|
||||
[auto-ap.routes.utils :refer [wrap-secure]]))
|
||||
|
||||
(defroutes 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))
|
||||
(wrap-routes
|
||||
(context "/invoices" []
|
||||
(GET "/" []
|
||||
{:status 200
|
||||
:body (pr-str (invoices/get-all))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(POST "/approve" {:keys [query-params]}
|
||||
(invoices/approve)
|
||||
|
||||
(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 "/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)]
|
||||
(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))
|
||||
(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)]
|
||||
(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"}}))
|
||||
: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)))))
|
||||
;; 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))))
|
||||
wrap-secure))
|
||||
|
||||
Reference in New Issue
Block a user