Skip to main content

Workflows

createSellerCustomerGroupWorkflow

This documentation provides a reference to the createSellerCustomerGroupWorkflow. It belongs to the @mercurjs/b2c-core package. This workflow creates a customer group for a seller and links it to the seller. It ensures that customer groups are properly associated with their respective sellers in the marketplace. Source code

Examples

packages/modules/b2c-core/src/api/vendor/customer-groups/route.ts
import {
  AuthenticatedMedusaRequest,
  MedusaResponse,
} from "@medusajs/framework";
import { fetchSellerByAuthActorId } from "../../../shared/infra/http/utils";
import { createSellerCustomerGroupWorkflow } from "../../../workflows/customer-groups/workflows";
import { VendorCreateCustomerGroupType } from "./validators";

export const POST = async (
  req: AuthenticatedMedusaRequest<VendorCreateCustomerGroupType>,
  res: MedusaResponse
) => {
  const seller = await fetchSellerByAuthActorId(
    req.auth_context.actor_id,
    req.scope
  );

  const { result: customer_group } =
    await createSellerCustomerGroupWorkflow.run({
      container: req.scope,
      input: {
        ...req.validatedBody,
        created_by: req.auth_context.actor_id,
        seller_id: seller.id,
      },
    });

  res.status(201).json({
    customer_group,
  });
};

Steps

  • createCustomerGroupsWorkflow: Creates the customer group using Medusa’s core workflow.
  • createRemoteLinkStep: Links the created customer group to the seller.

Input

input
object
required
The customer group creation details.

Output

CustomerGroupDTO
CustomerGroupDTO
The created customer group.