UNPKG

@opengis/fastify-table

Version:

core-plugins

24 lines (23 loc) 1.1 kB
import pgClients from "../../../plugins/pg/pgClients.js"; export default async function getAppSettings({ pg = pgClients.client, query, params, user = {}, }, reply) { const t1 = Date.now(); if (!pg) { return reply.status(500).send("empty pg"); } if (!pg.pk?.["admin.properties"]) { return reply.status(404).send("properties table not found"); } if (params?.entity === "user" && !user.uid) { return reply.status(401).send("unauthorized"); } const { uid } = user; const args = params?.entity === "user" ? [user.uid] : [params?.entity || "app"]; const { rows = [] } = await pg.query("select property_key as key, property_text, property_json from admin.properties where property_entity=$1", args); const settings = rows .filter((row) => typeof query?.keys === "string" ? query.keys.includes(row.key) : true) .reduce((acc, { key, property_text, property_json }) => ({ ...acc, [key]: property_text || property_json, }), {}); return reply.status(200).send({ time: Date.now() - t1, uid, settings }); }