From f1b2671d90a8e8470ca1d02f83b12a4439d86747 Mon Sep 17 00:00:00 2001 From: "D. Berge" Date: Tue, 11 Aug 2020 19:35:13 +0200 Subject: [PATCH] Project summary: paginate results --- lib/www/server/lib/db/project.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/www/server/lib/db/project.js b/lib/www/server/lib/db/project.js index acbda29..d57cb4a 100644 --- a/lib/www/server/lib/db/project.js +++ b/lib/www/server/lib/db/project.js @@ -8,6 +8,16 @@ async function list () { async function summary (projectId, opts = {}) { await pool.query("CALL set_survey($1);", [projectId]); + + const sortFields = [ + "pid", "name", "lines", "sequences", "unique_shots", + "total_shots", "info" + ]; + const sortKey = opts.sortBy && sortFields.includes(opts.sortBy) && opts.sortBy || "pid"; + const sortDir = opts.sortDesc == "true" ? "DESC" : "ASC"; + const offset = Math.abs((opts.page-1)*opts.itemsPerPage) || 0; + const limit = Math.abs(Number(opts.itemsPerPage)) || null; + // FIXME Make this into a PostgreSQL stored procedure const text = ` SELECT * FROM projects,