How to use @reactioncommerce/api-utils - 10 common examples

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 / tests / util / TestApp.js View on Github external
async setLoggedInUser(user = {}) {
    if (!user._id) throw new Error("setLoggedInUser: user must have _id property set");

    const { users } = this.reactionNodeApp.collections;

    const loginToken = Random.id();
    const hashedToken = hashToken(loginToken);

    const existing = await users.findOne({ _id: user._id });
    if (!existing) {
      await this.createUserAndAccount(user);
    }

    // Set the hashed login token on the users document
    await users.updateOne({ _id: user._id }, {
      $push: {
        "services.resume.loginTokens": {
          hashedToken,
          when: new Date()
        }
      }
    });
github reactioncommerce / reaction / imports / plugins / core / accounts / server / init.js View on Github external
if (user.emails[0] && user.emails[0].address.indexOf("localhost") > -1) {
      user.emails[0].verified = true;
      emailIsVerified = true;
    }

    // Set the first email to be the default
    if (user.emails[0]) {
      user.emails[0].provides = "default";
    }

    // create a tokenObj and send a welcome email to new users,
    // but skip the first default admin user and anonymous users
    // (default admins already get a verification email)
    let tokenObj;
    if (shopId && !emailIsVerified && user.emails[0]) {
      tokenObj = generateVerificationTokenObject({ address: user.emails[0].address });
    }

    // Get GraphQL context to pass to mutation
    // This is the only place in the app that still
    // uses `getGraphQLContextInMeteorMethod`
    // Prioritize removing if possible
    const context = Promise.await(getGraphQLContextInMeteorMethod(null));

    Promise.await(context.mutations.createAccount({ ...context, isInternalCall: true }, {
      emails: user.emails,
      name: user.name,
      profile,
      shopId,
      userId: user._id,
      verificationToken: tokenObj && tokenObj.token
    }));
github reactioncommerce / reaction / imports / node-app / core-services / account / resolvers / Query / groups.js View on Github external
export default async function groups(_, { shopId, ...connectionArgs }, context, info) {
  // Transform ID from base64
  const dbShopId = decodeShopOpaqueId(shopId);

  const query = await context.queries.groups(context, dbShopId);
  return getPaginatedResponse(query, connectionArgs, {
    includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info),
    includeHasPreviousPage: wasFieldRequested("pageInfo.hasPreviousPage", info),
    includeTotalCount: wasFieldRequested("totalCount", info)
  });
}
github reactioncommerce / reaction / imports / node-app / core-services / account / resolvers / Query / groups.js View on Github external
export default async function groups(_, { shopId, ...connectionArgs }, context, info) {
  // Transform ID from base64
  const dbShopId = decodeShopOpaqueId(shopId);

  const query = await context.queries.groups(context, dbShopId);
  return getPaginatedResponse(query, connectionArgs, {
    includeHasNextPage: wasFieldRequested("pageInfo.hasNextPage", info),
    includeHasPreviousPage: wasFieldRequested("pageInfo.hasPreviousPage", info),
    includeTotalCount: wasFieldRequested("totalCount", info)
  });
}
github reactioncommerce / reaction / src / core-services / orders / resolvers / OrderFulfillmentGroup / items.js View on Github external
export default async function items(fulfillmentGroup, connectionArgs, context) {
  let { items: orderItems } = fulfillmentGroup;
  if (!Array.isArray(orderItems) || orderItems.length === 0) return xformArrayToConnection(connectionArgs, []);

  // Apply requested sorting
  orderItems = sortOrderItems(orderItems, connectionArgs);

  return xformArrayToConnection(connectionArgs, xformOrderItems(context, orderItems));
}
github reactioncommerce / reaction / imports / plugins / core / cart / server / no-meteor / resolvers / Cart / items.js View on Github external
export default async function items(cart, connectionArgs, context) {
  let { items: cartItems } = cart;
  if (!Array.isArray(cartItems) || cartItems.length === 0) return xformArrayToConnection(connectionArgs, []);

  // Apply requested sorting
  cartItems = sortCartItems(cartItems, connectionArgs);

  return xformArrayToConnection(connectionArgs, xformCartItems(context, cartItems));
}
github reactioncommerce / reaction / imports / plugins / core / orders / server / no-meteor / resolvers / OrderFulfillmentGroup / items.js View on Github external
export default async function items(fulfillmentGroup, connectionArgs, context) {
  let { items: orderItems } = fulfillmentGroup;
  if (!Array.isArray(orderItems) || orderItems.length === 0) return xformArrayToConnection(connectionArgs, []);

  // Apply requested sorting
  orderItems = sortOrderItems(orderItems, connectionArgs);

  return xformArrayToConnection(connectionArgs, xformOrderItems(context, orderItems));
}
github reactioncommerce / reaction / imports / plugins / core / cart / server / no-meteor / resolvers / Cart / items.js View on Github external
export default async function items(cart, connectionArgs, context) {
  let { items: cartItems } = cart;
  if (!Array.isArray(cartItems) || cartItems.length === 0) return xformArrayToConnection(connectionArgs, []);

  // Apply requested sorting
  cartItems = sortCartItems(cartItems, connectionArgs);

  return xformArrayToConnection(connectionArgs, xformCartItems(context, cartItems));
}
github reactioncommerce / reaction / src / core-services / cart / resolvers / Cart / items.js View on Github external
export default async function items(cart, connectionArgs, context) {
  let { items: cartItems } = cart;
  if (!Array.isArray(cartItems) || cartItems.length === 0) return xformArrayToConnection(connectionArgs, []);

  // Apply requested sorting
  cartItems = sortCartItems(cartItems, connectionArgs);

  return xformArrayToConnection(connectionArgs, xformCartItems(context, cartItems));
}
github reactioncommerce / reaction / imports / plugins / core / orders / server / no-meteor / resolvers / OrderFulfillmentGroup / items.js View on Github external
export default async function items(fulfillmentGroup, connectionArgs, context) {
  let { items: orderItems } = fulfillmentGroup;
  if (!Array.isArray(orderItems) || orderItems.length === 0) return xformArrayToConnection(connectionArgs, []);

  // Apply requested sorting
  orderItems = sortOrderItems(orderItems, connectionArgs);

  return xformArrayToConnection(connectionArgs, xformOrderItems(context, orderItems));
}