drastically simplify logic to detect duplicate attribute names

neo4j-4
Josha von Gizycki 5 years ago
parent 4aa3a14ba2
commit b29ef0d724

@ -12,6 +12,16 @@
findy-by-schema
{:uuid schema-uuid})))
(neo4j/defquery with-name
"MATCH (a:attribute)
WHERE a.name = {name}
RETURN a")
(defn with-name! [name]
(-> (neo4j/exec-query! with-name
{:name name})
first
:a))
(neo4j/defquery create-new
"MATCH (s:schema {uuid:{schema_uuid}}),
(u:user {uuid:{user_uuid}})

@ -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!)

Loading…
Cancel
Save