Repository: penpot/penpot
File: frontend/src/app/main/data/profile.cljs (ClojureScript)

Code before:

(defn fetch-file-comments-users
  [{:keys [team-id]}]
  (assert (uuid? team-id) "expected a valid uuid for `team-id`")
  (letfn [(fetched [users state]
            (->> users
                 (d/index-by :id)
                 (assoc state :file-comments-users)))]
    (ptk/reify ::fetch-file-comments-users
      ptk/WatchEvent
      (watch [_ state _]
        (let [share-id (-> state :viewer-local :share-id)]
          (->> (rp/cmd! :get-profiles-for-file-comments {:team-id team-id :share-id share-id})
               (rx/map #(partial fetched %))))))))

;; --- EVENT: request-account-deletion

(def profile-deleted-event?
  (ptk/type? ::profile-deleted))

(defn- delete-subscription
  []
  (if (contains? cf/flags :subscriptions)
    (->> (http/fetch {:uri "/payments/subscriptions/delete"
                      :credentials "include"
                      :method :post})
         (rx/map (constantly nil))
         (rx/catch #(rx/empty)))
    (rx/empty)))

(defn request-account-deletion
  [params]
  (ptk/reify ::request-account-deletion
    ptk/WatchEvent
    (watch [_ _ _]
      (let [{:keys [on-error on-success]
             :or {on-error rx/throw
                  on-success identity}}
            (meta params)]

        (rx/concat
         (delete-subscription)
         (->> (rp/cmd! :delete-profile {})
              (rx/tap on-success)
              (rx/map (fn [_]
                        (ptk/data-event ::profile-deleted params)))
              (rx/catch on-error)
              (rx/delay-at-least 300)))))))

;; --- EVENT: request-profile-recovery


Review comment (suggestion):
```suggestion
                      :method :get})
```

All calls to payments are get. For consistency, I propose this change, if you agree.

Code after:

(defn fetch-file-comments-users
  [{:keys [team-id]}]
  (assert (uuid? team-id) "expected a valid uuid for `team-id`")
  (letfn [(fetched [users state]
            (->> users
                 (d/index-by :id)
                 (assoc state :file-comments-users)))]
    (ptk/reify ::fetch-file-comments-users
      ptk/WatchEvent
      (watch [_ state _]
        (let [share-id (-> state :viewer-local :share-id)]
          (->> (rp/cmd! :get-profiles-for-file-comments {:team-id team-id :share-id share-id})
               (rx/map #(partial fetched %))))))))

;; --- EVENT: request-account-deletion

(def profile-deleted-event?
  (ptk/type? ::profile-deleted))

(defn- delete-subscription
  []
  (if (contains? cf/flags :subscriptions)
    (->> (http/fetch {:uri "/payments/subscriptions/delete"
                      :credentials "include"
                      :method :get})
         (rx/map (constantly nil))
         (rx/catch #(rx/empty)))
    (rx/empty)))

(defn request-account-deletion
  [params]
  (ptk/reify ::request-account-deletion
    ptk/WatchEvent
    (watch [_ _ _]
      (let [{:keys [on-error on-success]
             :or {on-error rx/throw
                  on-success identity}}
            (meta params)]

        (rx/concat
         (delete-subscription)
         (->> (rp/cmd! :delete-profile {})
              (rx/tap on-success)
              (rx/map (fn [_]
                        (ptk/data-event ::profile-deleted params)))
              (rx/catch on-error)
              (rx/delay-at-least 300)))))))

;; --- EVENT: request-profile-recovery