|
|
|
@ -5,18 +5,11 @@
|
|
|
|
|
[clojure.spec.alpha :as spec]))
|
|
|
|
|
|
|
|
|
|
(defn unique-attr-name-in-schema! [req]
|
|
|
|
|
(let [schema-uuid (get-in req [:params :schema])
|
|
|
|
|
attr-uuid (get-in req [:params :uuid])
|
|
|
|
|
(let [attr-uuid (get-in req [:params :uuid])
|
|
|
|
|
name (get-in req [:params :name])
|
|
|
|
|
duplicates (->> (db-attr/find-by-schema! schema-uuid)
|
|
|
|
|
(map #(if (or (and (empty? attr-uuid)
|
|
|
|
|
(= name (:name %)))
|
|
|
|
|
(and (seq attr-uuid)
|
|
|
|
|
(= name (:name %))
|
|
|
|
|
(not= attr-uuid (:uuid %))))
|
|
|
|
|
1 0))
|
|
|
|
|
(apply +))]
|
|
|
|
|
(zero? duplicates)))
|
|
|
|
|
matching-attr (db-attr/with-name! name)]
|
|
|
|
|
(or (nil? matching-attr)
|
|
|
|
|
(= attr-uuid (:uuid matching-attr)))))
|
|
|
|
|
|
|
|
|
|
(spec/def ::unique-attr-name-per-schema
|
|
|
|
|
unique-attr-name-in-schema!)
|
|
|
|
|