diff --git a/project.clj b/project.clj index d77aba4b..16fd2eb5 100644 --- a/project.clj +++ b/project.clj @@ -68,7 +68,7 @@ :plugins [[lein-figwheel "0.5.13"] [lein-pdo "0.1.1"] [cider/cider-nrepl "0.16.0"]] - :jvm-opts ["-Dconfig=config/dev.edn" #_#_"--add-modules" "java.xml.bind"]} + :jvm-opts ["-Dconfig=config/dev.edn" "--add-modules" "java.xml.bind"]} :uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]} :provided {:dependencies [[org.clojure/clojurescript "1.10.238"] [reagent "0.7.0"] diff --git a/src/clj/auto_ap/db/invoices.clj b/src/clj/auto_ap/db/invoices.clj index eeff9f30..5adb0ae2 100644 --- a/src/clj/auto_ap/db/invoices.clj +++ b/src/clj/auto_ap/db/invoices.clj @@ -114,11 +114,11 @@ (not (nil? status)) (helpers/merge-where [:= :status status]) (not (nil? company-id)) (helpers/merge-where [:= :company-id company-id]))) -(defn get-graphql [{:keys [start sort-by asc] :as args}] +(defn get-graphql [{:keys [start sort-by asc limit] :as args :or {limit 20}}] (query (cond-> (base-graphql args) (not (nil? sort-by) ) (add-sort-by sort-by asc) - true (assoc :limit 20) + true (assoc :limit limit) start (assoc :offset start)))) (defn count-graphql [args] diff --git a/src/clj/auto_ap/handler.clj b/src/clj/auto_ap/handler.clj index 330deceb..6ed928c5 100644 --- a/src/clj/auto_ap/handler.clj +++ b/src/clj/auto_ap/handler.clj @@ -8,6 +8,7 @@ [auto-ap.routes.vendors :as vendors] [auto-ap.routes.events :as events] [auto-ap.routes.checks :as checks] + [auto-ap.routes.exports :as exports] [auto-ap.db.utils :as u] [buddy.auth.backends.token :refer [jws-backend]] [buddy.auth.middleware :refer [wrap-authentication @@ -31,6 +32,7 @@ (defroutes api-routes (context "/api" [] + exports/routes invoices/routes companies/routes vendors/routes diff --git a/src/clj/auto_ap/routes/exports.clj b/src/clj/auto_ap/routes/exports.clj new file mode 100644 index 00000000..c6939c47 --- /dev/null +++ b/src/clj/auto_ap/routes/exports.clj @@ -0,0 +1,41 @@ +(ns auto-ap.routes.exports + (:require + [auto-ap.db.invoices :as invoices] + [auto-ap.db.checks :as checks] + [auto-ap.db.transactions :as transactions] + [auto-ap.db.utils :refer [query]] + [auto-ap.utils :refer [by]] + [auto-ap.parse :as parse] + [auto-ap.routes.utils :refer [wrap-secure]] + [clj-time.coerce :refer [to-date]] + [auto-ap.db.invoices-expense-accounts :as expense-accounts] + [ring.middleware.json :refer [wrap-json-response]] + [compojure.core :refer [GET POST context defroutes wrap-routes]] + [clojure.string :as str])) + +(defroutes routes + (wrap-routes + (wrap-routes + (context "/" [] + (GET "/invoices/export" {:keys [query-params]} + (let [invoices (invoices/get-graphql {:company (query-params "company")})] + (map (fn [i] + (update i :date to-date)) + invoices))) + (GET "/checks/export" {:keys [query-params]} + (let [checks (checks/get-graphql {:company (query-params "company")})] + (map (fn [i] + (update i :date to-date)) + checks))) + (GET "/transactions/export" {:keys [query-params]} + (let [transactions (transactions/get-graphql {:company (query-params "company")})] + (println transactions) + (map (fn [i] + (-> i + (update :date to-date) + (update :post-date to-date))) + transactions)))) + + + wrap-secure) + wrap-json-response)) diff --git a/src/clj/auto_ap/routes/invoices.clj b/src/clj/auto_ap/routes/invoices.clj index 26b0909b..eebcc05d 100644 --- a/src/clj/auto_ap/routes/invoices.clj +++ b/src/clj/auto_ap/routes/invoices.clj @@ -6,7 +6,9 @@ [auto-ap.utils :refer [by]] [auto-ap.parse :as parse] [auto-ap.routes.utils :refer [wrap-secure]] + [clj-time.coerce :refer [to-date]] [auto-ap.db.invoices-expense-accounts :as expense-accounts] + [ring.middleware.json :refer [wrap-json-response]] [compojure.core :refer [GET POST context defroutes wrap-routes]] [clojure.string :as str])) @@ -150,11 +152,5 @@ :already-imported already-imported-count :vendors-not-found vendors-not-found :errors (map #(dissoc % :date) error-rows)}) - :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)))) + :headers {"Content-Type" "application/edn"}}))) wrap-secure))