Prevents bad bank account
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
(ns auto-ap.ssr.admin.clients
|
||||
(:require [auto-ap.datomic
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields apply-pagination apply-sort-3
|
||||
audit-transact conn merge-query pull-attr pull-id
|
||||
pull-many query2]]
|
||||
@@ -26,9 +27,10 @@
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.utils
|
||||
:refer [apply-middleware-to-all-handlers entity-id
|
||||
form-validation-error html-response main-transformer
|
||||
many-entity modal-response ref->enum-schema strip temp-id
|
||||
wrap-entity wrap-schema-enforce wrap-merge-prior-hx]]
|
||||
form-validation-error html-response many-entity
|
||||
many-entity-custom modal-response ref->enum-schema strip
|
||||
temp-id wrap-entity wrap-merge-prior-hx
|
||||
wrap-schema-enforce]]
|
||||
[auto-ap.time :as atime]
|
||||
[bidi.bidi :as bidi]
|
||||
[cheshire.core :as cheshire]
|
||||
@@ -42,7 +44,8 @@
|
||||
[malli.transform :as mt]
|
||||
[malli.util :as mut]
|
||||
[manifold.deferred :as de])
|
||||
(:import [java.util UUID]))
|
||||
(:import
|
||||
[java.util UUID]))
|
||||
|
||||
|
||||
;; TODO make more reusable malli schemas, use unions if it would be helpful
|
||||
@@ -292,7 +295,7 @@
|
||||
|
||||
|
||||
|
||||
(def bank-account-schema [:map
|
||||
(def bank-account-schema [:and [:map
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:bank-account/name :string]
|
||||
[:bank-account/code :string]
|
||||
@@ -324,7 +327,15 @@
|
||||
(if (string? m)
|
||||
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
||||
m))}
|
||||
inst?]]])
|
||||
inst?]]]
|
||||
[:fn {:error/message "Bank account financial code is required if the 'Include in Reports?' flag is true."
|
||||
:error/path [:bank-account/numeric-code]}
|
||||
(fn [{:bank-account/keys [include-in-reports numeric-code] :as g}]
|
||||
(cond
|
||||
(and include-in-reports (not numeric-code))
|
||||
false
|
||||
:else
|
||||
true))]])
|
||||
|
||||
(def form-schema-2 (mc/schema
|
||||
[:map
|
||||
@@ -369,7 +380,10 @@
|
||||
[:square-location/client-location :string])]]
|
||||
|
||||
[:client/bank-accounts {:default []}
|
||||
[:maybe (many-entity {}
|
||||
[:maybe (many-entity-custom {}
|
||||
[:and
|
||||
[:map
|
||||
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:bank-account/name :string]
|
||||
|
||||
@@ -401,7 +415,15 @@
|
||||
(if (string? m)
|
||||
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
||||
m))}
|
||||
inst?]])]]
|
||||
inst?]]]
|
||||
[:fn {:error/message "Bank account financial code is required if the 'Include in Reports?' flag is true."
|
||||
:error/path [:bank-account/numeric-code]}
|
||||
(fn [{:bank-account/keys [include-in-reports numeric-code] :as g}]
|
||||
(cond
|
||||
(and include-in-reports (not numeric-code))
|
||||
false
|
||||
:else
|
||||
true))]])]]
|
||||
[:client/matches {:optional true :default []} [:vector {:decode/arbitrary (fn [m] (if (map? m)
|
||||
(vals m)
|
||||
m))}
|
||||
|
||||
@@ -163,6 +163,15 @@
|
||||
x
|
||||
[x]))})
|
||||
(into [:map] keys)]))
|
||||
(defn many-entity-custom [params schema]
|
||||
(mc/schema
|
||||
[:vector (merge params {:decode/json map->db-id-decoder
|
||||
:decode/arbitrary (fn [x]
|
||||
(if (sequential? x)
|
||||
x
|
||||
[x]))})
|
||||
schema]))
|
||||
|
||||
|
||||
(defn str->keyword [s]
|
||||
(if (string? s)
|
||||
|
||||
Reference in New Issue
Block a user