Created
January 25, 2023 12:09
-
-
Save dotemacs/a24c84c139123d52a005990e12e78c20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn update-user | |
([^js db user] | |
(update-user db user nil)) | |
([^js db user prev-username] | |
(let [batch (.batch db)] | |
(update-user db batch user prev-username) | |
(.commit batch))) | |
([^js db batch-or-transaction user prev-username] | |
(let [user-id (:id user) | |
username (:username user)] | |
(.update batch-or-transaction | |
(user-profile-doc-ref db user-id) | |
(clj->js (dissoc user :id))) | |
(when (and prev-username | |
(not= (user-profile/normalize-username prev-username) | |
(user-profile/normalize-username username))) | |
(.delete batch-or-transaction | |
(username-doc-ref db (user-profile/normalize-username prev-username)))) | |
(when (not= (user-profile/normalize-username prev-username) | |
(user-profile/normalize-username username)) | |
(.set batch | |
(username-doc-ref db (user-profile/normalize-username username)) | |
(clj->js {:uid user-id})))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment