Added the ability to remove them in the ui.3

This commit is contained in:
Bryce Covert
2020-04-20 07:49:38 -07:00
parent 47babdfe7c
commit 773ae19f5c
7 changed files with 100 additions and 45 deletions

View File

@@ -42,6 +42,9 @@
node))
m))
(defn is-admin? [id]
(println "role" id)
(= "admin" (:user/role id)))
(defn assert-admin [id]
(println "role" id)

View File

@@ -1,5 +1,5 @@
(ns auto-ap.graphql.vendors
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-client]]
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-client assert-admin is-admin?]]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.time :refer [parse iso-date]]
[datomic.api :as d]
@@ -9,7 +9,22 @@
(defn upsert-vendor [context {{:keys [id name hidden terms code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule terms_overrides account_overrides] :as in} :vendor} value]
(let [_ (println default_account_id)
(when id
(assert-admin (:id context)))
(let [term-overrides (mapv
(fn [to]
(cond->
#:vendor-terms-override {:client (:client_id to)
:terms (:terms to)}
(:id to) (assoc :db/id (:id to))))
terms_overrides)
account-overrides (mapv
(fn [ao]
(cond->
#:vendor-account-override {:client (:client_id ao)
:account (:account_id ao)}
(:id ao) (assoc :db/id (:id ao))))
account_overrides)
transaction [(remove-nils #:vendor {:db/id (if id
id
"vendor")
@@ -20,20 +35,10 @@
:print-as print_as
:default-account default_account_id
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
:terms-overrides (mapv
(fn [to]
(cond->
#:vendor-terms-override {:client (:client_id to)
:terms (:terms to)}
(:id to) (assoc :db/id (:id to))))
terms_overrides)
:account-overrides (mapv
(fn [ao]
(cond->
#:vendor-account-override {:client (:client_id ao)
:account (:account_id ao)}
(:id ao) (assoc :db/id (:id ao))))
account_overrides)
:term-overrides (when (is-admin? (:id context))
term-overrides)
:account-overrides (when (is-admin? (:id context))
account-overrides)
:address (when address
(remove-nils #:address {:db/id (if (:id address)
(:id address)