2022-11-19 14:21:26 +00:00
|
|
|
// services
|
2023-01-26 18:12:20 +00:00
|
|
|
import APIService from "services/api.service";
|
2023-03-15 20:06:21 +00:00
|
|
|
import type { IUser, IUserActivity } from "types";
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
|
|
|
class UserService extends APIService {
|
|
|
|
constructor() {
|
|
|
|
super(NEXT_PUBLIC_API_BASE_URL || "http://localhost:8000");
|
|
|
|
}
|
|
|
|
|
|
|
|
currentUserConfig() {
|
|
|
|
return {
|
|
|
|
url: `${this.baseURL}/api/users/me/`,
|
|
|
|
headers: this.getHeaders(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-12-13 05:55:33 +00:00
|
|
|
async userIssues(workspaceSlug: string): Promise<any> {
|
2023-01-26 18:12:20 +00:00
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/my-issues/`)
|
|
|
|
.then((response) => response?.data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async currentUser(): Promise<any> {
|
2022-11-24 14:53:50 +00:00
|
|
|
if (!this.getAccessToken()) return null;
|
2023-01-26 18:12:20 +00:00
|
|
|
return this.get("/api/users/me/")
|
|
|
|
.then((response) => response?.data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.catch((error) => {
|
2022-11-24 14:53:50 +00:00
|
|
|
this.purgeAccessToken();
|
2022-11-19 14:21:26 +00:00
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-12-16 14:56:25 +00:00
|
|
|
async updateUser(data: Partial<IUser>): Promise<any> {
|
2023-01-26 18:12:20 +00:00
|
|
|
return this.patch("/api/users/me/", data)
|
|
|
|
.then((response) => response?.data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async updateUserOnBoard(): Promise<any> {
|
2023-01-26 18:12:20 +00:00
|
|
|
return this.patch("/api/users/me/onboard/", { is_onboarded: true })
|
|
|
|
.then((response) => response?.data)
|
2022-11-19 14:21:26 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-15 20:06:21 +00:00
|
|
|
|
|
|
|
async userActivity(workspaceSlug: string): Promise<IUserActivity[]> {
|
|
|
|
return this.get(`/api/users/me/workspaces/${workspaceSlug}/activity-graph/`)
|
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-11-19 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new UserService();
|