renamed company to client.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
(ns auto-ap.graphql.checks
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-company]]
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client]]
|
||||
[datomic.api :as d]
|
||||
[clojure.edn :as edn]
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
@@ -316,7 +316,7 @@
|
||||
(let [invoice (d-invoices/get-by-id (:invoice_id args))
|
||||
bank-account-id (:bank_account_id args)
|
||||
bank-account (d-bank-accounts/get-by-id bank-account-id)
|
||||
_ (assert-can-see-company (:id context) (:invoice/client invoice))
|
||||
_ (assert-can-see-client (:id context) (:invoice/client invoice))
|
||||
base-payment (base-payment [invoice] (:invoice/vendor invoice)
|
||||
(:invoice/client invoice)
|
||||
bank-account :payment-type/check 0 {(:invoice_id args) (:amount args)})]
|
||||
@@ -339,7 +339,7 @@
|
||||
(let [check (d-checks/get-by-id id)]
|
||||
(assert (or (= :payment-status/pending (:payment/status check))
|
||||
(#{:payment-type/cash :payment-type/debit} (:payment/type check))))
|
||||
(assert-can-see-company (:id context) (:client-id check))
|
||||
(assert-can-see-client (:id context) (:client-id check))
|
||||
(let [removing-payments (mapcat (fn [x]
|
||||
(let [invoice (:invoice-payment/invoice x)
|
||||
new-balance (+ (:invoice/outstanding-balance invoice)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(ns auto-ap.graphql.invoices
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-company assert-admin]]
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin]]
|
||||
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.invoices :as d-invoices]
|
||||
@@ -34,7 +34,7 @@
|
||||
:invoice/vendor vendor_id
|
||||
:invoice/client client_id}))
|
||||
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
|
||||
(let [_ (assert-can-see-company (:id context) client_id)
|
||||
(let [_ (assert-can-see-client (:id context) client_id)
|
||||
vendor (d-vendors/get-by-id vendor_id)
|
||||
|
||||
expense-account-id (:vendor/default-expense-account vendor)
|
||||
@@ -59,7 +59,7 @@
|
||||
(->graphql))))
|
||||
|
||||
|
||||
(defn edit-invoice [context {{:keys [id invoice_number total vendor_id date company_id] :as in} :invoice} value]
|
||||
(defn edit-invoice [context {{:keys [id invoice_number total vendor_id date client_id] :as in} :invoice} value]
|
||||
|
||||
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
@@ -71,7 +71,7 @@
|
||||
println))
|
||||
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
|
||||
paid-amount (- (:invoice/total invoice) (:invoice/outstanding-balance invoice))
|
||||
_ (assert-can-see-company (:id context) (:db/id (:client invoice)))
|
||||
_ (assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))
|
||||
updated-invoice (d-invoices/update {:db/id id
|
||||
:invoice/invoice-number invoice_number
|
||||
:invoice/date (coerce/to-date (parse date iso-date))
|
||||
@@ -82,7 +82,7 @@
|
||||
|
||||
(defn void-invoice [context {id :invoice_id} value]
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
_ (assert-can-see-client (:id context) (:client-id invoice))
|
||||
updated-invoice (d-invoices/update {:db/id id
|
||||
:invoice/total 0.0
|
||||
:invoice/outstanding-balance 0.0
|
||||
@@ -98,7 +98,7 @@
|
||||
(defn edit-expense-accounts [context args value]
|
||||
;; TODO - Can expense account id be used as a unique field? It may compose with component, meaning
|
||||
;; that you don't have to figure out which ones to delete and which ones to add. Just set to 0.
|
||||
(assert-can-see-company (:id context) (:db/id (:client (d-invoices/get-by-id (:invoice_id args)))))
|
||||
(assert-can-see-client (:id context) (:db/id (:invoice/client (d-invoices/get-by-id (:invoice_id args)))))
|
||||
(let [current-expense-accounts (:invoice/expense-accounts (d-invoices/get-by-id (:invoice_id args)))
|
||||
invoice-id (:invoice_id args)
|
||||
|
||||
|
||||
@@ -47,14 +47,14 @@
|
||||
(when-not (= "admin" (:user/role id))
|
||||
(throw-unauthorized)))
|
||||
|
||||
(defn can-see-company? [identity company]
|
||||
(defn can-see-client? [identity client]
|
||||
(or (= "admin" (:user/role identity))
|
||||
((set (map :db/id (:user/clients identity))) (:db/id company))
|
||||
((set (map :db/id (:user/clients identity))) company)))
|
||||
((set (map :db/id (:user/clients identity))) (:db/id client))
|
||||
((set (map :db/id (:user/clients identity))) client)))
|
||||
|
||||
(defn assert-can-see-company [identity company]
|
||||
(when-not (can-see-company? identity company)
|
||||
(println "IDENTITY " identity " can not see company " company)
|
||||
(defn assert-can-see-client [identity client]
|
||||
(when-not (can-see-client? identity client)
|
||||
(println "IDENTITY " identity " can not see company " client)
|
||||
(throw-unauthorized)))
|
||||
|
||||
(defn limited-clients [id]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(ns auto-ap.graphql.vendors
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-company]]
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql assert-can-see-client]]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.time :refer [parse iso-date]]
|
||||
[datomic.api :as d]
|
||||
|
||||
Reference in New Issue
Block a user