🎉 Add get-customer-prfile prepl rpc method

This commit is contained in:
Andrey Antukh 2025-04-15 16:21:57 +02:00
parent 952ab032f9
commit 5db5bc65de

View file

@ -9,6 +9,7 @@
(:require (:require
[app.auth :as auth] [app.auth :as auth]
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.schema :as sm]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.db :as db] [app.db :as db]
[app.rpc.commands.auth :as cmd.auth] [app.rpc.commands.auth :as cmd.auth]
@ -18,6 +19,13 @@
[app.util.time :as dt] [app.util.time :as dt]
[cuerdas.core :as str])) [cuerdas.core :as str]))
(defn coercer
[schema & {:as opts}]
(let [decode-fn (sm/decoder schema sm/json-transformer)
check-fn (sm/check-fn schema opts)]
(fn [data]
(-> data decode-fn check-fn))))
(defn- get-current-system (defn- get-current-system
[] []
(or (deref (requiring-resolve 'app.main/system)) (or (deref (requiring-resolve 'app.main/system))
@ -25,6 +33,12 @@
(defmulti ^:private exec-command ::cmd) (defmulti ^:private exec-command ::cmd)
(defmethod exec-command :default
[{:keys [::cmd]}]
(ex/raise :type :internal
:code :not-implemented
:hint (str/ffmt "command '%' not implemented" cmd)))
(defn exec (defn exec
"Entry point with external tools integrations that uses PREPL "Entry point with external tools integrations that uses PREPL
interface for interacting with running penpot backend." interface for interacting with running penpot backend."
@ -117,8 +131,20 @@
(let [props (get system ::setup/props)] (let [props (get system ::setup/props)]
(tokens/verify props {:token token :iss "authentication"})))) (tokens/verify props {:token token :iss "authentication"}))))
(defmethod exec-command :default (def ^:private schema:get-customer
[{:keys [::cmd]}] [:map [:id ::sm/uuid]])
(ex/raise :type :internal
:code :not-implemented (def coerce-get-customer-params
:hint (str/ffmt "command '%' not implemented" cmd))) (coercer schema:get-customer
:type :validation
:hint "invalid data provided for `get-customer` rpc call"))
(defmethod exec-command "get-customer"
[params]
(when-let [system (get-current-system)]
(let [{:keys [id] :as params} (coerce-get-customer-params params)
{:keys [props] :as profile} (cmd.profile/get-profile system id)]
{:id (get profile :id)
:name (get profile :fullname)
:email (get profile :email)
:subscription (get props :subscription)})))