♻️ Move teams queries and mutations to commands

This commit is contained in:
Andrey Antukh 2022-12-13 09:52:30 +01:00
parent 797ae22526
commit c570557203
23 changed files with 993 additions and 653 deletions

View file

@ -110,7 +110,7 @@
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/query! :team-members {:team-id team-id})
(->> (rp/cmd! :get-team-members {:team-id team-id})
(rx/map team-members-fetched))))))
;; --- EVENT: fetch-team-stats
@ -128,7 +128,7 @@
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/query! :team-stats {:team-id team-id})
(->> (rp/cmd! :get-team-stats {:team-id team-id})
(rx/map team-stats-fetched))))))
;; --- EVENT: fetch-team-invitations
@ -146,7 +146,7 @@
ptk/WatchEvent
(watch [_ state _]
(let [team-id (:current-team-id state)]
(->> (rp/query! :team-invitations {:team-id team-id})
(->> (rp/cmd! :get-team-invitations {:team-id team-id})
(rx/map team-invitations-fetched))))))
;; --- EVENT: fetch-team-webhooks
@ -384,14 +384,13 @@
(let [{:keys [on-success on-error]
:or {on-success identity
on-error rx/throw}} (meta params)]
(->> (rp/mutation! :create-team {:name name})
(->> (rp/cmd! :create-team {:name name})
(rx/tap on-success)
(rx/map team-created)
(rx/catch on-error))))))
;; --- EVENT: create-team-with-invitations
(defn create-team-with-invitations
[{:keys [name emails role] :as params}]
(us/assert! ::us/string name)
@ -404,7 +403,7 @@
params {:name name
:emails #{emails}
:role role}]
(->> (rp/mutation! :create-team-and-invite-members params)
(->> (rp/cmd! :create-team-and-invitations params)
(rx/tap on-success)
(rx/map team-created)
(rx/catch on-error))))))
@ -421,7 +420,7 @@
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/mutation! :update-team params)
(->> (rp/cmd! :update-team params)
(rx/ignore)))))
(defn update-team-photo
@ -440,7 +439,7 @@
(->> (rx/of file)
(rx/map di/validate-file)
(rx/map prepare)
(rx/mapcat #(rp/mutation :update-team-photo %))
(rx/mapcat #(rp/cmd! :update-team-photo %))
(rx/do on-success)
(rx/map du/fetch-teams)
(rx/catch on-error))))))
@ -454,7 +453,7 @@
(watch [_ state _]
(let [team-id (:current-team-id state)
params (assoc params :team-id team-id)]
(->> (rp/mutation! :update-team-member-role params)
(->> (rp/cmd! :update-team-member-role params)
(rx/mapcat (fn [_]
(rx/of (fetch-team-members)
(du/fetch-teams)))))))))
@ -467,7 +466,7 @@
(watch [_ state _]
(let [team-id (:current-team-id state)
params (assoc params :team-id team-id)]
(->> (rp/mutation! :delete-team-member params)
(->> (rp/cmd! :delete-team-member params)
(rx/mapcat (fn [_]
(rx/of (fetch-team-members)
(du/fetch-teams)))))))))
@ -487,7 +486,7 @@
params (cond-> {:id team-id}
(uuid? reassign-to)
(assoc :reassign-to reassign-to))]
(->> (rp/mutation! :leave-team params)
(->> (rp/cmd! :leave-team params)
(rx/tap #(tm/schedule on-success))
(rx/catch on-error))))))
@ -506,7 +505,7 @@
:or {on-success identity
on-error rx/throw}} (meta params)
params (dissoc params :resend?)]
(->> (rp/mutation! :invite-team-member params)
(->> (rp/cmd! :create-team-invitations params)
(rx/tap on-success)
(rx/catch on-error))))))
@ -524,7 +523,7 @@
(let [{:keys [on-success on-error]
:or {on-success identity
on-error rx/throw}} (meta params)]
(->> (rp/mutation! :update-team-invitation-role params)
(->> (rp/cmd! :update-team-invitation-role params)
(rx/tap on-success)
(rx/catch on-error))))))
@ -538,7 +537,7 @@
(let [{:keys [on-success on-error]
:or {on-success identity
on-error rx/throw}} (meta params)]
(->> (rp/mutation! :delete-team-invitation params)
(->> (rp/cmd! :delete-team-invitation params)
(rx/tap on-success)
(rx/catch on-error))))))
@ -608,7 +607,7 @@
(let [{:keys [on-success on-error]
:or {on-success identity
on-error rx/throw}} (meta params)]
(->> (rp/mutation! :delete-team {:id id})
(->> (rp/cmd! :delete-team {:id id})
(rx/tap on-success)
(rx/catch on-error))))))

View file

@ -87,7 +87,7 @@
(ptk/reify ::fetch-teams
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/query! :teams)
(->> (rp/cmd! :get-teams)
(rx/map teams-fetched)))))
;; --- EVENT: fetch-profile
@ -446,7 +446,7 @@
(ptk/reify ::fetch-team-users
ptk/WatchEvent
(watch [_ _ _]
(->> (rp/query! :team-users {:team-id team-id})
(->> (rp/cmd! :get-team-users {:team-id team-id})
(rx/map #(partial fetched %)))))))
(defn fetch-file-comments-users

View file

@ -265,7 +265,7 @@
(->> (rx/zip (rp/cmd! :get-file {:id file-id :features features})
(rp/cmd! :get-file-object-thumbnails {:file-id file-id})
(rp/query! :project {:id project-id})
(rp/query! :team-users {:file-id file-id})
(rp/cmd! :get-team-users {:file-id file-id})
(rp/cmd! :get-profiles-for-file-comments {:file-id file-id :share-id share-id}))
(rx/take 1)
(rx/map (partial bundle-fetched features))

View file

@ -17,6 +17,11 @@
(derive :get-file-libraries ::query)
(derive :get-file-fragment ::query)
(derive :search-files ::query)
(derive :get-teams ::query)
(derive :get-team-users ::query)
(derive :get-team-members ::query)
(derive :get-team-stats ::query)
(derive :get-team-invitations ::query)
(defn handle-response
[{:keys [status body] :as response}]