[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:
parent
ae657af958
commit
200be0ac7f
37 changed files with 240 additions and 284 deletions
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue