Skip to content
Snippets Groups Projects
Commit 6dc4920e authored by Cam Saül's avatar Cam Saül
Browse files

new implementation of exists? :honey_pot:

parent 587890ef
Branches
Tags
No related merge requests found
......@@ -62,8 +62,8 @@
first_name NonEmptyString
last_name NonEmptyString}
(check-self-or-superuser id)
(check-404 (exists? User :id id :is_active true)) ; only allow updates if the specified account is active
(check-400 (not (exists? User :email email :id [not= id]))) ; can't change email if it's already taken BY ANOTHER ACCOUNT
(check-404 (exists? User, :id id, :is_active true)) ; only allow updates if the specified account is active
(check-400 (not (exists? User, :email email, :id [:not= id]))) ; can't change email if it's already taken BY ANOTHER ACCOUNT
(check-500 (upd-non-nil-keys User id
:email email
:first_name first_name
......
......@@ -338,18 +338,6 @@
(some-> id entity models/post-insert)))
;; ## EXISTS?
(defmacro exists?
"Easy way to see if something exists in the db.
(exists? User :id 100)"
[entity & {:as kwargs}]
`(boolean (seq (k/select (i/entity->korma ~entity)
(k/fields [:id])
(k/where ~(if (seq kwargs) kwargs {}))
(k/limit 1)))))
;; ## CASADE-DELETE
(defn ^:deprecated -cascade-delete
......@@ -605,17 +593,6 @@
(insert! entity (apply array-map k v more))))
;;; ## EXISTS?
;; The new implementation of exists? is commented out for the time being until we re-work existing uses
#_(defn exists?
"Easy way to see if something exists in the DB.
(db/exists? User :id 100)
NOTE: This only works for objects that have an `:id` field."
[entity & kvs]
(boolean (select-one entity (apply where (h/select :id) kvs))))
;;; ## SELECT
;; All of the following functions are based off of the old `sel` macro and can do things like select certain fields by wrapping ENTITY in a vector
......@@ -724,6 +701,16 @@
(apply select-field->field :id field entity options))
;;; ## EXISTS?
(defn exists?
"Easy way to see if something exists in the DB.
(db/exists? User :id 100)
NOTE: This only works for objects that have an `:id` field."
[entity & kvs]
(boolean (select-one entity (apply where (h/select :id) kvs))))
;;; ## CASADE-DELETE
(defn cascade-delete!
......
......@@ -76,7 +76,7 @@
Returns true if `Segment` exists and is active, false otherwise."
[id]
{:pre [(integer? id)]}
(db/exists? Segment :id id :is_active true))
(db/exists? Segment, :id id, :is_active true))
(defn retrieve-segment
"Fetch a single `Segment` by its ID value."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment