@opengis/bi
Version:
BI data visualization module
44 lines (34 loc) • 1.08 kB
JavaScript
import {
config, getToken, dataUpdate, pgClients,
} from '@opengis/fastify-table/utils.js';
import datasetForms from '../utils/datasetForms.js';
export default async function datasetDataUpdate({
pg = pgClients.client, params = {}, body = {}, user = {},
}) {
if (!user?.uid) {
return { message: 'access restricted', status: 403 };
}
const tokenData = await getToken({
uid: user?.uid,
token: params.id,
mode: 'a',
json: 1,
});
if (!tokenData && !config.local && !config.debug) {
return { message: 'token not allow', status: 403 };
}
const dataset = await pg.query('select dataset_id as id, table_name as table from bi.dataset where dataset_id=$1', [tokenData?.dataset || params.id])
.then(el => el.rows[0] || {});
const table = tokenData?.table || dataset.table;
if (!dataset.id || !datasetForms[dataset.id]) {
return { message: 'dataset not found', status: 404 };
}
const res = await dataUpdate({
pg,
id: tokenData?.id || params?.object_id,
table,
data: body,
uid: user?.uid,
});
return res;
}