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