allows adding
This commit is contained in:
@@ -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)))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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}}}
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user