How to use the @reactioncommerce/api-utils/arrayJoinPlusRemainingQuery.js function in @reactioncommerce/api-utils

To help you get started, we’ve selected a few @reactioncommerce/api-utils 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 reactioncommerce / reaction / imports / node-app / core-services / tags / queries / productsByTagId.js View on Github external
export default async function productsByTagId(context, params) {
  const { connectionArgs, shopId, tagId } = params;
  const { collections, userHasPermission } = context;
  const { Products, Tags } = collections;

  // Check for owner or admin permissions from the user before allowing the query
  if (!userHasPermission(["owner", "admin", "tag/admin", "tag/edit"], shopId)) {
    throw new ReactionError("access-denied", "User does not have permission");
  }

  return arrayJoinPlusRemainingQuery({
    arrayFieldPath: "featuredProductIds",
    collection: Tags,
    connectionArgs,
    joinCollection: Products,
    joinFieldPath: "_id",
    joinSelector: { hashtags: tagId, shopId },
    joinSortOrder: "asc",
    positionFieldName: "position",
    selector: { _id: tagId },
    sortByForRemainingDocs: "createdAt",
    sortOrderForRemainingDocs: "asc"
  });
}
github reactioncommerce / reaction / src / core-services / tags / queries / productsByTagId.js View on Github external
export default async function productsByTagId(context, params) {
  const { connectionArgs, shopId, tagId } = params;
  const { checkPermissions, collections } = context;
  const { Products, Tags } = collections;

  // Check for owner or admin permissions from the user before allowing the query
  await checkPermissions(["owner", "admin", "tag/admin", "tag/edit"], shopId);

  return arrayJoinPlusRemainingQuery({
    arrayFieldPath: "featuredProductIds",
    collection: Tags,
    connectionArgs,
    joinCollection: Products,
    joinFieldPath: "_id",
    joinSelector: { hashtags: tagId, shopId },
    joinSortOrder: "asc",
    positionFieldName: "position",
    selector: { _id: tagId },
    sortByForRemainingDocs: "createdAt",
    sortOrderForRemainingDocs: "asc"
  });
}
github reactioncommerce / reaction / imports / node-app / core-services / catalog / queries / catalogItemsAggregate.js View on Github external
const { Catalog, Tags } = collections;

  if (!tagId) throw new ReactionError("invalid-param", "You must provide a tagId");

  const selector = {
    "product.tagIds": tagId,
    "product.isDeleted": { $ne: true },
    "product.isVisible": true,
    ...catalogBooleanFilters
  };

  if (shopIds && shopIds.length > 0) {
    selector.shopId = { $in: shopIds };
  }

  return arrayJoinPlusRemainingQuery({
    arrayFieldPath: "featuredProductIds",
    collection: Tags,
    connectionArgs,
    joinCollection: Catalog,
    joinFieldPath: "product.productId",
    joinSelector: selector,
    joinSortOrder: "asc",
    positionFieldName: "position",
    selector: { _id: tagId },
    sortByForRemainingDocs: "createdAt",
    sortOrderForRemainingDocs: "asc"
  });
}