Created
January 25, 2023 12:08
-
-
Save dotemacs/37eefe27b126a874aafc314c053aa0e4 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 user prev-username batch) | |
(.commit batch))) | |
([^js db user prev-username batch] | |
(let [user-id (:id user) | |
username (:username user)] | |
(.update batch | |
(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 | |
(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