User can set up sales queries on their own now.
This commit is contained in:
@@ -40,13 +40,12 @@
|
||||
:user/name (:name profile)})
|
||||
]
|
||||
(log/info "authenticated as user" user)
|
||||
|
||||
;; TODO - these namespaces are not being transmitted/deserialized properly
|
||||
(if (and token user)
|
||||
(let [jwt (jwt/sign {:user (:name profile)
|
||||
:exp (time/plus (time/now) (time/days 30))
|
||||
:user/clients (map (fn [c]
|
||||
(dissoc c :client/bank-accounts :client/location-matches :client/forecasted-transactions :client/matches :client/week-a-debits :client/week-a-credits :client/week-b-debits :client/week-b-credits :client/signature-file :client/address :client/emails :client/square-auth-token :client/square-locations))
|
||||
(select-keys c [:client/code :db/id :client/name :client/locations]))
|
||||
(:user/clients user))
|
||||
:user/role (name (:user/role user))
|
||||
:user/name (:name profile)}
|
||||
|
||||
@@ -41,17 +41,27 @@
|
||||
(into [(d/db conn)] (clojure.edn/read-string (get query-params "args" "[]")))))))))
|
||||
|
||||
|
||||
(defn put-query [id body note]
|
||||
(s3/put-object :bucket-name (:data-bucket env)
|
||||
:key (str "queries/" id)
|
||||
:input-stream (io/make-input-stream (.getBytes body) {})
|
||||
:metadata {:content-type "application/text"
|
||||
:user-metadata {:note note}})
|
||||
{:body {:query body
|
||||
:id id
|
||||
:results-url (str "/api/queries/" id "/results")
|
||||
:csv-results-url (str "/api/queries/" id "/results/csv")
|
||||
:json-results-url (str "/api/queries/" id "/results/json")}})
|
||||
(defn put-query [guid body note & [lookup-key client]]
|
||||
(let [guid (if lookup-key
|
||||
(or (:saved-query/guid (d/pull (d/db conn) [:saved-query/guid] [:saved-query/lookup-key lookup-key]))
|
||||
guid)
|
||||
guid)]
|
||||
@(d/transact conn [(cond->
|
||||
{:saved-query/guid guid
|
||||
:saved-query/description note
|
||||
:saved-query/key (str "queries/" guid)}
|
||||
client (assoc :saved-query/client client)
|
||||
lookup-key (assoc :saved-query/lookup-key lookup-key))])
|
||||
(s3/put-object :bucket-name (:data-bucket env)
|
||||
:key (str "queries/" guid)
|
||||
:input-stream (io/make-input-stream (.getBytes body) {})
|
||||
:metadata {:content-type "application/text"
|
||||
:user-metadata {:note note}})
|
||||
{:body {:query body
|
||||
:id guid
|
||||
:results-url (str "/api/queries/" guid "/results")
|
||||
:csv-results-url (str "/api/queries/" guid "/results/csv")
|
||||
:json-results-url (str "/api/queries/" guid "/results/json")}}))
|
||||
|
||||
(def json-routes
|
||||
(context "/queries" []
|
||||
|
||||
Reference in New Issue
Block a user