[WEB-3066] refactor: replace Space Services with Services Package (#6353)
* [WEB-3066] refactor: replace Space Services with Services Package * chore: minor improvements * fix: type --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
This commit is contained in:
parent
39ca600091
commit
ade4d290f5
66 changed files with 1002 additions and 631 deletions
|
|
@ -1,2 +1,3 @@
|
|||
export * from "./favorite.service";
|
||||
export * from "./user.service";
|
||||
export * from "./sites-member.service";
|
||||
|
|
|
|||
31
packages/services/src/user/sites-member.service.ts
Normal file
31
packages/services/src/user/sites-member.service.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// plane imports
|
||||
import { API_BASE_URL } from "@plane/constants";
|
||||
import { 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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// plane imports
|
||||
import { API_BASE_URL } from "@plane/constants";
|
||||
import type { IUser } from "@plane/types";
|
||||
import type { IUser, TUserProfile } from "@plane/types";
|
||||
// api service
|
||||
import { APIService } from "../api.service";
|
||||
|
||||
|
|
@ -18,6 +18,60 @@ export class UserService extends APIService {
|
|||
super(BASE_URL || API_BASE_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current user details
|
||||
* @returns {Promise<IUser>} Promise resolving to the current user details\
|
||||
* @remarks This method uses the validateStatus: null option to bypass interceptors for unauthorized errors.
|
||||
*/
|
||||
async me(): Promise<IUser> {
|
||||
return this.get("/api/users/me/", { validateStatus: null })
|
||||
.then((response) => response?.data)
|
||||
.catch((error) => {
|
||||
throw error?.response;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue