started working on validation on action form.

This commit is contained in:
Bryce Covert
2018-05-23 12:07:51 -07:00
parent a3762a76af
commit 0611c169c7
6 changed files with 51 additions and 8 deletions

View File

@@ -1,15 +1,13 @@
(ns auto-ap.entities.companies
(:require [clojure.spec.alpha :as s]
[auto-ap.entities.shared :as shared]
[clojure.string :as str]
[auto-ap.entities.address :as address]))
(def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$")
(s/def ::id int)
(s/def ::identifier (s/nilable string?))
(s/def ::required-identifier (s/and string?
#(not (str/blank? %))))
(s/def ::name ::required-identifier)
(s/def ::name ::shared/required-identifier)
(s/def ::address ::address/address)
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)

View File

@@ -0,0 +1,16 @@
(ns auto-ap.entities.invoice
(:require [clojure.spec.alpha :as s]
[auto-ap.entities.shared :as shared]))
(s/def ::vendor-id int?)
(s/def ::company-id int?)
(s/def ::invoice-number ::shared/required-identifier)
(s/def ::date ::shared/date)
(s/def ::total ::shared/money)
(s/def ::invoice (s/keys :opt-un [::vendor-id
::company-id
::invoice-number
::date
::total
]))

View File

@@ -0,0 +1,14 @@
(ns auto-ap.entities.shared
(:require [clojure.spec.alpha :as s]
[clojure.string :as str]))
(def date-regex #"[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}")
(def money-regex #"[0-9]+(\.[0-9]{1,2})?$")
(s/def ::identifier (s/nilable string?))
(s/def ::date (s/and string? #(re-matches date-regex %)))
(s/def ::required-identifier (s/and string?
#(not (str/blank? %))))
(s/def ::money (s/and string?
#(re-matches money-regex %)))