started making graphql do the right thing.

This commit is contained in:
Bryce Covert
2018-08-10 22:36:37 -07:00
parent 8ebd3da0c7
commit cbbabb2219
4 changed files with 28 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
(ns autoap.datomic
(ns auto-ap.datomic
(:require [datomic.api :as d]
[auto-ap.db.vendors :as v]
[auto-ap.db.companies :as c]
@@ -166,7 +166,7 @@
(def bank-account-schema
[{:db/ident :bank-account/id
[{:db/ident :bank-account/external-id
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one
:db/doc "Identifier for bank account"}
@@ -569,7 +569,7 @@
(fn [{:keys [number id check-number bank-name bank-code routing name yodlee-account-id type] }]
(remove-nils #:bank-account {:number number
:original-id (str client-id "-" id)
:id id
:external-id id
:check-number check-number
:bank-name bank-name
:bank-code bank-code
@@ -581,7 +581,7 @@
:bank-account-type/check)}))
bank-accounts)
#:bank-account {:original-id (str client-id "-" 0)
:id 0
:external-id 0
:type :bank-account-type/cash})} )))
(d/transact (d/connect uri))))

View File

@@ -0,0 +1,15 @@
(ns auto-ap.datomic.clients
(:require [datomic.api :as d]
[auto-ap.datomic :refer [uri]]))
(defn get-all []
(->> (d/q '[:find (pull ?e [*])
:where [?e :client/name]]
(d/db (d/connect uri)))
(map first)
(map (fn [c]
(update c :client/bank-accounts
(fn [bas]
(map (fn [ba]
(update ba :bank-account/type :db/ident ))
bas)))))))

View File

@@ -11,6 +11,7 @@
[auto-ap.graphql.utils :refer [assert-admin can-see-company? assert-can-see-company]]
[auto-ap.db.vendors :as vendors]
[auto-ap.db.companies :as companies]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.db.users :as users]
[auto-ap.db.checks :as checks]
[auto-ap.routes.checks :as rchecks]
@@ -33,7 +34,7 @@
:objects
{
:company
{:fields {:id {:type 'Int}
{:fields {:id {:type 'String}
:name {:type 'String}
:email {:type 'String}
:address {:type :address}
@@ -41,7 +42,7 @@
:bank_accounts {:type '(list :bank_account)}}}
:bank_account
{:fields {:id {:type 'Int}
{:fields {:id {:type 'String}
:type {:type 'String}
:number {:type 'String}
:check_number {:type 'Int}
@@ -451,9 +452,11 @@
(defn get-company [context args value]
(->graphql
(filter #(can-see-company? (:id context) %)
(companies/get-all))))
(println "GETTING COMPANY" (:id context))
(doto (->graphql
(filter #(can-see-company? (:id context) %)
(d-clients/get-all)))
println))
(defn join-companies [users]
(let [companies (by :id (companies/get-all))]

View File

@@ -47,7 +47,7 @@
(defn can-see-company? [identity company]
(or (= "admin" (:role identity))
((set (:companies identity)) (:id company))))
((set (map :db/id (:user/companies identity))) (:db/id company))))
(defn assert-can-see-company [identity company]
(when-not (can-see-company? identity company)