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

61.9% Statements 13/21
100% Branches 1/1
0% Functions 0/1
61.9% Lines 13/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 7x                 7x  
import {type IMeta, handler} from '@feasibleone/blong';
 
import * as model from './accessModel.ts';
 
type KnexQb = any;
 
/**
 * `access.acl.get` — one ACL rule (the generic CRUD row) with the principal,
 * action and target names joined in, so the editor shows what the ids mean.
 */
export default handler(() => ({
    async accessAclGet(params: {aclId?: string}, $meta: IMeta): Promise<Record<string, unknown>> {
        const qb: KnexQb = this.config?.context?.queryBuilder;
        if (!qb) throw new Error('Database not available');
        const result = (await super.exec(params, $meta)) as Record<string, unknown>;
        const rows = await model.attachAclNames(qb, [
            (result.acl ?? {}) as Record<string, unknown>,
        ]);
        return {acl: rows[0]};
    },
}));