a lot of prep for editing customers

This commit is contained in:
Bryce Covert
2018-04-05 09:09:56 -07:00
parent 1ed2b109c9
commit 23e1a7e20f
8 changed files with 110 additions and 40 deletions

View File

@@ -3,8 +3,21 @@
[auto-ap.db.utils :refer [clj->db db->clj get-conn]]
[clojure.edn :as edn]))
(defn merge-data [{:keys [data] :as x}]
(merge x (edn/read-string data)))
(defn parse [x]
(-> x
(db->clj)
merge-data
))
(defn get-all []
(->> (j/query (get-conn) "SELECT * FROM companies")
(map db->clj )
(map (fn [{:keys [data] :as x}]
(merge x (edn/read-string data))))))
(map parse)
))
(defn upsert [id data]
(j/update! (get-conn) :companies data ["id = ?" (Integer/parseInt id)] )
(merge-data (first (j/query (get-conn) ["SELECT * FROM companies WHERE id = ?" (Integer/parseInt id)]))))

View File

@@ -103,6 +103,11 @@
:body (pr-str (invoices/get-pending (query-params "company")))
: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"}})
(POST "/api/invoices" {:keys [edn-params]}
(invoices/insert-multi! (:rows edn-params))
{:status 200