mirror of
https://github.com/penpot/penpot.git
synced 2026-09-13 23:48:42 +00:00
✨ Add transactions support on management api
This commit is contained in:
parent
6c8873c7f5
commit
5fed5fa158
@ -29,19 +29,40 @@
|
|||||||
[_ params]
|
[_ params]
|
||||||
(assert (db/pool? (::db/pool params)) "expect valid database pool"))
|
(assert (db/pool? (::db/pool params)) "expect valid database pool"))
|
||||||
|
|
||||||
|
(def ^:private default-system
|
||||||
|
{:name ::default-system
|
||||||
|
:compile
|
||||||
|
(fn [_ _]
|
||||||
|
(fn [handler cfg]
|
||||||
|
(fn [request]
|
||||||
|
(handler cfg request))))})
|
||||||
|
|
||||||
|
(def ^:private transaction
|
||||||
|
{:name ::transaction
|
||||||
|
:compile
|
||||||
|
(fn [data _]
|
||||||
|
(when (:transaction data)
|
||||||
|
(fn [handler]
|
||||||
|
(fn [cfg request]
|
||||||
|
(db/tx-run! cfg handler request)))))})
|
||||||
|
|
||||||
(defmethod ig/init-key ::routes
|
(defmethod ig/init-key ::routes
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
[["/authenticate"
|
["" {:middleware [[default-system cfg]
|
||||||
{:handler (partial authenticate cfg)
|
[transaction]]}
|
||||||
|
["/authenticate"
|
||||||
|
{:handler authenticate
|
||||||
:allowed-methods #{:post}}]
|
:allowed-methods #{:post}}]
|
||||||
|
|
||||||
["/get-customer"
|
["/get-customer"
|
||||||
{:handler (partial get-customer cfg)
|
{:handler get-customer
|
||||||
|
:transaction true
|
||||||
:allowed-methods #{:post}}]
|
:allowed-methods #{:post}}]
|
||||||
|
|
||||||
["/update-customer"
|
["/update-customer"
|
||||||
{:handler (partial update-customer cfg)
|
{:handler update-customer
|
||||||
:allowed-methods #{:post}}]])
|
:allowed-methods #{:post}
|
||||||
|
:transaction true}]])
|
||||||
|
|
||||||
;; ---- HELPERS
|
;; ---- HELPERS
|
||||||
|
|
||||||
@ -192,7 +213,7 @@
|
|||||||
(-> request :params coerce-update-customer-params)
|
(-> request :params coerce-update-customer-params)
|
||||||
|
|
||||||
{:keys [props] :as profile}
|
{:keys [props] :as profile}
|
||||||
(cmd.profile/get-profile cfg id)
|
(cmd.profile/get-profile cfg id ::db/for-update true)
|
||||||
|
|
||||||
props
|
props
|
||||||
(assoc props :subscription subscription)]
|
(assoc props :subscription subscription)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user