users are not activated, looks like you can edit existing ones

This commit is contained in:
Bryce Covert
2018-05-21 17:48:59 -07:00
parent d020a4d254
commit 3fee89f840
12 changed files with 282 additions and 35 deletions

View File

@@ -6,8 +6,10 @@
[com.walmartlabs.lacinia.executor :as executor]
[com.walmartlabs.lacinia.resolve :as resolve]
[auto-ap.db.invoices :as invoices]
[auto-ap.utils :refer [by]]
[auto-ap.db.vendors :as vendors]
[auto-ap.db.companies :as companies]
[auto-ap.db.users :as users]
[auto-ap.db.checks :as checks]
[auto-ap.routes.checks :as rchecks]
[auto-ap.db.reminders :as reminders]
@@ -63,6 +65,12 @@
:check {:type :check
:resolve :get-check-by-id}}}
:user
{:fields {:id {:type 'Int}
:name {:type 'String}
:role {:type 'String}
:companies {:type '(list :company)}}}
:invoice
{:fields {:id {:type 'Int}
:total {:type 'String}
@@ -117,7 +125,9 @@
:company {:type '(list :company)
:resolve :get-company}
:vendor {:type '(list :vendor)
:resolve :get-vendor}}
:resolve :get-vendor}
:user {:type '(list :user)
:resolve :get-user}}
:input-objects
{
@@ -132,12 +142,7 @@
:company_id {:type 'Int}}
:resolve :mutation/print-checks}}})
(defn by [x kf]
(reduce
(fn [m x]
(assoc m (kf x) x))
{}
x))
(defn snake->kebab [s]
(str/replace s #"_" "-"))
@@ -178,8 +183,8 @@
(defn get-invoice-page [context args value]
(let [extra-context
(cond-> {}
(executor/selects-field? context :invoice/vendor) (assoc :vendor-cache (by (vendors/get-all) :id ))
(executor/selects-field? context :invoice/company) (assoc :company-cache (by (companies/get-all) :id )))
(executor/selects-field? context :invoice/vendor) (assoc :vendor-cache (by :id (vendors/get-all)))
(executor/selects-field? context :invoice/company) (assoc :company-cache (by :id (companies/get-all))))
invoices (map
->graphql
@@ -195,7 +200,7 @@
(defn get-reminder-page [context args value]
(let [extra-context
(cond-> {}
(executor/selects-field? context :reminder/vendor) (assoc :vendor-cache (by (vendors/get-all) :id )))
(executor/selects-field? context :reminder/vendor) (assoc :vendor-cache (by :id (vendors/get-all))))
reminders (map
->graphql
@@ -232,6 +237,22 @@
(->graphql
(companies/get-all)))
(defn join-companies [users]
(let [companies (by :id (companies/get-all))]
(map
(fn [u]
(update u :companies #(map companies %)))
users)))
(defn get-user [context args value]
(let [users (users/get-all)
users (cond-> users
(executor/selects-field? context :user/companies)
(join-companies)
)]
(println users)
(->graphql users)))
(defn get-vendor [context args value]
(->graphql
(vendors/get-all)))
@@ -253,6 +274,7 @@
:get-invoices-checks get-invoices-checks
:get-check-by-id get-check-by-id
:get-company get-company
:get-user get-user
:mutation/print-checks print-checks
:get-vendor get-vendor})
schema/compile))