Skip to content

Instantly share code, notes, and snippets.

@seantempesta
Created February 15, 2017 03:36
Show Gist options
  • Select an option

  • Save seantempesta/e748da43b94113fed9abd11679b52d73 to your computer and use it in GitHub Desktop.

Select an option

Save seantempesta/e748da43b94113fed9abd11679b52d73 to your computer and use it in GitHub Desktop.
Datomic update for user info from form data
(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