🐛 Fix incorrect teams query on profile deletion

The current approach prevents profile deletion when
there are some extra (soft)deleted teams where the profile
is owner
This commit is contained in:
Andrey Antukh 2024-12-09 09:48:35 +01:00
parent 2f79d71262
commit a923d39603
2 changed files with 26 additions and 4 deletions

View file

@ -422,7 +422,9 @@
:deleted-at deleted-at
:id profile-id}})
(rph/with-transform {} (session/delete-fn cfg)))))
(-> (rph/wrap nil)
(rph/with-transform (session/delete-fn cfg))))))
;; --- HELPERS
@ -431,8 +433,11 @@
"WITH owner_teams AS (
SELECT tpr.team_id AS id
FROM team_profile_rel AS tpr
JOIN team AS t ON (t.id = tpr.team_id)
WHERE tpr.is_owner IS TRUE
AND tpr.profile_id = ?
AND (t.deleted_at IS NULL OR
t.deleted_at > now())
)
SELECT tpr.team_id AS id,
count(tpr.profile_id) - 1 AS participants