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