UNPKG

@opengis/bi

Version:

BI data visualization module

41 lines (32 loc) 1.33 kB
import { pgClients, getTemplatePath, getTemplate } from '@opengis/fastify-table/utils.js'; const q = `select dashboard_id as name, 'db' as type, title, description, table_name, words, public from bi.dashboard`; export default async function data({ pg = pgClients.client, query = {}, user = {} }) { const time = Date.now(); const { type = 'file' } = query; const data = getTemplatePath('dashboard'); const dir = type === 'file' ? await Promise.all( data.map(async ([filename, filepath]) => { const obj = await getTemplate('dashboard', filename); const index = obj?.find?.((el) => el[0] === 'index.yml')?.[1]; const { table_name, description, title } = index || {}; return { name: filename, path: user?.user_type?.includes('admin') ? filepath : undefined, type: 'file', title, description, table_name }; }) ) : []; const { rows = [] } = ['db', 'viewer'].includes(type) ? await pg.query(q) : {}; if (type === 'viewer') { return { time: Date.now() - time, db: pg.options?.database, rows: rows.filter(el => el.table_name && !el.table_name.startsWith('demo.')), }; } const list = dir.concat(rows); const res = { time: Date.now() - time, db: pg.options?.database, rows: list, }; return res; }