How to use the loopback-datasource-juggler/lib/utils.mergeQuery function in loopback-datasource-juggler

To help you get started, we’ve selected a few loopback-datasource-juggler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EdgeVerve / oe-cloud / common / mixins / data-personalization-mixin.js View on Github external
}
      });

      andParams.push({
        and: manualAnd
      });
    }
    finalQuery = {
      where: {
        and: andParams
      }
    };
  }

  // Merging the query formed with the existing query if any.
  mergeQuery(ctx.query, finalQuery);
  log.debug(ctx.options, 'Final formed query', JSON.stringify(ctx.query));
  next();
}
github EdgeVerve / oe-cloud / common / mixins / data-hierarchy-mixin.js View on Github external
query[key] = regexObj;
      mergeQuery(ctx.query, {
        where: query
      });
    } else {
      for (let i = 0; i <= depth; i++) {
        query = {};
        if (i === 0) {
          modifiedRegex = `${regexString}$`;
        } else {
          modifiedRegex = `${modifiedRegex.substr(0, modifiedRegex.length - 1)}[[:alnum:]]*,$`;
        }
        query[key] = toRegExp(modifiedRegex);
        orParms.push(query);
      }
      mergeQuery(ctx.query, {
        where: {
          or: orParms
        }
      });
    }
  } else {
    if (depth === '*') {
      depth = regexString.split(',').length - 2;
    }
    for (let j = 0; j <= depth; j++) {
      query = {};
      if (j === 0) {
        modifiedRegex = `${regexString}$`;
      } else {
        const hierarchyArray = modifiedRegex.split(',');
        hierarchyArray.splice(hierarchyArray.length - 2, 1);
github EdgeVerve / oe-cloud / common / mixins / data-hierarchy-mixin.js View on Github external
for (let j = 0; j <= depth; j++) {
      query = {};
      if (j === 0) {
        modifiedRegex = `${regexString}$`;
      } else {
        const hierarchyArray = modifiedRegex.split(',');
        hierarchyArray.splice(hierarchyArray.length - 2, 1);
        modifiedRegex = hierarchyArray.join();
      }
      if (modifiedRegex === ',$' || modifiedRegex === '$') {
        break;
      }
      query[key] = toRegExp(modifiedRegex);
      orParms.push(query);
    }
    mergeQuery(ctx.query, {
      where: {
        or: orParms
      }
    });
  }
}
github EdgeVerve / oe-cloud / common / mixins / idempotent-mixin.js View on Github external
Model.checkIdempotencyForDelete = function modelCheckIdempotencyForDeletecb(context, cb) {
    var filter;
    if (context.id) {
      filter = { where: context.where, fetchDeleted: true };
      Model.findOne(filter, context.options, function modelFindOnecb(err, res) {
        if (err) {
          return cb(err);
        }
        if (res) {
          return cb(err, { count: 1 });
        }
        return cb();
      });
    } else if (context.options && context.options.requestId) {
      filter = { where: context.where, fetchDeleted: true };
      mergeQuery(filter, {
        where: {
          _requestId: context.options.requestId
        }
      });
      Model.find(filter, context.options, function modelFindcb(err, res) {
        if (err) {
          return cb(err);
        }
        if (res.length > 0) {
          return cb(err, { count: res.length });
        }
        return cb();
      });
    } else {
      return cb();
    }
github EdgeVerve / oe-cloud / common / models / framework / data-ACL.js View on Github external
Object.keys(filterUsed).forEach(function filterUsedForEach(group) {
          if (filterUsed[group].length === 1) {
            mergeQuery(filter, {
              'where': {
                'and': filterUsed[group]
              }
            });
          } else {
            mergeQuery(filter, {
              'where': {
                'or': filterUsed[group]
              }
            });
          }
        });
github EdgeVerve / oe-cloud / lib / service-personalizer.js View on Github external
function addLbFiltertoCtx(ctx, filter, cb) {
  ctx.args.filter = ctx.args.filter || {};
  mergeQuery(ctx.args.filter, filter);
  cb();
}
github EdgeVerve / oe-cloud / common / mixins / soft-delete-mixin.js View on Github external
function addSoftDeleteFilter(ctx, next) {
  if (!ctx.Model.settings._softDelete) {
    return next();
  }
  ctx.query = ctx.query || {};
  if (ctx.query.fetchDeleted) {
    mergeQuery(ctx.query, {
      where: {
        _isDeleted: true
      }
    });
  } else {
    mergeQuery(ctx.query, {
      where: {
        _isDeleted: false
      }
    });
  }
  next();
}