a lot of prep for editing customers
This commit is contained in:
@@ -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)]))))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user