logging in, and updating users, works.
This commit is contained in:
@@ -25,6 +25,10 @@
|
|||||||
(defn get-all []
|
(defn get-all []
|
||||||
(map data->fields (query base-query)))
|
(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]
|
(defn find-or-insert! [row]
|
||||||
(let [user (-> base-query
|
(let [user (-> base-query
|
||||||
(helpers/merge-where [:and [:= :provider-id (:provider-id row)]
|
(helpers/merge-where [:and [:= :provider-id (:provider-id row)]
|
||||||
@@ -42,3 +46,10 @@
|
|||||||
first
|
first
|
||||||
db->clj
|
db->clj
|
||||||
data->fields))))
|
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.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]
|
||||||
|
[auto-ap.graphql.users :as gq-users]
|
||||||
[auto-ap.db.reminders :as reminders]
|
[auto-ap.db.reminders :as reminders]
|
||||||
[auto-ap.db.invoices-checks :as invoices-checks]
|
[auto-ap.db.invoices-checks :as invoices-checks]
|
||||||
[auto-ap.db.utils :as utils]
|
[auto-ap.db.utils :as utils]
|
||||||
@@ -69,7 +70,8 @@
|
|||||||
{:fields {:id {:type 'Int}
|
{:fields {:id {:type 'Int}
|
||||||
:name {:type 'String}
|
:name {:type 'String}
|
||||||
:role {:type 'String}
|
:role {:type 'String}
|
||||||
:companies {:type '(list :company)}}}
|
:companies {:type '(list :company)
|
||||||
|
:resolve :get-user-companies}}}
|
||||||
|
|
||||||
:invoice
|
:invoice
|
||||||
{:fields {:id {:type 'Int}
|
{:fields {:id {:type 'Int}
|
||||||
@@ -133,6 +135,12 @@
|
|||||||
{
|
{
|
||||||
:invoice_payment {:fields {:invoice_id {:type 'Int}
|
:invoice_payment {:fields {:invoice_id {:type 'Int}
|
||||||
:amount {:type 'Float}}}
|
:amount {:type 'Float}}}
|
||||||
|
|
||||||
|
:edit_user
|
||||||
|
{:fields {:id {:type 'Int}
|
||||||
|
:name {:type 'String}
|
||||||
|
:role {:type 'String}
|
||||||
|
:companies {:type '(list Int)}}}
|
||||||
}
|
}
|
||||||
|
|
||||||
:mutations
|
:mutations
|
||||||
@@ -140,7 +148,10 @@
|
|||||||
:args {:invoice_payments {:type '(list :invoice_payment)}
|
:args {:invoice_payments {:type '(list :invoice_payment)}
|
||||||
:bank_account_id {:type 'Int}
|
:bank_account_id {:type 'Int}
|
||||||
:company_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))
|
(company-cache (:company_id value))
|
||||||
(companies/get-by-id (: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]
|
(defn get-company [context args value]
|
||||||
(->graphql
|
(->graphql
|
||||||
(companies/get-all)))
|
(companies/get-all)))
|
||||||
@@ -246,12 +263,11 @@
|
|||||||
|
|
||||||
(defn get-user [context args value]
|
(defn get-user [context args value]
|
||||||
(let [users (users/get-all)
|
(let [users (users/get-all)
|
||||||
users (cond-> users
|
|
||||||
(executor/selects-field? context :user/companies)
|
extra-context (cond-> context
|
||||||
(join-companies)
|
(executor/selects-field? context :user/companies) (assoc :company-cache (by :id (companies/get-all))))]
|
||||||
)]
|
(resolve/with-context
|
||||||
(println users)
|
(->graphql users) extra-context)))
|
||||||
(->graphql users)))
|
|
||||||
|
|
||||||
(defn get-vendor [context args value]
|
(defn get-vendor [context args value]
|
||||||
(->graphql
|
(->graphql
|
||||||
@@ -265,6 +281,10 @@
|
|||||||
(:company_id args)
|
(:company_id args)
|
||||||
(:bank_account_id args))))
|
(:bank_account_id args))))
|
||||||
|
|
||||||
|
(defn edit-user [context args value]
|
||||||
|
(->graphql
|
||||||
|
(gq-users/edit-user (:edit_user args))))
|
||||||
|
|
||||||
(def schema
|
(def schema
|
||||||
(-> integreat-schema
|
(-> integreat-schema
|
||||||
(attach-resolvers {:get-invoice-page get-invoice-page
|
(attach-resolvers {:get-invoice-page get-invoice-page
|
||||||
@@ -275,7 +295,9 @@
|
|||||||
:get-check-by-id get-check-by-id
|
:get-check-by-id get-check-by-id
|
||||||
:get-company get-company
|
:get-company get-company
|
||||||
:get-user get-user
|
:get-user get-user
|
||||||
|
:get-user-companies get-user-companies
|
||||||
:mutation/print-checks print-checks
|
:mutation/print-checks print-checks
|
||||||
|
:mutation/edit-user edit-user
|
||||||
:get-vendor get-vendor})
|
:get-vendor get-vendor})
|
||||||
schema/compile))
|
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)))
|
||||||
|
|
||||||
|
|
||||||
@@ -8,3 +8,12 @@
|
|||||||
#(assoc %1 (f %2) (fv %2))
|
#(assoc %1 (f %2) (fv %2))
|
||||||
{}
|
{}
|
||||||
xs)))
|
xs)))
|
||||||
|
|
||||||
|
(defn replace-if [f candidate existing]
|
||||||
|
(reduce
|
||||||
|
(fn [xs x]
|
||||||
|
(if (f x candidate)
|
||||||
|
(conj xs candidate)
|
||||||
|
(conj xs x)))
|
||||||
|
[]
|
||||||
|
existing))
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
(:require-macros [cljs.core.async.macros :refer [go]])
|
(:require-macros [cljs.core.async.macros :refer [go]])
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
|
[clojure.string :as str]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.events.admin.companies :as events]
|
[auto-ap.events.admin.companies :as events]
|
||||||
[auto-ap.entities.companies :as entity]
|
[auto-ap.entities.companies :as entity]
|
||||||
[auto-ap.views.components.address :refer [address-field]]
|
[auto-ap.views.components.address :refer [address-field]]
|
||||||
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]]
|
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]]
|
||||||
[auto-ap.views.components.modal :refer [modal]]
|
[auto-ap.views.components.modal :refer [modal]]
|
||||||
[auto-ap.utils :refer [by]]
|
[auto-ap.utils :refer [by replace-if]]
|
||||||
[cljs.reader :as edn]
|
[cljs.reader :as edn]
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
[bidi.bidi :as bidi]))
|
[bidi.bidi :as bidi]))
|
||||||
@@ -62,9 +63,35 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::remove-company
|
::remove-company
|
||||||
(fn [db [_ d]]
|
(fn [db [_ d]]
|
||||||
(println "remove compnay " d)
|
|
||||||
(update-in db [::editing :user :companies] #(filter (fn [c] (not= (:id c) d)) %))))
|
(update-in db [::editing :user :companies] #(filter (fn [c] (not= (:id c) d)) %))))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::save
|
||||||
|
(fn [{:keys [db]} [_]]
|
||||||
|
{:db (-> db
|
||||||
|
(assoc-in [::editing :saving?] true ))
|
||||||
|
:graphql
|
||||||
|
{:token (-> db :user)
|
||||||
|
|
||||||
|
:query-obj {:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "EditUser"}
|
||||||
|
|
||||||
|
:venia/queries [{:query/data [:edit-user
|
||||||
|
{:edit-user (update (get-in db [::editing :user]) :companies #(map :id %))}
|
||||||
|
[:id :name :role [:companies [:id :name]]]]}]}
|
||||||
|
:on-success [::saved]}}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::saved
|
||||||
|
(fn [{:keys [db]} [_ {:keys [edit-user]}]]
|
||||||
|
{:db (-> db
|
||||||
|
(assoc-in [::editing :saving?] false )
|
||||||
|
(dissoc ::editing)
|
||||||
|
(update ::users
|
||||||
|
(fn [us]
|
||||||
|
(replace-if #(= (:id %1) (:id %2)) edit-user us)
|
||||||
|
)))}))
|
||||||
|
|
||||||
(defn users-table []
|
(defn users-table []
|
||||||
(let [users (re-frame/subscribe [::users])]
|
(let [users (re-frame/subscribe [::users])]
|
||||||
[:table {:class "table", :style {:width "100%"}}
|
[:table {:class "table", :style {:width "100%"}}
|
||||||
@@ -79,14 +106,13 @@
|
|||||||
:style {"cursor" "pointer"}}
|
:style {"cursor" "pointer"}}
|
||||||
[:td name]
|
[:td name]
|
||||||
[:td role]
|
[:td role]
|
||||||
[:td]])]]))
|
[:td (str/join ", " (map :name companies))]])]]))
|
||||||
(def admin-users-page
|
(def admin-users-page
|
||||||
(with-meta
|
(with-meta
|
||||||
(fn []
|
(fn []
|
||||||
[:div
|
[:div
|
||||||
(let [companies (re-frame/subscribe [::users])
|
(let [companies (re-frame/subscribe [::users])
|
||||||
editing @(re-frame/subscribe [::editing])]
|
editing @(re-frame/subscribe [::editing])]
|
||||||
(println editing)
|
|
||||||
|
|
||||||
[:div
|
[:div
|
||||||
[:h1.title "Users"]
|
[:h1.title "Users"]
|
||||||
@@ -94,11 +120,11 @@
|
|||||||
|
|
||||||
(when editing
|
(when editing
|
||||||
[modal {:title (str "Edit " (:name (:user editing)))
|
[modal {:title (str "Edit " (:name (:user editing)))
|
||||||
:foot [:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save]))}
|
:foot [:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::save]))
|
||||||
[:span "Save"]
|
:class (when (:saving? editing)
|
||||||
(when (:saving? editing)
|
"is-loading"
|
||||||
[:span.icon
|
)}
|
||||||
[:i.fa.fa-spin.fa-spinner]])]
|
[:span "Save"]]
|
||||||
:hide-event [::edit nil]}
|
:hide-event [::edit nil]}
|
||||||
[horizontal-field
|
[horizontal-field
|
||||||
[:label.label "Name"]
|
[:label.label "Name"]
|
||||||
|
|||||||
@@ -4,14 +4,26 @@
|
|||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.events :as events]
|
[auto-ap.events :as events]
|
||||||
[auto-ap.views.utils :refer [login-url]]
|
[auto-ap.views.utils :refer [login-url dispatch-event]]
|
||||||
[cljs.reader :as edn]
|
[cljs.reader :as edn]
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
[bidi.bidi :as bidi]
|
[bidi.bidi :as bidi]
|
||||||
[goog.string :as gstring]))
|
[goog.string :as gstring]))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::relogin
|
||||||
|
(fn [{:keys [db]} _]
|
||||||
|
{
|
||||||
|
:db (assoc db :user nil)}
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
(defn needs-activation-page []
|
(defn needs-activation-page []
|
||||||
[:div
|
[:div
|
||||||
[:h2 "Sorry, your user is not activated yet. Please have Ben Skinner enable your account."]])
|
[:h2 "Sorry, your user is not activated yet. Please have Ben Skinner enable your account. Click "
|
||||||
|
[:a {:on-click (fn []
|
||||||
|
(re-frame/dispatch-sync [::relogin])
|
||||||
|
true)
|
||||||
|
:href login-url}
|
||||||
|
"here"]
|
||||||
|
" to try again."]])
|
||||||
|
|||||||
Reference in New Issue
Block a user