Prevents bad bank account
This commit is contained in:
@@ -1,48 +1,51 @@
|
||||
(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]]
|
||||
[auto-ap.graphql.utils :refer [extract-client-ids]]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.query-params :refer [wrap-copy-qp-pqp]]
|
||||
[auto-ap.routes.admin.clients :as route]
|
||||
[auto-ap.routes.indicators :as indicators]
|
||||
[auto-ap.routes.queries :as q]
|
||||
[auto-ap.routes.utils
|
||||
[auto-ap.graphql.utils :refer [extract-client-ids]]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.query-params :refer [wrap-copy-qp-pqp]]
|
||||
[auto-ap.routes.admin.clients :as route]
|
||||
[auto-ap.routes.indicators :as indicators]
|
||||
[auto-ap.routes.queries :as q]
|
||||
[auto-ap.routes.utils
|
||||
:refer [wrap-admin wrap-client-redirect-unauthenticated]]
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.square.core3 :as square]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.common-handlers :refer [add-new-entity-handler
|
||||
add-new-primitive-handler]]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.components.multi-modal :as mm]
|
||||
[auto-ap.ssr.form-cursor :as fc]
|
||||
[auto-ap.ssr.grid-page-helper :as helper :refer [wrap-apply-sort]]
|
||||
[auto-ap.ssr.hiccup-helper :as hh]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
[auto-ap.ssr.indicators :as i]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.utils
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.square.core3 :as square]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.common-handlers :refer [add-new-entity-handler
|
||||
add-new-primitive-handler]]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.components.multi-modal :as mm]
|
||||
[auto-ap.ssr.form-cursor :as fc]
|
||||
[auto-ap.ssr.grid-page-helper :as helper :refer [wrap-apply-sort]]
|
||||
[auto-ap.ssr.hiccup-helper :as hh]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
[auto-ap.ssr.indicators :as i]
|
||||
[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]]
|
||||
[auto-ap.time :as atime]
|
||||
[bidi.bidi :as bidi]
|
||||
[cheshire.core :as cheshire]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as dc]
|
||||
[hiccup.util :as hu]
|
||||
[malli.core :as mc]
|
||||
[malli.transform :as mt]
|
||||
[malli.util :as mut]
|
||||
[manifold.deferred :as de])
|
||||
(:import [java.util UUID]))
|
||||
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]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as dc]
|
||||
[hiccup.util :as hu]
|
||||
[malli.core :as mc]
|
||||
[malli.transform :as mt]
|
||||
[malli.util :as mut]
|
||||
[manifold.deferred :as de])
|
||||
(:import
|
||||
[java.util UUID]))
|
||||
|
||||
|
||||
;; TODO make more reusable malli schemas, use unions if it would be helpful
|
||||
@@ -292,39 +295,47 @@
|
||||
|
||||
|
||||
|
||||
(def bank-account-schema [:map
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:bank-account/name :string]
|
||||
[:bank-account/code :string]
|
||||
(def bank-account-schema [:and [:map
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:bank-account/name :string]
|
||||
[:bank-account/code :string]
|
||||
|
||||
[:bank-account/type [:maybe (ref->enum-schema "bank-account-type")]]
|
||||
[:bank-account/numeric-code {:optional true} [:maybe :int]]
|
||||
[:bank-account/check-number {:optional true} [:maybe :int]]
|
||||
[:bank-account/bank-name {:optional true} [:maybe :string]]
|
||||
[:bank-account/number {:optional true} [:maybe :string]]
|
||||
[:bank-account/routing {:optional true} [:maybe :string]]
|
||||
[:bank-account/bank-code {:optional true} [:maybe :string]]
|
||||
[:bank-account/sort-order {:default 0} [:maybe :int]]
|
||||
[:bank-account/yodlee-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/plaid-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/intuit-bank-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/include-in-reports {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
[:bank-account/type [:maybe (ref->enum-schema "bank-account-type")]]
|
||||
[:bank-account/numeric-code {:optional true} [:maybe :int]]
|
||||
[:bank-account/check-number {:optional true} [:maybe :int]]
|
||||
[:bank-account/bank-name {:optional true} [:maybe :string]]
|
||||
[:bank-account/number {:optional true} [:maybe :string]]
|
||||
[:bank-account/routing {:optional true} [:maybe :string]]
|
||||
[:bank-account/bank-code {:optional true} [:maybe :string]]
|
||||
[:bank-account/sort-order {:default 0} [:maybe :int]]
|
||||
[:bank-account/yodlee-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/plaid-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/intuit-bank-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/include-in-reports {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
|
||||
(boolean %))}}]]
|
||||
[:bank-account/visible {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
(boolean %))}}]]
|
||||
[:bank-account/visible {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
|
||||
(boolean %))}}]]
|
||||
[:bank-account/use-date-instead-of-post-date? {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
(boolean %))}}]]
|
||||
[:bank-account/use-date-instead-of-post-date? {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
|
||||
(boolean %))}}]]
|
||||
[:bank-account/start-date {:optional true} [:maybe {:decode/arbitrary (fn [m]
|
||||
(if (string? m)
|
||||
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
||||
m))}
|
||||
inst?]]])
|
||||
(boolean %))}}]]
|
||||
[:bank-account/start-date {:optional true} [:maybe {:decode/arbitrary (fn [m]
|
||||
(if (string? m)
|
||||
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
||||
m))}
|
||||
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,39 +380,50 @@
|
||||
[:square-location/client-location :string])]]
|
||||
|
||||
[:client/bank-accounts {:default []}
|
||||
[:maybe (many-entity {}
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:bank-account/name :string]
|
||||
|
||||
[:bank-account/code :string]
|
||||
[:bank-account/type [:maybe (ref->enum-schema "bank-account-type")]]
|
||||
[:bank-account/numeric-code {:optional true} [:maybe :int]]
|
||||
[:bank-account/sort-order {:default 0} [:maybe :int]]
|
||||
[:bank-account/routing {:optional true} [:maybe :string]]
|
||||
[:bank-account/bank-code {:optional true} [:maybe :string]]
|
||||
[:bank-account/bank-name {:optional true} [:maybe :string]]
|
||||
[:bank-account/number {:optional true} [:maybe :string]]
|
||||
[:bank-account/check-number {:optional true} [:maybe :int]]
|
||||
[:bank-account/yodlee-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/plaid-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/intuit-bank-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/include-in-reports {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
|
||||
(boolean %))}}]]
|
||||
[:bank-account/visible {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
|
||||
(boolean %))}}]]
|
||||
[:bank-account/use-date-instead-of-post-date? {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
|
||||
(boolean %))}}]]
|
||||
[:bank-account/start-date {:optional true} [:maybe {:decode/arbitrary (fn [m]
|
||||
(if (string? m)
|
||||
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
||||
m))}
|
||||
inst?]])]]
|
||||
[:maybe (many-entity-custom {}
|
||||
[:and
|
||||
[:map
|
||||
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:bank-account/name :string]
|
||||
|
||||
[:bank-account/code :string]
|
||||
[:bank-account/type [:maybe (ref->enum-schema "bank-account-type")]]
|
||||
[:bank-account/numeric-code {:optional true} [:maybe :int]]
|
||||
[:bank-account/sort-order {:default 0} [:maybe :int]]
|
||||
[:bank-account/routing {:optional true} [:maybe :string]]
|
||||
[:bank-account/bank-code {:optional true} [:maybe :string]]
|
||||
[:bank-account/bank-name {:optional true} [:maybe :string]]
|
||||
[:bank-account/number {:optional true} [:maybe :string]]
|
||||
[:bank-account/check-number {:optional true} [:maybe :int]]
|
||||
[:bank-account/yodlee-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/plaid-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/intuit-bank-account {:optional true} [:maybe entity-id]]
|
||||
[:bank-account/include-in-reports {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
|
||||
(boolean %))}}]]
|
||||
[:bank-account/visible {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
|
||||
(boolean %))}}]]
|
||||
[:bank-account/use-date-instead-of-post-date? {:default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true
|
||||
|
||||
(boolean %))}}]]
|
||||
[:bank-account/start-date {:optional true} [:maybe {:decode/arbitrary (fn [m]
|
||||
(if (string? m)
|
||||
(clj-time.coerce/to-date (auto-ap.time/parse m atime/normal-date))
|
||||
m))}
|
||||
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