allows adding

This commit is contained in:
Bryce Covert
2018-08-05 19:51:18 -07:00
parent a9d8bf21f9
commit 2e8a7b4648
8 changed files with 183 additions and 25 deletions

View File

@@ -45,4 +45,13 @@
(Integer/parseInt id))))
(defn add-bank-account [id bank-account]
(let [company (get-by-id id)
company (update company :bank-accounts
(fn [ba]
(let [next-id (inc (apply max (conj (map :id ba) 0)))]
(conj (vec ba) (assoc bank-account :id next-id)))))]
(upsert id company)))

View File

@@ -36,6 +36,7 @@
{:fields {:id {:type 'Int}
:name {:type 'String}
:email {:type 'String}
:address {:type :address}
:locations {:type '(list String)}
:bank_accounts {:type '(list :bank_account)}}}
@@ -49,6 +50,7 @@
:bank_name {:type 'String}}}
:address
{:fields {:street1 {:type 'String}
:street2 {:type 'String}
:city {:type 'String}
:state {:type 'String}
:zip {:type 'String}}}

View File

@@ -15,10 +15,19 @@
:body (pr-str (filter #(can-see-company? (:identity r) (:id %)) (companies/get-all)))
:headers {"Content-Type" "application/edn"}})
(wrap-spec
(PUT "/:id" {:keys [edn-params] {:keys [id]} :route-params :as r}
(PUT "/:id" {{:keys [address email locations new-bank-accounts]} :edn-params :keys [edn-params] {:keys [id ]} :route-params :as r}
(assert-can-see-company (:identity r) id)
{:status 200
:body (pr-str (companies/upsert id edn-params))
:headers {"Content-Type" "application/edn"}})
(let [id (Integer/parseInt id)
company (companies/get-by-id id)
updated-company (merge company {:address address
:email email
:locations locations})]
(companies/upsert id updated-company)
(doseq [bank-account new-bank-accounts]
(companies/add-bank-account id bank-account))
{:status 200
:body (pr-str (companies/get-by-id id))
:headers {"Content-Type" "application/edn"}}))
::entity/company))
wrap-secure))