started making graphql do the right thing.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
(ns autoap.datomic
|
(ns auto-ap.datomic
|
||||||
(:require [datomic.api :as d]
|
(:require [datomic.api :as d]
|
||||||
[auto-ap.db.vendors :as v]
|
[auto-ap.db.vendors :as v]
|
||||||
[auto-ap.db.companies :as c]
|
[auto-ap.db.companies :as c]
|
||||||
@@ -166,7 +166,7 @@
|
|||||||
|
|
||||||
|
|
||||||
(def bank-account-schema
|
(def bank-account-schema
|
||||||
[{:db/ident :bank-account/id
|
[{:db/ident :bank-account/external-id
|
||||||
:db/valueType :db.type/long
|
:db/valueType :db.type/long
|
||||||
:db/cardinality :db.cardinality/one
|
:db/cardinality :db.cardinality/one
|
||||||
:db/doc "Identifier for bank account"}
|
: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] }]
|
(fn [{:keys [number id check-number bank-name bank-code routing name yodlee-account-id type] }]
|
||||||
(remove-nils #:bank-account {:number number
|
(remove-nils #:bank-account {:number number
|
||||||
:original-id (str client-id "-" id)
|
:original-id (str client-id "-" id)
|
||||||
:id id
|
:external-id id
|
||||||
:check-number check-number
|
:check-number check-number
|
||||||
:bank-name bank-name
|
:bank-name bank-name
|
||||||
:bank-code bank-code
|
:bank-code bank-code
|
||||||
@@ -581,7 +581,7 @@
|
|||||||
:bank-account-type/check)}))
|
:bank-account-type/check)}))
|
||||||
bank-accounts)
|
bank-accounts)
|
||||||
#:bank-account {:original-id (str client-id "-" 0)
|
#:bank-account {:original-id (str client-id "-" 0)
|
||||||
:id 0
|
:external-id 0
|
||||||
:type :bank-account-type/cash})} )))
|
:type :bank-account-type/cash})} )))
|
||||||
(d/transact (d/connect uri))))
|
(d/transact (d/connect uri))))
|
||||||
|
|
||||||
|
|||||||
15
src/clj/auto_ap/datomic/clients.clj
Normal file
15
src/clj/auto_ap/datomic/clients.clj
Normal 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)))))))
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
[auto-ap.graphql.utils :refer [assert-admin can-see-company? assert-can-see-company]]
|
[auto-ap.graphql.utils :refer [assert-admin can-see-company? assert-can-see-company]]
|
||||||
[auto-ap.db.vendors :as vendors]
|
[auto-ap.db.vendors :as vendors]
|
||||||
[auto-ap.db.companies :as companies]
|
[auto-ap.db.companies :as companies]
|
||||||
|
[auto-ap.datomic.clients :as d-clients]
|
||||||
[auto-ap.db.users :as users]
|
[auto-ap.db.users :as users]
|
||||||
[auto-ap.db.checks :as checks]
|
[auto-ap.db.checks :as checks]
|
||||||
[auto-ap.routes.checks :as rchecks]
|
[auto-ap.routes.checks :as rchecks]
|
||||||
@@ -33,7 +34,7 @@
|
|||||||
:objects
|
:objects
|
||||||
{
|
{
|
||||||
:company
|
:company
|
||||||
{:fields {:id {:type 'Int}
|
{:fields {:id {:type 'String}
|
||||||
:name {:type 'String}
|
:name {:type 'String}
|
||||||
:email {:type 'String}
|
:email {:type 'String}
|
||||||
:address {:type :address}
|
:address {:type :address}
|
||||||
@@ -41,7 +42,7 @@
|
|||||||
:bank_accounts {:type '(list :bank_account)}}}
|
:bank_accounts {:type '(list :bank_account)}}}
|
||||||
|
|
||||||
:bank_account
|
:bank_account
|
||||||
{:fields {:id {:type 'Int}
|
{:fields {:id {:type 'String}
|
||||||
:type {:type 'String}
|
:type {:type 'String}
|
||||||
:number {:type 'String}
|
:number {:type 'String}
|
||||||
:check_number {:type 'Int}
|
:check_number {:type 'Int}
|
||||||
@@ -451,9 +452,11 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn get-company [context args value]
|
(defn get-company [context args value]
|
||||||
(->graphql
|
(println "GETTING COMPANY" (:id context))
|
||||||
(filter #(can-see-company? (:id context) %)
|
(doto (->graphql
|
||||||
(companies/get-all))))
|
(filter #(can-see-company? (:id context) %)
|
||||||
|
(d-clients/get-all)))
|
||||||
|
println))
|
||||||
|
|
||||||
(defn join-companies [users]
|
(defn join-companies [users]
|
||||||
(let [companies (by :id (companies/get-all))]
|
(let [companies (by :id (companies/get-all))]
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
(defn can-see-company? [identity company]
|
(defn can-see-company? [identity company]
|
||||||
(or (= "admin" (:role identity))
|
(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]
|
(defn assert-can-see-company [identity company]
|
||||||
(when-not (can-see-company? identity company)
|
(when-not (can-see-company? identity company)
|
||||||
|
|||||||
Reference in New Issue
Block a user