adding more validation.
This commit is contained in:
@@ -16,9 +16,11 @@
|
||||
(when (seq (invoices/find-conflicting {:invoice-number invoice_number
|
||||
:vendor-id vendor_id
|
||||
:company-id company_id}))
|
||||
(throw (ex-info "that invoice already exists" {:invoice-number invoice_number})))
|
||||
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
|
||||
(let [vendor (-create-or-get-vendor vendor_id vendor_name)
|
||||
_ (assert-can-see-company (:id context) company_id)
|
||||
_ (when-not (:default-expense-account vendor)
|
||||
(throw (ex-info (str "Vendor '" (:name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))
|
||||
company (companies/get-by-id company_id)
|
||||
|
||||
[invoice] (invoices/insert-multi! [{:invoice-number invoice_number
|
||||
@@ -44,7 +46,7 @@
|
||||
:invoice-number invoice_number
|
||||
:vendor-id (:vendor-id invoice)
|
||||
:company-id (:company-id invoice)}))
|
||||
(throw (ex-info "that invoice already exists" {:invoice-number invoice_number})))
|
||||
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
|
||||
paid-amount (- (:total invoice) (:outstanding-balance invoice))
|
||||
_ (assert-can-see-company (:id context) (:company-id invoice))
|
||||
updated-invoice (invoices/update (-> in
|
||||
|
||||
@@ -16,9 +16,14 @@
|
||||
(when (= "none" (:role (:identity r)))
|
||||
(throw-unauthorized))
|
||||
|
||||
(let [variables (some-> (query-params "variables")
|
||||
edn/read-string)]
|
||||
{:status 200
|
||||
:body (pr-str (ql/query (:identity r) (query-params "query") variables ))
|
||||
:headers {"Content-Type" "application/edn"}})))
|
||||
(try
|
||||
(let [variables (some-> (query-params "variables")
|
||||
edn/read-string)]
|
||||
{:status 200
|
||||
:body (pr-str (ql/query (:identity r) (query-params "query") variables ))
|
||||
:headers {"Content-Type" "application/edn"}})
|
||||
(catch Exception e
|
||||
{:status 400
|
||||
:body (pr-str {:data (merge {:message (.getMessage e)} (ex-data e))})
|
||||
:headers {"Content-Type" "application/edn"}}))))
|
||||
wrap-secure))
|
||||
|
||||
@@ -344,7 +344,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-create-failed
|
||||
(fn [{:keys [db]} [_ data]]
|
||||
{:dispatch [::events/modal-failed ::new-invoice "That invoice already exists."]}))
|
||||
{:dispatch [::events/modal-failed ::new-invoice (:message data)]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-created
|
||||
|
||||
Reference in New Issue
Block a user