logging in, and updating users, works.
This commit is contained in:
@@ -25,6 +25,10 @@
|
||||
(defn get-all []
|
||||
(map data->fields (query base-query)))
|
||||
|
||||
(defn get-by-id [id]
|
||||
(first (map data->fields (query (-> base-query
|
||||
(helpers/merge-where [:= :id id]))))))
|
||||
|
||||
(defn find-or-insert! [row]
|
||||
(let [user (-> base-query
|
||||
(helpers/merge-where [:and [:= :provider-id (:provider-id row)]
|
||||
@@ -42,3 +46,10 @@
|
||||
first
|
||||
db->clj
|
||||
data->fields))))
|
||||
|
||||
|
||||
(defn update! [row]
|
||||
(j/update! (get-conn)
|
||||
:users
|
||||
(-> row (fields->data) (clj->db))
|
||||
["id = ?" (:id row)]))
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
[auto-ap.db.users :as users]
|
||||
[auto-ap.db.checks :as checks]
|
||||
[auto-ap.routes.checks :as rchecks]
|
||||
[auto-ap.graphql.users :as gq-users]
|
||||
[auto-ap.db.reminders :as reminders]
|
||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||
[auto-ap.db.utils :as utils]
|
||||
@@ -69,7 +70,8 @@
|
||||
{:fields {:id {:type 'Int}
|
||||
:name {:type 'String}
|
||||
:role {:type 'String}
|
||||
:companies {:type '(list :company)}}}
|
||||
:companies {:type '(list :company)
|
||||
:resolve :get-user-companies}}}
|
||||
|
||||
:invoice
|
||||
{:fields {:id {:type 'Int}
|
||||
@@ -133,6 +135,12 @@
|
||||
{
|
||||
:invoice_payment {:fields {:invoice_id {:type 'Int}
|
||||
:amount {:type 'Float}}}
|
||||
|
||||
:edit_user
|
||||
{:fields {:id {:type 'Int}
|
||||
:name {:type 'String}
|
||||
:role {:type 'String}
|
||||
:companies {:type '(list Int)}}}
|
||||
}
|
||||
|
||||
:mutations
|
||||
@@ -140,7 +148,10 @@
|
||||
:args {:invoice_payments {:type '(list :invoice_payment)}
|
||||
:bank_account_id {:type 'Int}
|
||||
:company_id {:type 'Int}}
|
||||
:resolve :mutation/print-checks}}})
|
||||
:resolve :mutation/print-checks}
|
||||
:edit_user {:type :user
|
||||
:args {:edit_user {:type :edit_user}}
|
||||
:resolve :mutation/edit-user}}})
|
||||
|
||||
|
||||
|
||||
@@ -233,6 +244,12 @@
|
||||
(company-cache (:company_id value))
|
||||
(companies/get-by-id (:company_id value)))))
|
||||
|
||||
(defn get-user-companies [context args value]
|
||||
(->graphql
|
||||
(if-let [company-cache (:company-cache context)]
|
||||
(map company-cache (:companies value))
|
||||
(map companies/get-by-id (:companies value)))))
|
||||
|
||||
(defn get-company [context args value]
|
||||
(->graphql
|
||||
(companies/get-all)))
|
||||
@@ -246,12 +263,11 @@
|
||||
|
||||
(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)))
|
||||
|
||||
extra-context (cond-> context
|
||||
(executor/selects-field? context :user/companies) (assoc :company-cache (by :id (companies/get-all))))]
|
||||
(resolve/with-context
|
||||
(->graphql users) extra-context)))
|
||||
|
||||
(defn get-vendor [context args value]
|
||||
(->graphql
|
||||
@@ -265,6 +281,10 @@
|
||||
(:company_id args)
|
||||
(:bank_account_id args))))
|
||||
|
||||
(defn edit-user [context args value]
|
||||
(->graphql
|
||||
(gq-users/edit-user (:edit_user args))))
|
||||
|
||||
(def schema
|
||||
(-> integreat-schema
|
||||
(attach-resolvers {:get-invoice-page get-invoice-page
|
||||
@@ -275,7 +295,9 @@
|
||||
:get-check-by-id get-check-by-id
|
||||
:get-company get-company
|
||||
:get-user get-user
|
||||
:get-user-companies get-user-companies
|
||||
:mutation/print-checks print-checks
|
||||
:mutation/edit-user edit-user
|
||||
:get-vendor get-vendor})
|
||||
schema/compile))
|
||||
|
||||
|
||||
8
src/clj/auto_ap/graphql/users.clj
Normal file
8
src/clj/auto_ap/graphql/users.clj
Normal file
@@ -0,0 +1,8 @@
|
||||
(ns auto-ap.graphql.users
|
||||
(:require [auto-ap.db.users :as users]))
|
||||
|
||||
(defn edit-user [user]
|
||||
(users/update! user)
|
||||
(users/get-by-id (:id user)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user