From 8c223b9fb86ae0be6203e903511105dfa9682dcf Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 7 Jun 2021 10:56:21 +0200 Subject: [PATCH] :sparkles: Allow future dates on get-by-params method. --- backend/src/app/db.clj | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/src/app/db.clj b/backend/src/app/db.clj index 6527fa2a8d..2b98c5e31f 100644 --- a/backend/src/app/db.clj +++ b/backend/src/app/db.clj @@ -221,14 +221,20 @@ (sql/delete table params opts) (assoc opts :return-keys true)))) +(defn- is-deleted? + [{:keys [deleted-at]}] + (and (dt/instant? deleted-at) + (< (inst-ms deleted-at) + (inst-ms (dt/now))))) + (defn get-by-params ([ds table params] (get-by-params ds table params nil)) ([ds table params {:keys [uncheked] :or {uncheked false} :as opts}] (let [res (exec-one! ds (sql/select table params opts))] - (when (and (not uncheked) - (or (:deleted-at res) (not res))) + (when (and (not uncheked) (or (not res) (is-deleted? res))) (ex/raise :type :not-found + :table table :hint "database object not found")) res)))