From 932d5bb00400ef24de13ab12a4d56ea1ba53aaee Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 10 Dec 2019 21:49:19 +0100 Subject: [PATCH] :tada: Add :project-file query. --- .../uxbox/services/queries/project_files.clj | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/src/uxbox/services/queries/project_files.clj b/backend/src/uxbox/services/queries/project_files.clj index 1e3effa59..5666e54fa 100644 --- a/backend/src/uxbox/services/queries/project_files.clj +++ b/backend/src/uxbox/services/queries/project_files.clj @@ -22,9 +22,7 @@ (s/def ::project-id ::us/uuid) (s/def ::user ::us/uuid) -;; --- Query: Project Files - -(def ^:private sql:project-files +(def ^:private sql:generic-project-files "select pf.*, array_agg(pp.id) as pages from project_files as pf @@ -32,10 +30,15 @@ inner join project_users as pu on (p.id = pu.project_id) left join project_pages as pp on (pf.id = pp.file_id) where pu.user_id = $1 - and pu.project_id = $2 and pu.can_edit = true group by pf.id - order by pf.created_at asc;") + order by pf.created_at asc") + +;; --- Query: Project Files + +(def ^:private sql:project-files + (str "with files as (" sql:generic-project-files ")" + " select * from files where project_id = $2")) (s/def ::project-files (s/keys :req-un [::user ::project-id])) @@ -45,6 +48,20 @@ (-> (db/query db/pool [sql:project-files user project-id]) (p/then' (partial mapv decode-row)))) +;; --- Query: Project File (By ID) + +(def ^:private sql:project-file + (str "with files as (" sql:generic-project-files ")" + " select * from files where id = $2")) + +(s/def ::project-file + (s/keys :req-un [::user ::id])) + +(sq/defquery ::project-file + [{:keys [user id] :as params}] + (-> (db/query-one db/pool [sql:project-file user id]) + (p/then' decode-row))) + ;; --- Helpers (defn decode-row