All files / lib/utils getQueryFor.ts

0% Statements 0/8
0% Branches 0/10
0% Functions 0/1
0% Lines 0/7

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 22 23 24 25 26 27 28 29 30 31 32 33                                                                 
import { mergeQuery } from "@artesa/feathers-utils";
 
import getFieldsQueryFor from "./getFieldsQueryFor";
import getConditionalQueryFor from "./getConditionalQueryFor";
 
import { Query } from "@feathersjs/feathers";
import { Ability } from "@casl/ability";
 
import {
  GetConditionalQueryOptions,
  GetQueryOptions 
} from "../types";
 
export default (
  ability: Ability, 
  method: string, 
  modelName: string, 
  options?: GetConditionalQueryOptions & GetQueryOptions
): Query => {
  options = options || {};
  const { skipConditional, skipFields } = options;
  if (skipConditional && skipFields) { return {}; }
  const condQuery = (!skipConditional) 
    ? getConditionalQueryFor(ability, method, modelName, { actionOnForbidden: options.actionOnForbidden })
    : {};
  const fieldsQuery = (!skipFields)
    ? getFieldsQueryFor(ability, method, modelName)
    : {};
 
  const query = mergeQuery(condQuery, fieldsQuery, { defaultHandle: "combine" });
  return query;
};