0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

🎉 Add :project-file query.

This commit is contained in:
Andrey Antukh 2019-12-10 21:49:19 +01:00
parent 94fe18b4ae
commit 932d5bb004

View file

@ -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