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-29 06:54:19 +00:00
|
|
|
import trackEventServices from "services/track-event.service";
|
|
|
|
|
2023-03-30 11:34:41 +00:00
|
|
|
import type { IUser, IUserActivityResponse, IUserWorkspaceDashboard } from "types";
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
const { NEXT_PUBLIC_API_BASE_URL } = process.env;
|
|
|
|
|
2023-03-29 06:54:19 +00:00
|
|
|
const trackEvent =
|
|
|
|
process.env.NEXT_PUBLIC_TRACK_EVENTS === "true" || process.env.NEXT_PUBLIC_TRACK_EVENTS === "1";
|
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
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> {
|
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) => {
|
2023-04-08 12:35:54 +00:00
|
|
|
throw error?.response;
|
2022-11-19 14:21:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-04-03 18:27:19 +00:00
|
|
|
async updateUserOnBoard({ userRole }: any): Promise<any> {
|
|
|
|
return this.patch("/api/users/me/onboard/", {
|
|
|
|
is_onboarded: true,
|
|
|
|
})
|
2023-03-29 06:54:19 +00:00
|
|
|
.then((response) => {
|
2023-04-03 18:27:19 +00:00
|
|
|
if (trackEvent)
|
|
|
|
trackEventServices.trackUserOnboardingCompleteEvent({
|
|
|
|
...response.data,
|
|
|
|
user_role: userRole ?? "None",
|
|
|
|
});
|
2023-03-29 06:54:19 +00:00
|
|
|
return response?.data;
|
|
|
|
})
|
2022-11-19 14:21:26 +00:00
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-15 20:06:21 +00:00
|
|
|
|
2023-03-30 11:34:41 +00:00
|
|
|
async getUserActivity(): Promise<IUserActivityResponse> {
|
|
|
|
return this.get("/api/users/activities/")
|
2023-03-15 20:06:21 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2023-03-23 10:24:59 +00:00
|
|
|
|
2023-03-24 05:36:52 +00:00
|
|
|
async userWorkspaceDashboard(
|
|
|
|
workspaceSlug: string,
|
|
|
|
month: number
|
|
|
|
): Promise<IUserWorkspaceDashboard> {
|
|
|
|
return this.get(`/api/users/me/workspaces/${workspaceSlug}/dashboard/`, {
|
|
|
|
params: {
|
|
|
|
month: month,
|
|
|
|
},
|
|
|
|
})
|
2023-03-23 10:24:59 +00:00
|
|
|
.then((response) => response?.data)
|
|
|
|
.catch((error) => {
|
|
|
|
throw error?.response?.data;
|
|
|
|
});
|
|
|
|
}
|
2022-11-19 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new UserService();
|