All files / realm/blong-access/adapter/db accessAclFind.ts

76.19% Statements 16/21
100% Branches 1/1
0% Functions 0/1
76.19% Lines 16/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 221x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x           7x  
import {type IMeta, handler} from '@feasibleone/blong';
 
import * as model from './accessModel.ts';
 
type KnexQb = any;
 
/**
 * `access.acl.find` — the ACL rule list with the principal, action and target
 * names joined in, so the exceptions page is readable without an extra lookup
 * per row.  The row shape itself comes from the generic CRUD (`super.exec`); the
 * names are virtual fields resolved here (`${principal}Name`, `actionName`,
 * `${target}Name`).
 */
export default handler(() => ({
    async accessAclFind(params: Record<string, unknown>, $meta: IMeta): Promise<unknown> {
        const qb: KnexQb = this.config?.context?.queryBuilder;
        if (!qb) throw new Error('Database not available');
        const rows = (await super.exec(params, $meta)) as Array<Record<string, unknown>>;
        return model.attachAclNames(qb, rows);
    },
}));