Added the ability to remove them in the ui.3
This commit is contained in:
@@ -1,14 +1,27 @@
|
||||
(ns auto-ap.datomic.vendors
|
||||
(:require [datomic.api :as d]
|
||||
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||
[auto-ap.datomic :refer [uri]]))
|
||||
(defn cleanse [id vendor]
|
||||
(let [clients (if-let [clients (limited-clients id)]
|
||||
(set (map :db/id clients))
|
||||
nil)]
|
||||
(if clients
|
||||
(-> vendor
|
||||
(update :vendor/account-overrides (fn [ao] (filter #(clients (:db/id (:vendor-account-override/client %))) ao)))
|
||||
(update :vendor/terms-overrides (fn [to] (filter #(clients (:db/id (:vendor-terms-override/client %))) to))))
|
||||
vendor)))
|
||||
|
||||
(defn get-graphql [args]
|
||||
(->> (d/q '[:find (pull ?e [* {:vendor/account-overrides [* {:vendor-account-override/client [:client/name :db/id]
|
||||
:vendor-account-override/account [:account/name :account/numeric-code :db/id]}]
|
||||
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :db/id]}]}])
|
||||
:where [?e :vendor/name]]
|
||||
(d/db (d/connect uri)))
|
||||
(map first)))
|
||||
(->> (cond-> {:query {:find ['(pull ?e [* {:vendor/account-overrides [* {:vendor-account-override/client [:client/name :db/id]
|
||||
:vendor-account-override/account [:account/name :account/numeric-code :db/id]}]
|
||||
:vendor/terms-overrides [* {:vendor-terms-override/client [:client/name :db/id]}]}])]
|
||||
:in ['$]
|
||||
:where ['[?e :vendor/name]]}
|
||||
:args [(d/db (d/connect uri))]})
|
||||
(d/query)
|
||||
(map first)
|
||||
(map #(cleanse (:id args) %))))
|
||||
|
||||
(defn get-by-id [id]
|
||||
|
||||
@@ -24,6 +37,7 @@
|
||||
(map first)
|
||||
(first)))
|
||||
|
||||
|
||||
(defn terms-for-client-id [vendor client-id]
|
||||
(->>
|
||||
(filter
|
||||
|
||||
@@ -793,7 +793,7 @@
|
||||
|
||||
(defn get-vendor [context args value]
|
||||
(->graphql
|
||||
(d-vendors/get-graphql args)))
|
||||
(d-vendors/get-graphql (assoc args :id (:id context)))))
|
||||
|
||||
(defn print-checks [context args value]
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
node))
|
||||
m))
|
||||
|
||||
(defn is-admin? [id]
|
||||
(println "role" id)
|
||||
(= "admin" (:user/role id)))
|
||||
|
||||
(defn assert-admin [id]
|
||||
(println "role" id)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user