UNPKG

@opengis/fastify-table

Version:

core-plugins

26 lines (25 loc) 1.06 kB
import pgClients from "../../../plugins/pg/pgClients.js"; import getData from "../functions/getData.js"; export default async function tableData(req, reply, called) { const { user, params, headers, query, pg = pgClients.client } = req; // це можна від користувача const q = `select attr, (select rule_values from admin.account_grants where account_id in (select account_id from admin.account_users where user_uid=$2) and rule_id=r.rule_id limit 1) from admin.rules r where (select route_id from admin.routes where $1 in (alias,table_name)) = any(routes)`; const { rows = [] } = pg?.pk?.["admin.rules"] && user?.uid ? await pg.query(q, [params.table, user.uid]) : {}; const contextQuery = rows .filter((el) => el.rule_values) .map((el) => `${el.attr} = any ('{${el.rule_values}}')`) .join(" and "); const res = await getData({ pg, params, query, headers, user, contextQuery, }, reply, called); return res; }