Files
dougal-software/lib/www/server/lib/db/configuration/get.js
2025-08-06 10:41:42 +02:00

21 lines
536 B
JavaScript

const { setSurvey, pool } = require('../connection');
async function get (projectId, path, opts = {}) {
const text = `SELECT meta data FROM public.projects WHERE pid = $1;`;
const res = await pool.query(text, [projectId]);
const config = res.rows.length == 1
? res.rows[0].data
: res.rows.map(r => r.data);
if (path) {
return path.split('/').filter(i => i !== "").reduce( (obj, idx) =>
(typeof obj !== 'undefined' && obj !== null) ? obj[idx] : undefined, config);
} else {
return config;
}
}
module.exports = get;