@opengis/bi
Version:
BI data visualization module
37 lines (31 loc) • 908 B
JavaScript
import { pgClients, dataInsert, getPGAsync } from "@opengis/fastify-table/utils.js";
export default async function dashboardAdd(req, reply) {
const {
pg = pgClients.client,
body = {},
} = req;
const time = Date.now();
if (body?.db) {
try {
const pg1 = await getPGAsync(body.db);
await pg1.query('select 1');
} catch (err) {
return reply.status(400).send('Некоректна база даних');
}
}
const res = await dataInsert({
pg,
table: 'bi.dashboard',
data: body,
}).then(el => el.rows?.[0] || {});
if (res.dashboard_id && body.dataset) {
await pg.query(`update bi.dataset set dashboard_list=coalesce(dashboard_list, '{}'::text[]) || array[$1]
where dataset_id=$2`, [res.dashboard_id, body.dataset]);
}
return {
time: Date.now() - time,
id: res.dashboard_id,
title: res.title,
name: res.name,
};
}