Prevents bad bank account
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
(ns auto-ap.ssr.admin.clients
|
(ns auto-ap.ssr.admin.clients
|
||||||
(:require [auto-ap.datomic
|
(:require
|
||||||
|
[auto-ap.datomic
|
||||||
:refer [add-sorter-fields apply-pagination apply-sort-3
|
:refer [add-sorter-fields apply-pagination apply-sort-3
|
||||||
audit-transact conn merge-query pull-attr pull-id
|
audit-transact conn merge-query pull-attr pull-id
|
||||||
pull-many query2]]
|
pull-many query2]]
|
||||||
@@ -26,9 +27,10 @@
|
|||||||
[auto-ap.ssr.svg :as svg]
|
[auto-ap.ssr.svg :as svg]
|
||||||
[auto-ap.ssr.utils
|
[auto-ap.ssr.utils
|
||||||
:refer [apply-middleware-to-all-handlers entity-id
|
:refer [apply-middleware-to-all-handlers entity-id
|
||||||
form-validation-error html-response main-transformer
|
form-validation-error html-response many-entity
|
||||||
many-entity modal-response ref->enum-schema strip temp-id
|
many-entity-custom modal-response ref->enum-schema strip
|
||||||
wrap-entity wrap-schema-enforce wrap-merge-prior-hx]]
|
temp-id wrap-entity wrap-merge-prior-hx
|
||||||
|
wrap-schema-enforce]]
|
||||||
[auto-ap.time :as atime]
|
[auto-ap.time :as atime]
|
||||||
[bidi.bidi :as bidi]
|
[bidi.bidi :as bidi]
|
||||||
[cheshire.core :as cheshire]
|
[cheshire.core :as cheshire]
|
||||||
@@ -42,7 +44,8 @@
|
|||||||
[malli.transform :as mt]
|
[malli.transform :as mt]
|
||||||
[malli.util :as mut]
|
[malli.util :as mut]
|
||||||
[manifold.deferred :as de])
|
[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
|
;; 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]]
|
[:db/id [:or entity-id temp-id]]
|
||||||
[:bank-account/name :string]
|
[:bank-account/name :string]
|
||||||
[:bank-account/code :string]
|
[:bank-account/code :string]
|
||||||
@@ -324,7 +327,15 @@
|
|||||||
(if (string? m)
|
(if (string? m)
|
||||||
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
||||||
m))}
|
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
|
(def form-schema-2 (mc/schema
|
||||||
[:map
|
[:map
|
||||||
@@ -369,7 +380,10 @@
|
|||||||
[:square-location/client-location :string])]]
|
[:square-location/client-location :string])]]
|
||||||
|
|
||||||
[:client/bank-accounts {:default []}
|
[:client/bank-accounts {:default []}
|
||||||
[:maybe (many-entity {}
|
[:maybe (many-entity-custom {}
|
||||||
|
[:and
|
||||||
|
[:map
|
||||||
|
|
||||||
[:db/id [:or entity-id temp-id]]
|
[:db/id [:or entity-id temp-id]]
|
||||||
[:bank-account/name :string]
|
[:bank-account/name :string]
|
||||||
|
|
||||||
@@ -401,7 +415,15 @@
|
|||||||
(if (string? m)
|
(if (string? m)
|
||||||
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
||||||
m))}
|
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)
|
[:client/matches {:optional true :default []} [:vector {:decode/arbitrary (fn [m] (if (map? m)
|
||||||
(vals m)
|
(vals m)
|
||||||
m))}
|
m))}
|
||||||
|
|||||||
@@ -163,6 +163,15 @@
|
|||||||
x
|
x
|
||||||
[x]))})
|
[x]))})
|
||||||
(into [:map] keys)]))
|
(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]
|
(defn str->keyword [s]
|
||||||
(if (string? s)
|
(if (string? s)
|
||||||
|
|||||||
Reference in New Issue
Block a user