UNPKG

@opengis/admin

Version:

This project Softpro Admin

30 lines (23 loc) 1.07 kB
import { pgClients } from '@opengis/fastify-table/utils.js'; import { getAdminAccess } from '../../../../utils.js'; export default async function accessGroup({ pg = pgClients.client, params = {}, session = {}, }) { const { user = {} } = session?.passport || {}; if (!params?.id) { return { message: 'not enough params: id', status: 400 }; } // restrict access - admin only const check = await getAdminAccess({ id: params.id, user, }); if (check) return check; const { rows: routes = [] } = await pg.query(`select a.route_id as path, b.actions from admin.routes a left join admin.role_access b on a.route_id=b.route_id where b.role_id=$1`, [params.id]); const { rows: users = [] } = await pg.query(`select user_uid as id, user_name as name, access_granted, b.cdate as user_created, b.last_activity_date as last_activity from admin.user_roles a left join admin.users b on a.user_uid=b.uid where a.role_id=$1`, [params.id]); return { routes, users }; }