s-private API Documentation - v3.8.1
    Preparing search index...

    Domain service for Category resolution.

    Encapsulates the business logic for resolving or creating categories. Ensures that category existence check and creation is handled correctly with proper race condition handling.

    const categoryService = new CategoryService(queryRepo, commandRepo);
    const categoryId = await categoryService.resolveOrCreate(categoryName, userId);
    // Use categoryId when creating articles
    Index

    Constructors

    Methods

    Constructors

    Methods

    • Resolves an existing category or creates a new one.

      Parameters

      • categoryName: string & $brand<"CategoryName">

        The category name to resolve

      • userId: string & $brand<"UserId">

        The user ID for tenant isolation

      Returns Promise<string & $brand<"Id">>

      The category ID (existing or newly created)

      This method handles race conditions where multiple requests might try to create the same category simultaneously. If a duplicate error occurs during creation (due to DB unique constraint), it will retry the lookup.

      const categoryId = await categoryService.resolveOrCreate(
      makeCategoryName("Tech"),
      makeUserId("user-123")
      );