|  | 
|  | 1 | +// plane constants | 
|  | 2 | +import { API_BASE_URL } from "@plane/constants"; | 
|  | 3 | +// plane types | 
|  | 4 | +import { TWorkspaceDashboard } from "@plane/types"; | 
|  | 5 | +import { APIService } from "../api.service"; | 
|  | 6 | + | 
|  | 7 | +export class WorkspaceDashboardsService extends APIService { | 
|  | 8 | +  constructor(BASE_URL?: string) { | 
|  | 9 | +    super(BASE_URL || API_BASE_URL); | 
|  | 10 | +  } | 
|  | 11 | + | 
|  | 12 | +  /** | 
|  | 13 | +   * Retrieves the list of dashboards for a specific workspace | 
|  | 14 | +   * @param {string} workspaceSlug - The unique identifier for the workspace | 
|  | 15 | +   * @returns {Promise<TWorkspaceDashboard>} Promise resolving to dashboard data | 
|  | 16 | +   * @throws {Error} If the API request fails | 
|  | 17 | +   */ | 
|  | 18 | +  async list(workspaceSlug: string): Promise<TWorkspaceDashboard[]> { | 
|  | 19 | +    return this.get(`/api/workspaces/${workspaceSlug}/dashboards/`) | 
|  | 20 | +      .then((response) => response?.data) | 
|  | 21 | +      .catch((error) => { | 
|  | 22 | +        throw error?.response?.data; | 
|  | 23 | +      }); | 
|  | 24 | +  } | 
|  | 25 | + | 
|  | 26 | +  /** | 
|  | 27 | +   * Retrieves detailed information about a specific dashboard | 
|  | 28 | +   * @param {string} workspaceSlug - The unique identifier for the workspace | 
|  | 29 | +   * @param {string} dashboardId - The unique identifier for the dashboard | 
|  | 30 | +   * @returns {Promise<TWorkspaceDashboard>} Promise resolving to dashboard details | 
|  | 31 | +   * @throws {Error} If the API request fails | 
|  | 32 | +   */ | 
|  | 33 | +  async retrieve(workspaceSlug: string, dashboardId: string): Promise<TWorkspaceDashboard> { | 
|  | 34 | +    return this.get(`/api/workspaces/${workspaceSlug}/dashboards/${dashboardId}/`) | 
|  | 35 | +      .then((response) => response?.data) | 
|  | 36 | +      .catch((error) => { | 
|  | 37 | +        throw error?.response?.data; | 
|  | 38 | +      }); | 
|  | 39 | +  } | 
|  | 40 | + | 
|  | 41 | +  /** | 
|  | 42 | +   * Creates a new dashboard within a workspace | 
|  | 43 | +   * @param {string} workspaceSlug - The unique identifier for the workspace | 
|  | 44 | +   * @param {Partial<TWorkspaceDashboard>} data - Partial dashboard data to create | 
|  | 45 | +   * @returns {Promise<TWorkspaceDashboard>} Promise resolving to the created dashboard data | 
|  | 46 | +   * @throws {Error} If the API request fails | 
|  | 47 | +   */ | 
|  | 48 | +  async create(workspaceSlug: string, data: Partial<TWorkspaceDashboard>): Promise<TWorkspaceDashboard> { | 
|  | 49 | +    return this.post(`/api/workspaces/${workspaceSlug}/dashboards/`, data) | 
|  | 50 | +      .then((response) => response?.data) | 
|  | 51 | +      .catch((error) => { | 
|  | 52 | +        throw error?.response?.data; | 
|  | 53 | +      }); | 
|  | 54 | +  } | 
|  | 55 | + | 
|  | 56 | +  /** | 
|  | 57 | +   * Updates a specific dashboard within a workspace | 
|  | 58 | +   * @param {string} workspaceSlug - The unique identifier for the workspace | 
|  | 59 | +   * @param {string} dashboardId - The unique identifier for the dashboard | 
|  | 60 | +   * @param {Partial<TWorkspaceDashboard>} data - Partial dashboard data to update | 
|  | 61 | +   * @returns {Promise<TWorkspaceDashboard>} Promise resolving to the updated dashboard data | 
|  | 62 | +   * @throws {Error} If the API request fails | 
|  | 63 | +   */ | 
|  | 64 | +  async update( | 
|  | 65 | +    workspaceSlug: string, | 
|  | 66 | +    dashboardId: string, | 
|  | 67 | +    data: Partial<TWorkspaceDashboard> | 
|  | 68 | +  ): Promise<TWorkspaceDashboard> { | 
|  | 69 | +    return this.patch(`/api/workspaces/${workspaceSlug}/dashboard/${dashboardId}/`, data) | 
|  | 70 | +      .then((response) => response?.data) | 
|  | 71 | +      .catch((error) => { | 
|  | 72 | +        throw error?.response?.data; | 
|  | 73 | +      }); | 
|  | 74 | +  } | 
|  | 75 | + | 
|  | 76 | +  /** | 
|  | 77 | +   * Removes a specific dashboard within a workspace | 
|  | 78 | +   * @param {string} workspaceSlug - The unique identifier for the workspace | 
|  | 79 | +   * @param {string} dashboardId - The unique identifier for the dashboard | 
|  | 80 | +   * @throws {Error} If the API request fails | 
|  | 81 | +   */ | 
|  | 82 | +  async destroy(workspaceSlug: string, dashboardId: string): Promise<void> { | 
|  | 83 | +    return this.delete(`/api/workspaces/${workspaceSlug}/dashboards/${dashboardId}/`) | 
|  | 84 | +      .then((response) => response?.data) | 
|  | 85 | +      .catch((error) => { | 
|  | 86 | +        throw error?.response?.data; | 
|  | 87 | +      }); | 
|  | 88 | +  } | 
|  | 89 | +} | 
0 commit comments