All files / lib/utils getFieldsQueryFor.ts

88.89% Statements 8/9
75% Branches 3/4
100% Functions 1/1
87.5% Lines 7/8

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      1x     1x 55x 55x 15x     15x     1x
import { AnyAbility, Subject } from "@casl/ability";
import { Query } from "@feathersjs/feathers";
import { GetFieldsQueryOptions } from "../types";
import hasRestrictingFields from "./hasRestrictingFields";
 
// eslint-disable-next-line no-unused-vars
const getFieldsQueryFor = (ability: AnyAbility, action: string, subject: Subject, options?: GetFieldsQueryOptions): Query => {
  const fields = hasRestrictingFields(ability, action, subject, options);
  if (!fields) { return {}; }
  Iif (fields === true) { 
    return { $select: [] }; 
  }
  return { $select: fields };
};
 
export default getFieldsQueryFor;