Skip to content

Comments

[WEB-3065] refactor: replace admin services with service packages#6342

Merged
sriramveeraghanta merged 3 commits intopreviewfrom
refactor-admin-services
Jan 7, 2025
Merged

[WEB-3065] refactor: replace admin services with service packages#6342
sriramveeraghanta merged 3 commits intopreviewfrom
refactor-admin-services

Conversation

@prateekshourya29
Copy link
Member

@prateekshourya29 prateekshourya29 commented Jan 7, 2025

Description

In this PR, I have replaced all the admin application services with service package

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Summary by CodeRabbit

Based on the comprehensive summary, here are the updated release notes:

  • Services Refactoring

    • Introduced a new @plane/services package.
    • Standardized service imports across the application.
    • Updated method signatures in multiple services.
  • New Services

    • Added InstanceWorkspaceService for workspace management.
    • Added ProjectViewService for project view operations.
    • Added UserService for retrieving admin user details.
  • Import and Path Changes

    • Replaced relative imports with absolute imports.
    • Updated import statements across multiple files.
    • Removed path aliases in TypeScript configuration.
  • Dependency Management

    • Added @plane/services as a new dependency.
    • Removed several standalone service files.

These changes represent a significant restructuring of the services layer to improve modularity and consistency across the application.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Walkthrough

This pull request involves significant refactoring of service modules within the Plane project, focusing on restructuring service imports and modifying service classes. The changes primarily include updating import paths to a centralized @plane/services package, removing individual service files, and introducing new methods in the InstanceService and InstanceWorkspaceService classes. Additionally, method signatures across various components have been refined to enhance clarity and maintainability.

Changes

File/Path Change Summary
admin/package.json Added @plane/services dependency
admin/core/services/* Removed individual service files like api.service.ts, auth.service.ts, instance.service.ts, user.service.ts, workspace.service.ts
packages/services/src/ Added new centralized services such as InstanceService, UserService, and InstanceWorkspaceService with refined method signatures
Multiple components Updated service imports from relative/absolute paths to @plane/services

Sequence Diagram

sequenceDiagram
    participant Client
    participant Services
    participant API

    Client->>Services: Request workspace/instance data
    Services->>API: Make HTTP request
    API-->>Services: Return response data
    Services-->>Client: Provide processed data
Loading

Possibly related PRs

  • [WEB-2610] fix: workspace redirection from admin app #6122: Changes in admin/app/workspace/create/form.tsx involve modifications to the WorkspaceCreateForm component, which is related to the InstanceService used for workspace management, similar to the changes made in the main PR regarding the InstanceService import path.

Suggested Reviewers

  • SatishGandham
  • sriramveeraghanta
  • pushya22

Poem

🐰 Services dancing, imports realign,
Code refactored, looking so fine!
From scattered paths to one clear way,
Rabbit's magic makes modules play!
Plane's architecture, sleek and bright! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🔭 Outside diff range comments (1)
packages/services/src/auth/auth.service.ts (1)

Line range hint 89-116: Consider environment-agnostic approach for signOut

The signOut method uses direct DOM manipulation which might not work in all environments (e.g., SSR). Consider using the API service's post method instead.

   async signOut(baseUrl: string): Promise<any> {
-    await this.requestCSRFToken().then((data) => {
-      const csrfToken = data?.csrf_token;
-
-      if (!csrfToken) throw Error("CSRF token not found");
-
-      const form = document.createElement("form");
-      const element1 = document.createElement("input");
-
-      form.method = "POST";
-      form.action = `${baseUrl}/auth/sign-out/`;
-
-      element1.value = csrfToken;
-      element1.name = "csrfmiddlewaretoken";
-      element1.type = "hidden";
-      form.appendChild(element1);
-
-      document.body.appendChild(form);
-
-      form.submit();
-    });
+    const { csrf_token } = await this.requestCSRFToken();
+    if (!csrf_token) throw Error("CSRF token not found");
+    
+    return this.post(
+      `${baseUrl}/auth/sign-out/`,
+      { csrfmiddlewaretoken: csrf_token },
+      {
+        headers: {
+          "X-CSRFTOKEN": csrf_token
+        }
+      }
+    );
   }
🧹 Nitpick comments (16)
packages/services/src/project/view.service.ts (1)

6-6: Add class-level JSDoc documentation

Consider adding comprehensive class-level documentation to describe the purpose and responsibilities of this service.

+/**
+ * Service responsible for managing project views and their operations
+ * Handles CRUD operations for project views, including custom views and filters
+ */
 export class ProjectViewService extends APIService {
packages/services/src/ai/ai.service.ts (1)

Line range hint 21-71: Consider enhancing type safety with specific error and response types

The implementation is solid with good error handling and documentation. Consider these type safety improvements:

  1. Define specific error types:
type AIServiceError = {
  status: number;
  message: string;
  details?: Record<string, unknown>;
};
  1. Create detailed response interfaces:
interface GPTTaskResponse {
  result: string;
  metadata?: {
    model: string;
    processingTime: number;
  };
}

interface GrammarResponse {
  response: string;
  corrections?: Array<{
    original: string;
    corrected: string;
    explanation?: string;
  }>;
}
  1. Update method signatures to use these types:
async prompt(workspaceSlug: string, data: { prompt: string; task: string }): Promise<GPTTaskResponse>
async rephraseGrammar(workspaceSlug: string, data: TTaskPayload): Promise<GrammarResponse>
packages/services/src/user/user.service.ts (1)

26-32: Consider adding request parameters type safety

The adminDetails method could benefit from explicit typing of the response structure.

-  async adminDetails(): Promise<IUser> {
+  async adminDetails(): Promise<{ data: IUser }> {
     return this.get("/api/instances/admins/me/")
-      .then((response) => response?.data)
+      .then((response) => response)
       .catch((error) => {
-        throw error?.response;
+        throw error?.response?.data;
       });
   }
packages/services/src/workspace/instance-workspace.service.ts (1)

44-45: Consider using URLSearchParams more efficiently

The URLSearchParams instantiation and string conversion can be simplified.

-    const params = new URLSearchParams({ slug });
-    return this.get(`/api/instances/workspace-slug-check/?${params.toString()}`)
+    return this.get("/api/instances/workspace-slug-check/", {
+      params: { slug }
+    })
admin/core/store/user.store.ts (2)

59-59: Consider adding error type safety

The error handling could benefit from stronger typing instead of using any.

-    } catch (error: any) {
+    } catch (error: Error | { status: number; message: string }) {

Line range hint 31-35: Consider implementing dependency injection

Services are directly instantiated in the constructor. Consider implementing dependency injection for better testability.

-  constructor(private store: CoreRootStore) {
+  constructor(
+    private store: CoreRootStore,
+    private userService = new UserService(),
+    private authService = new AuthService()
+  ) {
     makeObservable(this, {
       // ... observable definitions
     });
-    this.userService = new UserService();
-    this.authService = new AuthService();
   }
admin/core/store/workspace.store.ts (2)

Line range hint 87-95: Consider adding error type information.

The error handling is present but could be improved by adding type information for better error handling.

-    } catch (error) {
+    } catch (error: unknown) {
       console.error("Error fetching workspaces", error);
-      throw error;
+      throw error instanceof Error ? error : new Error("Failed to fetch workspaces");

Line range hint 138-146: Consider adding data validation.

The workspace creation implementation looks correct, but consider adding data validation before making the API call.

 createWorkspace = async (data: IWorkspace): Promise<IWorkspace> => {
   try {
     this.loader = "mutation";
+    // Validate required fields
+    if (!data.name || !data.slug) {
+      throw new Error("Workspace name and slug are required");
+    }
     const workspace = await this.instanceWorkspaceService.create(data);
admin/core/components/admin-sidebar/sidebar-dropdown.tsx (1)

10-10: Fix import formatting.

There's an extra space after import in the AuthService import statement.

-import  {AuthService } from "@plane/services";
+import { AuthService } from "@plane/services";
admin/core/store/instance.store.ts (3)

5-5: Fix import formatting.

The import statement needs consistent spacing.

-import {InstanceService} from "@plane/services";
+import { InstanceService } from "@plane/services";

Line range hint 98-115: Remove console.log statement.

There's a debug console.log statement that should be removed before production.

-        console.log("instanceInfo: ", instanceInfo);
         this.isLoading = false;

Line range hint 127-137: Consider implementing retry logic for API calls.

The service methods handle errors appropriately, but for better reliability, consider implementing retry logic for transient failures.

You could create a utility function to handle retries:

const withRetry = async <T>(
  operation: () => Promise<T>,
  maxRetries: number = 3,
  delay: number = 1000
): Promise<T> => {
  let lastError: Error;
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await operation();
    } catch (error) {
      lastError = error instanceof Error ? error : new Error(String(error));
      if (i < maxRetries - 1) await new Promise(resolve => setTimeout(resolve, delay));
    }
  }
  throw lastError!;
};

Then use it in your service calls:

 updateInstanceInfo = async (data: Partial<IInstance>) => {
   try {
-    const instanceResponse = await this.instanceService.update(data);
+    const instanceResponse = await withRetry(() => this.instanceService.update(data));

Also applies to: 146-152, 161-167, 176-189

packages/services/src/instance/instance.service.ts (4)

59-65: Standardize error handling in admins method

In the admins() method, errors are caught and re-thrown using throw error;, whereas other methods like update() and updateConfigurations() throw error?.response?.data;. For consistency and to provide more informative error messages, consider standardizing the error handling across all methods to ensure they either all throw the full error object or a specific error response.


73-79: Ensure consistent error handling in update method

The update() method throws error?.response?.data; when an error occurs. To maintain consistency and provide detailed error information, consider standardizing the error handling across all methods. Decide whether to throw the full error object or a specific part of it, and apply this consistently.


86-92: Standardize error handling in configurations method

The configurations() method re-throws errors as throw error;, differing from methods that throw error?.response?.data;. To provide consistent and informative error handling, consider aligning this method's error handling with the others.


100-106: Ensure consistent error handling in updateConfigurations method

In updateConfigurations(), errors are thrown as error?.response?.data;. For consistency and clarity in error handling across all methods, consider standardizing the error handling approach.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4c4848 and e6220c9.

📒 Files selected for processing (37)
  • admin/app/email/test-email-modal.tsx (1 hunks)
  • admin/app/workspace/create/form.tsx (2 hunks)
  • admin/core/components/admin-sidebar/sidebar-dropdown.tsx (1 hunks)
  • admin/core/components/instance/setup-form.tsx (1 hunks)
  • admin/core/components/login/sign-in-form.tsx (1 hunks)
  • admin/core/services/api.service.ts (0 hunks)
  • admin/core/services/auth.service.ts (0 hunks)
  • admin/core/services/instance.service.ts (0 hunks)
  • admin/core/services/user.service.ts (0 hunks)
  • admin/core/services/workspace.service.ts (0 hunks)
  • admin/core/store/instance.store.ts (6 hunks)
  • admin/core/store/user.store.ts (2 hunks)
  • admin/core/store/workspace.store.ts (6 hunks)
  • admin/package.json (1 hunks)
  • packages/services/src/ai/ai.service.ts (1 hunks)
  • packages/services/src/auth/auth.service.ts (1 hunks)
  • packages/services/src/cycle/cycle-analytics.service.ts (1 hunks)
  • packages/services/src/cycle/cycle-archive.service.ts (1 hunks)
  • packages/services/src/cycle/cycle-operations.service.ts (1 hunks)
  • packages/services/src/cycle/cycle.service.ts (1 hunks)
  • packages/services/src/developer/api-token.service.ts (1 hunks)
  • packages/services/src/instance/instance.service.ts (2 hunks)
  • packages/services/src/intake/intake.service.ts (1 hunks)
  • packages/services/src/intake/issue.service.ts (1 hunks)
  • packages/services/src/module/link.service.ts (1 hunks)
  • packages/services/src/module/module.service.ts (1 hunks)
  • packages/services/src/module/operations.service.ts (1 hunks)
  • packages/services/src/project/index.ts (1 hunks)
  • packages/services/src/project/view.service.ts (1 hunks)
  • packages/services/src/user/favorite.service.ts (1 hunks)
  • packages/services/src/user/index.ts (1 hunks)
  • packages/services/src/user/user.service.ts (1 hunks)
  • packages/services/src/workspace/index.ts (1 hunks)
  • packages/services/src/workspace/instance-workspace.service.ts (1 hunks)
  • packages/services/src/workspace/invitation.service.ts (1 hunks)
  • packages/services/src/workspace/view.service.ts (1 hunks)
  • packages/services/tsconfig.json (0 hunks)
💤 Files with no reviewable changes (6)
  • packages/services/tsconfig.json
  • admin/core/services/instance.service.ts
  • admin/core/services/api.service.ts
  • admin/core/services/auth.service.ts
  • admin/core/services/workspace.service.ts
  • admin/core/services/user.service.ts
✅ Files skipped from review due to trivial changes (14)
  • packages/services/src/project/index.ts
  • packages/services/src/module/operations.service.ts
  • packages/services/src/cycle/cycle-analytics.service.ts
  • packages/services/src/workspace/view.service.ts
  • packages/services/src/workspace/invitation.service.ts
  • packages/services/src/cycle/cycle-operations.service.ts
  • packages/services/src/cycle/cycle-archive.service.ts
  • packages/services/src/developer/api-token.service.ts
  • packages/services/src/intake/intake.service.ts
  • packages/services/src/user/favorite.service.ts
  • packages/services/src/intake/issue.service.ts
  • packages/services/src/module/link.service.ts
  • admin/core/components/instance/setup-form.tsx
  • packages/services/src/cycle/cycle.service.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint-web
  • GitHub Check: lint-admin
  • GitHub Check: lint-space
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (16)
packages/services/src/project/view.service.ts (2)

6-14: Implementation appears incomplete

The service class is currently empty without any methods for handling project view operations. Consider implementing methods for:

  • Creating project views
  • Retrieving project views
  • Updating project views
  • Deleting project views

Would you like me to help generate the implementation for these essential project view operations?


1-4: Verify the APIService import path

Since this PR involves refactoring services, let's verify that the APIService import path is correct and the service exists at the specified location.

✅ Verification successful

Import path for APIService is correct

The relative import path "../api.service" correctly points to the APIService class which exists at packages/services/src/api.service.ts and is widely used as the base class across the services package.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and location of api.service.ts

# Check if api.service.ts exists in the expected location
fd -e ts "api.service.ts" packages/services/src/

# Check the content of api.service.ts to verify it exports APIService
rg -l "export.*class.*APIService" packages/services/src/

Length of output: 1466

packages/services/src/ai/ai.service.ts (2)

Line range hint 7-19: Well-structured type definition with comprehensive documentation

The TTaskPayload type is well-documented with JSDoc comments and has a clear structure that supports both required and optional fields.


4-4: Verify the relative import path resolution

The change from absolute to relative import path aligns with the service package refactoring. Let's verify that the path resolves correctly.

✅ Verification successful

Relative import path is correctly resolved

The import path "../api.service" correctly resolves to the APIService class and follows the consistent pattern used by other services in the same package.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and location of api.service.ts
# relative to the current file's location

# Check if api.service.ts exists at the expected location
fd --type f "api.service.ts" --exec echo "Found api.service at: {}"

# Verify there are no lingering references to the old import path
rg -l "@/api.service" 

Length of output: 328


Script:

#!/bin/bash
# Verify APIService class exists in the target file
ast-grep --pattern 'export class APIService {
  $$$
}'  packages/services/src/api.service.ts

# Check if there are any other files importing APIService
rg "import.*APIService.*from" -g "!api.service.ts"

Length of output: 8373

packages/services/src/auth/auth.service.ts (1)

12-12: LGTM: Export change aligns with module system best practices

The change from default export to named export improves consistency and makes imports more explicit.

admin/core/store/workspace.store.ts (2)

3-4: Service initialization looks good.

The migration from WorkspaceService to InstanceWorkspaceService is properly implemented with correct import and initialization.

Also applies to: 32-32, 51-51


Line range hint 112-120: Verify pagination cursor handling.

The pagination implementation looks correct, but ensure that the cursor handling in list() method of InstanceWorkspaceService matches the expected format.

✅ Verification successful

Cursor handling implementation verified successfully.

The pagination implementation in both the workspace store and InstanceWorkspaceService is correct and type-safe. The cursor is properly passed to the API and the pagination information is correctly handled in the response.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the implementation of cursor handling in InstanceWorkspaceService
ast-grep --pattern 'class InstanceWorkspaceService {
  $$$
  list($cursor) {
    $$$
  }
  $$$
}'

Length of output: 99


Script:

#!/bin/bash
# Find files that might contain InstanceWorkspaceService
fd -t f workspace

# Search for InstanceWorkspaceService class or interface
rg "class InstanceWorkspaceService|interface InstanceWorkspaceService" -A 5

# Try alternative ast-grep pattern for TypeScript
ast-grep --pattern 'export class InstanceWorkspaceService {
  $$$
  async list($_): Promise<$_> {
    $$$
  }
  $$$
}'

Length of output: 4998


Script:

#!/bin/bash
# View the implementation file
cat packages/services/src/workspace/instance-workspace.service.ts

# Search for pagination-related types
rg "interface.*Paginated|type.*Paginated" -A 3

Length of output: 2971


Script:

#!/bin/bash
# Check the workspace pagination type definition
rg "type.*TWorkspacePaginationInfo|interface.*TWorkspacePaginationInfo" -A 5 packages/types/src/

Length of output: 287

admin/app/email/test-email-modal.tsx (1)

3-4: LGTM! Clean import refactoring.

The import path update aligns with the service package restructuring.

packages/services/src/module/module.service.ts (2)

4-4: LGTM! Import path updated correctly.

The change from alias import to relative path aligns with the service package refactoring.


Line range hint 41-42: Improved type safety and REST compliance.

The update method now:

  1. Uses Partial<IModule> type for better type safety
  2. Uses PATCH instead of PUT, following REST conventions for partial updates
admin/core/components/login/sign-in-form.tsx (1)

8-8: LGTM! Service import updated correctly.

Import updated to use the centralized @plane/services package.

admin/app/workspace/create/form.tsx (2)

7-7: LGTM! Service migration implemented correctly.

Successfully migrated from WorkspaceService to InstanceWorkspaceService.

Also applies to: 14-14


41-42: Method call updated appropriately.

The workspaceSlugCheck method call has been correctly updated to use slugCheck from the new service.

admin/package.json (1)

21-21: LGTM! Required dependency added.

Added @plane/services package dependency to support the service refactoring.

packages/services/src/user/index.ts (1)

2-2: Confirming export of user.service

Adding export * from "./user.service"; correctly exposes all exports from user.service. This change enhances the module's public API and maintains consistency with other service exports.

packages/services/src/workspace/index.ts (1)

6-6: Confirming export of instance-workspace.service

Including export * from "./instance-workspace.service"; appropriately expands the workspace service exports. This ensures that functionalities from instance-workspace.service are accessible where needed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
packages/services/src/instance/instance.service.ts (1)

114-122: ⚠️ Potential issue

Adjust return type or implementation of sendTestEmail method

The method is declared to return Promise<void>, but it returns response?.data. This mismatch should be addressed.

Apply this diff to align the implementation with the declared return type:

  async sendTestEmail(receiverEmail: string): Promise<void> {
    return this.post("/api/instances/email-credentials-check/", {
      receiver_email: receiverEmail,
    })
-     .then((response) => response?.data)
+     .then(() => undefined)
      .catch((error) => {
        throw error?.response?.data;
      });
  }
🧹 Nitpick comments (1)
packages/services/src/instance/instance.service.ts (1)

Line range hint 19-122: Consider implementing centralized error handling.

Given the service's role in the refactoring effort and the observed inconsistencies in error handling, consider implementing a centralized error handling mechanism in the base APIService class. This would ensure consistent error propagation across all derived services.

This could be achieved by:

  1. Adding an error handling method in APIService
  2. Using this method consistently across all service methods
  3. Standardizing error response formats

Would you like me to provide a detailed implementation proposal for this architectural improvement?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6220c9 and 397e8fc.

📒 Files selected for processing (2)
  • packages/services/src/instance/instance.service.ts (2 hunks)
  • packages/services/src/user/user.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/services/src/user/user.service.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: lint-web
  • GitHub Check: lint-space
  • GitHub Check: lint-admin
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
packages/services/src/instance/instance.service.ts (3)

1-19: Well-structured imports and class documentation!

The imports are properly organized, and the class documentation follows JSDoc conventions effectively.


73-79: LGTM! Well-implemented update method.

The method is properly typed, uses appropriate HTTP method (PATCH), and has consistent error handling.


100-106: LGTM! Well-implemented configuration update method.

The method is properly typed, uses appropriate HTTP method (PATCH), and has consistent error handling.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/services/src/instance/instance.service.ts (1)

108-121: ⚠️ Potential issue

Align implementation with declared return type.

The method is declared to return Promise<void> but returns response?.data. This issue was previously identified in the past review.

Apply this diff to align the implementation with the declared return type:

  async sendTestEmail(receiverEmail: string): Promise<void> {
    return this.post("/api/instances/email-credentials-check/", {
      receiver_email: receiverEmail,
    })
-     .then((response) => response?.data)
+     .then(() => undefined)
      .catch((error) => {
        throw error?.response?.data;
      });
  }
🧹 Nitpick comments (1)
packages/services/src/instance/instance.service.ts (1)

54-92: Standardize response data access pattern.

Some methods use response.data while others use response?.data. Consider standardizing to use optional chaining consistently:

  async admins(): Promise<IInstanceAdmin[]> {
    return this.get("/api/instances/admins/")
-     .then((response) => response.data)
+     .then((response) => response?.data)
      .catch((error) => {
        throw error?.response?.data;
      });
  }

  async configurations(): Promise<IInstanceConfiguration[]> {
    return this.get("/api/instances/configurations/")
-     .then((response) => response.data)
+     .then((response) => response?.data)
      .catch((error) => {
        throw error?.response?.data;
      });
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 397e8fc and caea7ad.

📒 Files selected for processing (1)
  • packages/services/src/instance/instance.service.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build-web
  • GitHub Check: build-admin
  • GitHub Check: build-space
🔇 Additional comments (2)
packages/services/src/instance/instance.service.ts (2)

1-19: LGTM! Well-organized imports and clear class documentation.

The imports are properly grouped and documented, with clear type definitions imported from the shared types package.


Line range hint 26-52: LGTM! Consistent error handling implementation.

The error handling in both methods now follows the standardized pattern of throwing error?.response?.data, addressing the consistency issues raised in previous reviews.

@sriramveeraghanta sriramveeraghanta merged commit 200be0a into preview Jan 7, 2025
11 checks passed
@sriramveeraghanta sriramveeraghanta deleted the refactor-admin-services branch January 7, 2025 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants