mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:27:08 +00:00
Adapt db.events.list to latest schema
This commit is contained in:
@@ -3,8 +3,8 @@ const { setSurvey } = require('../connection');
|
||||
async function list (projectId, opts = {}) {
|
||||
const client = await setSurvey(projectId);
|
||||
|
||||
const sortFields = [ "sequence", "shot_number", "ts0", "ts1", "label", "remarks" ];
|
||||
const sortKey = opts.sortBy && sortFields.includes(opts.sortBy) && opts.sortBy || "ts0";
|
||||
const sortFields = [ "sequence", "point", "tstamp", "remarks" ];
|
||||
const sortKey = opts.sortBy && sortFields.includes(opts.sortBy) && opts.sortBy || "tstamp";
|
||||
const sortDir = (opts.sortDesc == "true" || !opts.sortDesc) ? "DESC" : "ASC";
|
||||
const offset = Math.abs((opts.page-1)*opts.itemsPerPage) || 0;
|
||||
const limit = Math.abs(Number(opts.itemsPerPage)) || null;
|
||||
@@ -15,13 +15,14 @@ async function list (projectId, opts = {}) {
|
||||
: [ "sequence = $1", [ opts.sequence ] ]
|
||||
: opts.date0
|
||||
? opts.date1
|
||||
? [ "date(ts0) BETWEEN SYMMETRIC $1 AND $2", [ opts.date0, opts.date1 ] ]
|
||||
: [ "date(ts0) = $1", [ opts.date0 ] ]
|
||||
? [ "date(tstamp) BETWEEN SYMMETRIC $1 AND $2", [ opts.date0, opts.date1 ] ]
|
||||
: [ "date(tstamp) = $1", [ opts.date0 ] ]
|
||||
: [ "true = true", [] ];
|
||||
|
||||
const text = `
|
||||
SELECT *
|
||||
FROM events
|
||||
SELECT *,
|
||||
array(SELECT label FROM events_labels l WHERE l.type = e.type AND l.id = e.id) labels
|
||||
FROM events e
|
||||
WHERE
|
||||
${filter[0]}
|
||||
ORDER BY ${sortKey} ${sortDir};
|
||||
|
||||
Reference in New Issue
Block a user