Skip to main content

Workflows

createWishlistEntryWorkflow

This documentation provides a reference to the createWishlistEntryWorkflow. It belongs to the @mercurjs/b2c-core package. This workflow adds a product to a customer’s wishlist. If the customer doesn’t have a wishlist yet, it creates one and links it to the customer. It then links the specified product to the wishlist. Source code

Examples

packages/modules/b2c-core/src/api/store/wishlist/route.ts
import {
  AuthenticatedMedusaRequest,
  MedusaResponse,
} from "@medusajs/framework";
import { ContainerRegistrationKeys } from "@medusajs/framework/utils";
import { createWishlistEntryWorkflow } from "../../../workflows/wishlist/workflows";
import { StoreCreateWishlistType } from "./validators";

export const POST = async (
  req: AuthenticatedMedusaRequest<StoreCreateWishlistType>,
  res: MedusaResponse
) => {
  const { result } = await createWishlistEntryWorkflow.run({
    container: req.scope,
    input: {
      ...req.validatedBody,
      customer_id: req.auth_context.actor_id,
    },
  });

  const query = req.scope.resolve(ContainerRegistrationKeys.QUERY);

  const {
    data: [wishlist],
  } = await query.graph({
    entity: "wishlist",
    fields: req.queryConfig.fields,
    filters: {
      id: result.id,
    },
  });

  res.status(201).json({ wishlist });
};

Steps

Input

input
CreateWishlistDTO
required
The wishlist entry creation details.

Output

WishlistDTO
WishlistDTO
The wishlist containing the newly added product.

deleteWishlistEntryWorkflow

This documentation provides a reference to the deleteWishlistEntryWorkflow. It belongs to the @mercurjs/b2c-core package. This workflow removes a product from a customer’s wishlist by dismissing the link between the wishlist and the product. Source code

Examples

packages/modules/b2c-core/src/api/store/wishlist/[id]/product/[reference_id]/route.ts
import { AuthenticatedMedusaRequest, MedusaResponse } from '@medusajs/framework'
import { deleteWishlistEntryWorkflow } from '../../../../../../workflows/wishlist/workflows'

export const DELETE = async (
  req: AuthenticatedMedusaRequest,
  res: MedusaResponse
) => {
  await deleteWishlistEntryWorkflow.run({
    container: req.scope,
    input: req.params
  })

  res.json({
    ...req.params,
    object: 'wishlist',
    deleted: true
  })
}

Steps

Input

input
DeleteWishlistDTO
required
The wishlist entry deletion details.

Output

object
object

Steps

createWishlistEntryStep

Creates or retrieves a wishlist for a customer and links a product to it. If the customer doesn’t have a wishlist, it creates one and links it to the customer. Then it creates a link between the wishlist and the specified product. Source code

Input

input
CreateWishlistDTO
required
The wishlist entry creation details.

Output

WishlistDTO
WishlistDTO
The wishlist containing the newly linked product.

deleteWishlistEntryStep

Removes the link between a wishlist and a product, effectively removing the product from the customer’s wishlist. Source code

Input

input
DeleteWishlistDTO
required
The wishlist entry deletion details.

Output

object
object