Skip to content
Snippets Groups Projects
Commit 3770ac9c authored by Allen Gilliland's avatar Allen Gilliland
Browse files

cleanup a few bits and pieces based on feedback on the PR.

parent 3b8da0cc
Branches
Tags
No related merge requests found
......@@ -45,7 +45,7 @@
(check-404 (db/exists? Pulse :id id))
(pulse/update-pulse {:id id
:name name
:cards (filter identity (into [] (map :id cards)))
:cards (filter identity (map :id cards))
:channels channels})
(pulse/retrieve-pulse id))
......
......@@ -33,14 +33,13 @@
(post-select [_ {:keys [id creator_id] :as pulse}]
(map->PulseInstance
(u/assoc* pulse
:cards (delay (k/select Card
(k/join PulseCard (= :pulse_card.card_id :id))
(k/fields :id :name :description :display)
(k/where {:pulse_card.pulse_id id})
(k/order :pulse_card.position :asc)))
:channels (delay (db/sel :many PulseChannel (k/where {:pulse_id id})))
:creator (delay (when creator_id (db/sel :one User :id creator_id))))))
(assoc pulse :cards (delay (k/select Card
(k/join PulseCard (= :pulse_card.card_id :id))
(k/fields :id :name :description :display)
(k/where {:pulse_card.pulse_id id})
(k/order :pulse_card.position :asc)))
:channels (delay (db/sel :many PulseChannel (k/where {:pulse_id id})))
:creator (delay (when creator_id (db/sel :one User :id creator_id))))))
(pre-cascade-delete [_ {:keys [id]}]
(db/cascade-delete PulseCard :pulse_id id)
......@@ -64,7 +63,7 @@
(coll? card-ids)
(every? integer? card-ids)]}
;; first off, just delete any cards associated with this pulse (we add them again below)
(k/delete PulseCard (k/where {:pulse_id id}))
(db/cascade-delete PulseCard :pulse_id id)
;; now just insert all of the cards that were given to us
(let [cards (map-indexed (fn [idx itm] {:pulse_id id :card_id itm :position idx}) card-ids)]
(k/insert PulseCard (k/values cards))))
......@@ -97,8 +96,8 @@
{:pre [(integer? id)
(coll? channels)
(every? map? channels)]}
(let [new-channels (group-by #(keyword (:channel_type %)) channels)
old-channels (group-by #(keyword (:channel_type %)) (db/sel :many PulseChannel :pulse_id id))
(let [new-channels (group-by (comp keyword :channel_type) channels)
old-channels (group-by (comp keyword :channel_type) (db/sel :many PulseChannel :pulse_id id))
handle-channel #(create-update-delete-channel id (first (get new-channels %)) (first (get old-channels %)))]
(assert (= 0 (count (get new-channels nil))) "Cannot have channels without a :channel_type attribute")
(dorun (map handle-channel (vec (keys pulse-channel/channel-types))))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment