base
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
import { API_BASE_URL } from "@plane/constants";
|
||||
import type { IFavorite } from "@plane/types";
|
||||
import { APIService } from "../api.service";
|
||||
|
||||
/**
|
||||
* Service class for managing user favorites
|
||||
* Handles operations for adding, updating, removing, and retrieving user favorites within a workspace
|
||||
* @extends {APIService}
|
||||
*/
|
||||
export class UserFavoriteService extends APIService {
|
||||
constructor(BASE_URL?: string) {
|
||||
super(BASE_URL || API_BASE_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new item to user favorites
|
||||
* @param {string} workspaceSlug - The unique slug identifier for the workspace
|
||||
* @param {Partial<IFavorite>} data - Favorite item data to be added
|
||||
* @returns {Promise<IFavorite>} Promise resolving to the created favorite item
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async add(workspaceSlug: string, data: Partial<IFavorite>): Promise<IFavorite> {
|
||||
return this.post(`/api/workspaces/${workspaceSlug}/user-favorites/`, data)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing favorite item
|
||||
* @param {string} workspaceSlug - The unique slug identifier for the workspace
|
||||
* @param {string} favoriteId - The unique identifier for the favorite item
|
||||
* @param {Partial<IFavorite>} data - Updated favorite item data
|
||||
* @returns {Promise<IFavorite>} Promise resolving to the updated favorite item
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async update(workspaceSlug: string, favoriteId: string, data: Partial<IFavorite>): Promise<IFavorite> {
|
||||
return this.patch(`/api/workspaces/${workspaceSlug}/user-favorites/${favoriteId}/`, data)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an item from user favorites
|
||||
* @param {string} workspaceSlug - The unique slug identifier for the workspace
|
||||
* @param {string} favoriteId - The unique identifier for the favorite item to remove
|
||||
* @returns {Promise<void>} Promise resolving when the favorite item is removed
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async remove(workspaceSlug: string, favoriteId: string): Promise<void> {
|
||||
return this.delete(`/api/workspaces/${workspaceSlug}/user-favorites/${favoriteId}/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all favorite items for a user in a workspace
|
||||
* @param {string} workspaceSlug - The unique slug identifier for the workspace
|
||||
* @returns {Promise<IFavorite[]>} Promise resolving to array of favorite items
|
||||
* @throws {Error} If the API request fails
|
||||
* @remarks This method includes the 'all' parameter to retrieve all favorites
|
||||
*/
|
||||
async list(workspaceSlug: string): Promise<IFavorite[]> {
|
||||
return this.get(`/api/workspaces/${workspaceSlug}/user-favorites/`, {
|
||||
params: {
|
||||
all: true,
|
||||
},
|
||||
})
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves grouped favorite items for a specific favorite in a workspace
|
||||
* @param {string} workspaceSlug - The unique slug identifier for the workspace
|
||||
* @param {string} favoriteId - The unique identifier for the favorite item to get grouped items for
|
||||
* @returns {Promise<IFavorite[]>} Promise resolving to array of grouped favorite items
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async groupedList(workspaceSlug: string, favoriteId: string): Promise<IFavorite[]> {
|
||||
return this.get(`/api/workspaces/${workspaceSlug}/user-favorites/${favoriteId}/group/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
export * from "./favorite.service";
|
||||
export * from "./user.service";
|
||||
export * from "./sites-member.service";
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
// plane imports
|
||||
import { API_BASE_URL } from "@plane/constants";
|
||||
import type { TPublicMember } from "@plane/types";
|
||||
// api service
|
||||
import { APIService } from "../api.service";
|
||||
|
||||
/**
|
||||
* Service class for managing members operations within plane sites application.
|
||||
* Extends APIService to handle HTTP requests to the member-related endpoints.
|
||||
* @extends {APIService}
|
||||
* @remarks This service is only available for plane sites
|
||||
*/
|
||||
export class SitesMemberService extends APIService {
|
||||
constructor(BASE_URL?: string) {
|
||||
super(BASE_URL || API_BASE_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of members for a specific anchor.
|
||||
* @param {string} anchor - The anchor identifier
|
||||
* @returns {Promise<TPublicMember[]>} The list of members
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async list(anchor: string): Promise<TPublicMember[]> {
|
||||
return this.get(`/api/public/anchor/${anchor}/members/`)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Copyright (c) 2023-present Plane Software, Inc. and contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
// plane imports
|
||||
import { API_BASE_URL } from "@plane/constants";
|
||||
import type { IUser, TUserProfile } 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 user details
|
||||
* @returns {Promise<IUser>} Promise resolving to the current user details
|
||||
*/
|
||||
async me(): Promise<IUser> {
|
||||
return this.get("/api/users/me/")
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current user details
|
||||
* @param {Partial<IUser>} data Data to update the user with
|
||||
* @returns {Promise<IUser>} Promise resolving to the updated user details
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async update(data: Partial<IUser>): Promise<IUser> {
|
||||
return this.patch("/api/users/me/", data)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response?.data;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current user's profile details
|
||||
* @returns {Promise<TUserProfile>} Promise resolving to the current user's profile details
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async profile(): Promise<TUserProfile> {
|
||||
return this.get("/api/users/me/profile/")
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the current user's profile details
|
||||
* @param {Partial<TUserProfile>} data Data to update the user's profile with
|
||||
* @returns {Promise<TUserProfile>} Promise resolving to the updated user's profile details
|
||||
* @throws {Error} If the API request fails
|
||||
*/
|
||||
async updateProfile(data: Partial<TUserProfile>): Promise<TUserProfile> {
|
||||
return this.patch("/api/users/me/profile/", data)
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user