@opengis/bi
Version:
BI data visualization module
41 lines (32 loc) • 1.03 kB
JavaScript
import {
config, getToken, dataDelete, pgClients,
} from '@opengis/fastify-table/utils.js';
export default async function datasetDataDelete({
pg = pgClients.client, params = {}, 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) {
return { message: 'dataset not found', status: 404 };
}
const res = await dataDelete({
pg,
id: tokenData?.id || params?.object_id,
table,
uid: user?.uid,
});
return { rowCount: res.rowCount, msg: !res.rowCount ? res : null };
}