Created
February 15, 2017 03:36
-
-
Save seantempesta/e748da43b94113fed9abd11679b52d73 to your computer and use it in GitHub Desktop.
Datomic update for user info from form data
This file contains hidden or 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 user-info | |
| "Updates a user entity with form-data supplied by the user. | |
| Steps: | |
| 1. Validate the data. | |
| 2. Ensure that I'm only updating certain keys. (since spec allows extra keys) | |
| 3. Create a merged map to update the entity. (this feels hacky!) | |
| 4. Create an audit map. | |
| 5. Transact and return success." | |
| [conn form-data user] | |
| (if (s/valid? :user/info form-data) | |
| (let [db (d/db conn) | |
| restrict-keys (select-keys form-data [:user/firstName :user/lastName :user/photo :user/email]) | |
| merged (merge (into {} user) restrict-keys {:db/id (:db/id user)}) | |
| audit-map {:db/id (d/tempid :db.part/tx) :audit/user-uuid (:user/uuid user)} | |
| tx-report (d/transact conn [merged audit-map])] | |
| :update/success) | |
| :update/invalid)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment