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

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

* chore: minor updates

* chore: error handling
This commit is contained in:
Prateek Shourya 2025-01-07 19:07:47 +05:30 committed by GitHub
parent ae657af958
commit 200be0ac7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 240 additions and 284 deletions

View file

@ -1,7 +1,7 @@
// plane web constants
import { AI_EDITOR_TASKS, API_BASE_URL } from "@plane/constants";
// services
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
/**
* Payload type for AI editor tasks

View file

@ -9,7 +9,7 @@ import { APIService } from "../api.service";
* Provides methods for user authentication, password management, and session handling
* @extends {APIService}
*/
export default class AuthService extends APIService {
export class AuthService extends APIService {
/**
* Creates an instance of AuthService
* Initializes with the base API URL

View file

@ -1,6 +1,6 @@
import { API_BASE_URL } from "@plane/constants";
import type { TCycleDistribution, TProgressSnapshot, TCycleEstimateDistribution } from "@plane/types";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
/**
* Service class for managing cycles within a workspace and project context.

View file

@ -1,6 +1,6 @@
import { API_BASE_URL } from "@plane/constants";
import { ICycle } from "@plane/types";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
/**
* Service class for managing archived cycles in a project

View file

@ -1,5 +1,5 @@
import { API_BASE_URL } from "@plane/constants";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
export class CycleOperationsService extends APIService {
constructor(BASE_URL?: string) {

View file

@ -1,6 +1,6 @@
import { API_BASE_URL } from "@plane/constants";
import type { CycleDateCheckData, ICycle, TIssuesResponse, IWorkspaceActiveCyclesResponse } from "@plane/types";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
/**
* Service class for managing cycles within a workspace and project context.

View file

@ -1,6 +1,6 @@
import { API_BASE_URL } from "@plane/constants";
import { IApiToken } from "@plane/types";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
export class APITokenService extends APIService {
constructor(BASE_URL?: string) {

View file

@ -1,13 +1,22 @@
// plane imports
import { API_BASE_URL } from "@plane/constants";
import type { IInstanceInfo, TPage } from "@plane/types";
import { APIService } from "@/api.service";
import type {
IFormattedInstanceConfiguration,
IInstance,
IInstanceAdmin,
IInstanceConfiguration,
IInstanceInfo,
TPage,
} from "@plane/types";
// api service
import { APIService } from "../api.service";
/**
* Service class for managing instance-related operations
* Handles retrieval of instance information and changelog
* @extends {APIService}
*/
export default class InstanceService extends APIService {
export class InstanceService extends APIService {
/**
* Creates an instance of InstanceService
* Initializes the service with the base API URL
@ -25,7 +34,7 @@ export default class InstanceService extends APIService {
return this.get("/api/instances/")
.then((response) => response.data)
.catch((error) => {
throw error;
throw error?.response?.data;
});
}
@ -38,7 +47,77 @@ export default class InstanceService extends APIService {
return this.get("/api/instances/changelog/")
.then((response) => response.data)
.catch((error) => {
throw error;
throw error?.response?.data;
});
}
/**
* Fetches the list of instance admins
* @returns {Promise<IInstanceAdmin[]>} Promise resolving to an array of instance admins
* @throws {Error} If the API request fails
*/
async admins(): Promise<IInstanceAdmin[]> {
return this.get("/api/instances/admins/")
.then((response) => response.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Updates the instance information
* @param {Partial<IInstance>} data Data to update the instance with
* @returns {Promise<IInstance>} Promise resolving to the updated instance information
* @throws {Error} If the API request fails
*/
async update(data: Partial<IInstance>): Promise<IInstance> {
return this.patch("/api/instances/", data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Fetches the list of instance configurations
* @returns {Promise<IInstanceConfiguration[]>} Promise resolving to an array of instance configurations
* @throws {Error} If the API request fails
*/
async configurations(): Promise<IInstanceConfiguration[]> {
return this.get("/api/instances/configurations/")
.then((response) => response.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Updates the instance configurations
* @param {Partial<IFormattedInstanceConfiguration>} data Data to update the instance configurations with
* @returns {Promise<IInstanceConfiguration[]>} The updated instance configurations
* @throws {Error} If the API request fails
*/
async updateConfigurations(data: Partial<IFormattedInstanceConfiguration>): Promise<IInstanceConfiguration[]> {
return this.patch("/api/instances/configurations/", data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Sends a test email to the specified receiver to test SMTP configuration
* @param {string} receiverEmail Email address to send the test email to
* @returns {Promise<void>} Promise resolving to void
* @throws {Error} If the API request fails
*/
async sendTestEmail(receiverEmail: string): Promise<void> {
return this.post("/api/instances/email-credentials-check/", {
receiver_email: receiverEmail,
})
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -1,5 +1,5 @@
import { API_BASE_URL } from "@plane/constants";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
export default class IntakeService extends APIService {
constructor(BASE_URL?: string) {

View file

@ -1,5 +1,5 @@
import { API_BASE_URL } from "@plane/constants";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
export default class IntakeIssueService extends APIService {
constructor(BASE_URL?: string) {

View file

@ -1,7 +1,7 @@
// types
import type { ILinkDetails, ModuleLink } from "@plane/types";
// services
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
/**
* Service class for handling module link related operations.

View file

@ -1,7 +1,7 @@
// types
import type { IModule, ILinkDetails, ModuleLink, TIssuesResponse } from "@plane/types";
// services
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
export class ModuleService extends APIService {
constructor(baseURL: string) {

View file

@ -1,7 +1,7 @@
// types
// import type { IModule, ILinkDetails, ModuleLink, TIssuesResponse } from "@plane/types";
// services
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
export class ModuleOperationService extends APIService {
constructor(baseURL: string) {

View file

@ -1 +1 @@
export * from "./view.service";
export * from "./view.service";

View file

@ -0,0 +1,14 @@
// plane imports
import { API_BASE_URL } from "@plane/constants";
// api services
import { APIService } from "../api.service";
export class ProjectViewService extends APIService {
/**
* Creates an instance of ProjectViewService
* @param {string} baseUrl - The base URL for API requests
*/
constructor(BASE_URL?: string) {
super(BASE_URL || API_BASE_URL);
}
}

View file

@ -1,6 +1,6 @@
import { API_BASE_URL } from "@plane/constants";
import type { IFavorite } from "@plane/types";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
/**
* Service class for managing user favorites

View file

@ -1 +1,2 @@
export * from "./favorite.service";
export * from "./user.service";

View file

@ -0,0 +1,33 @@
// plane imports
import { API_BASE_URL } from "@plane/constants";
import type { IUser } from "@plane/types";
// api service
import { APIService } from "../api.service";
/**
* Service class for managing user operations
* Handles operations for retrieving the current user's details and perform CRUD operations
* @extends {APIService}
*/
export class UserService extends APIService {
/**
* Constructor for UserService
* @param BASE_URL - Base URL for API requests
*/
constructor(BASE_URL?: string) {
super(BASE_URL || API_BASE_URL);
}
/**
* Retrieves the current instance admin details
* @returns {Promise<IUser>} Promise resolving to the current instance admin details
* @throws {Error} If the API request fails
*/
async adminDetails(): Promise<IUser> {
return this.get("/api/instances/admins/me/")
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -3,3 +3,4 @@ export * from "./member.service";
export * from "./notification.service";
export * from "./view.service";
export * from "./workspace.service";
export * from "./instance-workspace.service";

View file

@ -0,0 +1,65 @@
import { API_BASE_URL } from "@plane/constants";
import type { IWorkspace, TWorkspacePaginationInfo } from "@plane/types";
import { APIService } from "../api.service";
/**
* Service class for managing instance workspaces
* Handles CRUD operations on instance workspaces
* @extends APIService
*/
export class InstanceWorkspaceService extends APIService {
/**
* Constructor for InstanceWorkspaceService
* @param BASE_URL - Base URL for API requests
*/
constructor(BASE_URL?: string) {
super(BASE_URL || API_BASE_URL);
}
/**
* Retrieves a paginated list of workspaces for the current instance
* @param {string} nextPageCursor - Optional cursor to retrieve the next page of results
* @returns {Promise<TWorkspacePaginationInfo>} Promise resolving to a paginated list of workspaces
* @throws {Error} If the API request fails
*/
async list(nextPageCursor?: string): Promise<TWorkspacePaginationInfo> {
return this.get(`/api/instances/workspaces/`, {
params: {
cursor: nextPageCursor,
},
})
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Checks if a workspace slug is available
* @param {string} slug - The workspace slug to check
* @returns {Promise<any>} Promise resolving to slug availability status
* @throws {Error} If the API request fails
*/
async slugCheck(slug: string): Promise<any> {
const params = new URLSearchParams({ slug });
return this.get(`/api/instances/workspace-slug-check/?${params.toString()}`)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
/**
* Creates a new workspace
* @param {Partial<IWorkspace>} data - Workspace data for creation
* @returns {Promise<IWorkspace>} Promise resolving to the created workspace
* @throws {Error} If the API request fails
*/
async create(data: Partial<IWorkspace>): Promise<IWorkspace> {
return this.post("/api/instances/workspaces/", data)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

View file

@ -1,6 +1,6 @@
import { API_BASE_URL } from "@plane/constants";
import { IWorkspaceMemberInvitation, IWorkspaceBulkInviteFormData, IWorkspaceMember } from "@plane/types";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
/**
* Service class for managing workspace invitations

View file

@ -1,6 +1,6 @@
import { API_BASE_URL } from "@plane/constants";
import { IWorkspaceView, TIssuesResponse } from "@plane/types";
import { APIService } from "@/api.service";
import { APIService } from "../api.service";
export class WorkspaceViewService extends APIService {
/**