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 findy-by-schema
{:uuid schema-uuid}))) {: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 (neo4j/defquery create-new
"MATCH (s:schema {uuid:{schema_uuid}}), "MATCH (s:schema {uuid:{schema_uuid}}),
(u:user {uuid:{user_uuid}}) (u:user {uuid:{user_uuid}})

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

Loading…
Cancel
Save