form refactor foo

integration-tests
Josha von Gizycki 6 years ago
parent a72ddfb7f4
commit b5898110c4

@ -9,7 +9,7 @@
(neo4j/defquery
findy-by-schema
"MATCH (i:instance)-->(s:schema)
"MATCH (i:instance)-[:of]->(s:schema)
WHERE s.uuid = {uuid}
RETURN i
ORDER BY i.updated_at DESC")
@ -77,3 +77,14 @@
(:a %))
(neo4j/exec-query! find-properties
{:uuid uuid})))
(neo4j/defquery schema-of
"MATCH (i:instance {uuid:{uuid}}),
(i)-[:of]->(s:schema)
RETURN s")
(defn schema-of [uuid]
(-> (neo4j/exec-query! schema-of
{:uuid uuid})
first
(map :s)))

@ -20,7 +20,7 @@
:required true
:widget (attr-type->widget (:type attr))})
(defn new-form [schema-uuid required-attrs]
(defn with-attributes [attrs]
(update form
:fields
(fn [fields]
@ -29,11 +29,11 @@
(attr->field-id attr)
(attr->field attr)))
fields
required-attrs))))
attrs))))
(defn form-data->instance [form-data required-attrs]
(defn form-data->instance [form-data attrs]
{:name (:name form-data)
:properties (map (fn [ra]
{:attribute ra
:value ((attr->field-id ra) form-data)})
required-attrs)})
attrs)})

@ -13,14 +13,12 @@
(defn list! [schema-uuid req]
(view/list! (domain-schema/find-by-uuid! schema-uuid)
(domain/find-by-schema! schema-uuid)
(forms-inst/new-form schema-uuid
(domain-attr/required! schema-uuid))
(forms-inst/with-attributes (domain-attr/required! schema-uuid))
req))
(defn new! [req]
(let [schema-uuid (get-in req [:params :schema-uuid])
form-def (forms-inst/new-form schema-uuid
(domain-attr/required! schema-uuid))]
form-def (forms-inst/with-attributes (domain-attr/required! schema-uuid))]
(if (form/valid? form-def req)
(let [form-data (form/form-data form-def req)
req-attrs (domain-attr/required! schema-uuid)

Loading…
Cancel
Save