Transactions are converted!

This commit is contained in:
Bryce Covert
2020-08-21 08:21:47 -07:00
parent 57895d9ee2
commit e8301b071d
5 changed files with 145 additions and 90 deletions

View File

@@ -80,8 +80,14 @@
(re-frame/reg-fx
:http
(fn [{:keys [method uri on-success on-error body headers token]}]
(fn [{:keys [method uri on-success on-error body headers owns-state token]}]
(go
(when (:multi owns-state)
(re-frame/dispatch-sync [::status/loading-multi (:multi owns-state) (:which owns-state)]))
(when (:single owns-state)
(re-frame/dispatch-sync [::status/loading (:single owns-state)]))
(let [headers (if token
(assoc headers "Authorization" (str "Token " token))
headers)
@@ -90,23 +96,37 @@
:headers headers
:url uri}))]
(if (>= (:status response) 400)
(when on-error
(do
(when (:multi owns-state)
(re-frame/dispatch [::status/error-multi (:multi owns-state) (:which owns-state) [(:body response)]]))
(when (:single owns-state)
(re-frame/dispatch [::status/error (:single owns-state) [(:body response)]]))
(when on-error
(->> response
:body
(dates->date-times)
(conj on-error)
(re-frame/dispatch))))
(do
(when (:multi owns-state)
(re-frame/dispatch [::status/completed-multi (:multi owns-state) (:which owns-state)]))
(when (:single owns-state)
(re-frame/dispatch [::status/completed (:single owns-state)]))
(->> response
:body
(dates->date-times)
(conj on-error)
(re-frame/dispatch)))
(->> response
:body
(dates->date-times)
(conj on-success)
(re-frame/dispatch)))))))
:body
(dates->date-times)
(conj on-success)
(re-frame/dispatch))))))))
(re-frame/reg-fx
:https
(fn [{:keys [requests on-success on-failure]}]
(fn [{:keys [requests on-success on-failure owns-state]}]
(go
(when (:multi owns-state)
(re-frame/dispatch-sync [::status/loading-multi (:multi owns-state) (:which owns-state)]))
(when (:single owns-state)
(re-frame/dispatch-sync [::status/loading (:single owns-state)]))
(let [results (->>
(for [{:keys [method body headers uri token]} requests]
(go
@@ -123,9 +143,21 @@
(async/merge)
(async/reduce conj [])
(async/<!))]
(println "DONE")
(if (some #{:error} results)
(re-frame/dispatch on-failure)
(re-frame/dispatch on-success))))))
(do
(when (:multi owns-state)
(re-frame/dispatch [::status/error-multi (:multi owns-state) (:which owns-state) results]))
(when (:single owns-state)
(re-frame/dispatch [::status/error (:single owns-state) results]))
(re-frame/dispatch on-failure))
(do
(when (:multi owns-state)
(re-frame/dispatch [::status/completed-multi (:multi owns-state) (:which owns-state)]))
(when (:single owns-state)
(re-frame/dispatch [::status/completed (:single owns-state)]))
(re-frame/dispatch on-success)))))))
(defn kebab->snake [s]
(str/replace s #"-" "_"))