enforce locked until for payments
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
(ns auto-ap.graphql.utils
|
||||
(:require [clojure.string :as str]
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[auto-ap.time :as atime]
|
||||
[buddy.auth :refer [throw-unauthorized]]
|
||||
[datomic.api :as d]
|
||||
[clojure.walk :as walk]
|
||||
[clojure.tools.logging :as log]))
|
||||
|
||||
@@ -106,3 +110,16 @@
|
||||
|
||||
(defn enum->keyword [e namespace]
|
||||
(some->> e name snake->kebab (keyword namespace)))
|
||||
|
||||
(defn get-locked-until [client-id]
|
||||
(:client/locked-until (d/pull (d/db conn) [:client/locked-until] client-id)))
|
||||
|
||||
(defn assert-not-locked [client-id date]
|
||||
(let [locked-until (get-locked-until client-id)]
|
||||
(when (and locked-until
|
||||
(>= (compare locked-until (coerce/to-date date)) 0))
|
||||
(assert-failure (str "Integreat has locked finances prior to " (-> locked-until coerce/to-date-time (atime/unparse-local atime/normal-date)) ".")))))
|
||||
|
||||
(defn assert-none-locked [client-id dates]
|
||||
(doseq [d dates]
|
||||
(assert-not-locked client-id d)))
|
||||
|
||||
Reference in New Issue
Block a user