enforce locked until for payments

This commit is contained in:
Bryce Covert
2022-03-14 10:43:38 -07:00
parent ab4a426369
commit ee6669253f
4 changed files with 42 additions and 12 deletions

View File

@@ -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)))