2022-11-19 19:51:26 +05:30
|
|
|
// services
|
2023-01-26 23:42:20 +05:30
|
|
|
import APIService from "services/api.service";
|
2023-09-20 20:33:25 +05:30
|
|
|
import trackEventServices from "services/track_event.service";
|
2023-03-29 12:24:19 +05:30
|
|
|
|
2023-04-11 12:25:21 +05:30
|
|
|
import type {
|
|
|
|
|
ICurrentUserResponse,
|
2023-07-26 17:51:26 +05:30
|
|
|
IIssue,
|
2023-04-11 12:25:21 +05:30
|
|
|
IUser,
|
|
|
|
|
IUserActivityResponse,
|
2023-07-28 13:39:42 +05:30
|
|
|
IUserProfileData,
|
|
|
|
|
IUserProfileProjectSegregation,
|
2023-04-11 12:25:21 +05:30
|
|
|
IUserWorkspaceDashboard,
|
|
|
|
|
} from "types";
|
2022-11-19 19:51:26 +05:30
|
|
|
|
2023-09-13 20:21:02 +05:30
|
|
|
import { API_BASE_URL } from "helpers/common.helper";
|
2022-11-19 19:51:26 +05:30
|
|
|
|
2023-09-08 12:42:09 +05:30
|
|
|
export class UserService extends APIService {
|
2022-11-19 19:51:26 +05:30
|
|
|
constructor() {
|
2023-09-13 20:21:02 +05:30
|
|
|
super(API_BASE_URL);
|
2022-11-19 19:51:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentUserConfig() {
|
|
|
|
|
return {
|
|
|
|
|
url: `${this.baseURL}/api/users/me/`,
|
|
|
|
|
headers: this.getHeaders(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 17:51:26 +05:30
|
|
|
async userIssues(
|
|
|
|
|
workspaceSlug: string,
|
|
|
|
|
params: any
|
|
|
|
|
): Promise<
|
|
|
|
|
| {
|
|
|
|
|
[key: string]: IIssue[];
|
|
|
|
|
}
|
|
|
|
|
| IIssue[]
|
|
|
|
|
> {
|
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/my-issues/`, {
|
|
|
|
|
params,
|
|
|
|
|
})
|
2023-01-26 23:42:20 +05:30
|
|
|
.then((response) => response?.data)
|
2022-11-19 19:51:26 +05:30
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-11 12:25:21 +05:30
|
|
|
async currentUser(): Promise<ICurrentUserResponse> {
|
2023-01-26 23:42:20 +05:30
|
|
|
return this.get("/api/users/me/")
|
|
|
|
|
.then((response) => response?.data)
|
2022-11-19 19:51:26 +05:30
|
|
|
.catch((error) => {
|
2023-04-08 18:05:54 +05:30
|
|
|
throw error?.response;
|
2022-11-19 19:51:26 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-16 20:26:25 +05:30
|
|
|
async updateUser(data: Partial<IUser>): Promise<any> {
|
2023-01-26 23:42:20 +05:30
|
|
|
return this.patch("/api/users/me/", data)
|
|
|
|
|
.then((response) => response?.data)
|
2022-11-19 19:51:26 +05:30
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 21:36:00 +05:30
|
|
|
async updateUserOnBoard({ userRole }: any, user: ICurrentUserResponse | undefined): Promise<any> {
|
2023-04-03 23:57:19 +05:30
|
|
|
return this.patch("/api/users/me/onboard/", {
|
|
|
|
|
is_onboarded: true,
|
|
|
|
|
})
|
2023-03-29 12:24:19 +05:30
|
|
|
.then((response) => {
|
2023-09-14 16:05:31 +05:30
|
|
|
trackEventServices.trackUserOnboardingCompleteEvent(
|
|
|
|
|
{
|
|
|
|
|
user_role: userRole ?? "None",
|
|
|
|
|
},
|
|
|
|
|
user
|
|
|
|
|
);
|
2023-03-29 12:24:19 +05:30
|
|
|
return response?.data;
|
|
|
|
|
})
|
2022-11-19 19:51:26 +05:30
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-03-16 01:36:21 +05:30
|
|
|
|
2023-07-12 19:55:08 +05:30
|
|
|
async updateUserTourCompleted(user: ICurrentUserResponse): Promise<any> {
|
|
|
|
|
return this.patch("/api/users/me/tour-completed/", {
|
|
|
|
|
is_tour_completed: true,
|
|
|
|
|
})
|
|
|
|
|
.then((response) => {
|
2023-09-14 16:05:31 +05:30
|
|
|
trackEventServices.trackUserTourCompleteEvent({ user_role: user.role ?? "None" }, user);
|
2023-07-12 19:55:08 +05:30
|
|
|
return response?.data;
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 13:29:48 +05:30
|
|
|
async getUserWorkspaceActivity(workspaceSlug: string): Promise<IUserActivityResponse> {
|
|
|
|
|
return this.get(`/api/users/workspaces/${workspaceSlug}/activities/`)
|
2023-03-16 01:36:21 +05:30
|
|
|
.then((response) => response?.data)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-03-23 15:54:59 +05:30
|
|
|
|
2023-09-20 20:33:25 +05:30
|
|
|
async userWorkspaceDashboard(workspaceSlug: string, month: number): Promise<IUserWorkspaceDashboard> {
|
2023-03-24 11:06:52 +05:30
|
|
|
return this.get(`/api/users/me/workspaces/${workspaceSlug}/dashboard/`, {
|
|
|
|
|
params: {
|
|
|
|
|
month: month,
|
|
|
|
|
},
|
|
|
|
|
})
|
2023-03-23 15:54:59 +05:30
|
|
|
.then((response) => response?.data)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-06-06 21:36:13 +05:30
|
|
|
|
|
|
|
|
async forgotPassword(data: { email: string }): Promise<any> {
|
|
|
|
|
return this.post(`/api/forgot-password/`, data)
|
|
|
|
|
.then((response) => response?.data)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async resetPassword(
|
|
|
|
|
uidb64: string,
|
|
|
|
|
token: string,
|
|
|
|
|
data: {
|
|
|
|
|
new_password: string;
|
|
|
|
|
confirm_password: string;
|
|
|
|
|
}
|
|
|
|
|
): Promise<any> {
|
|
|
|
|
return this.post(`/api/reset-password/${uidb64}/${token}/`, data)
|
|
|
|
|
.then((response) => response?.data)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-07-28 13:39:42 +05:30
|
|
|
|
|
|
|
|
async getUserProfileData(workspaceSlug: string, userId: string): Promise<IUserProfileData> {
|
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/user-stats/${userId}/`)
|
|
|
|
|
.then((response) => response?.data)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getUserProfileProjectsSegregation(
|
|
|
|
|
workspaceSlug: string,
|
|
|
|
|
userId: string
|
|
|
|
|
): Promise<IUserProfileProjectSegregation> {
|
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/user-profile/${userId}/`)
|
|
|
|
|
.then((response) => response?.data)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 20:33:25 +05:30
|
|
|
async getUserProfileActivity(workspaceSlug: string, userId: string): Promise<IUserActivityResponse> {
|
2023-07-28 13:39:42 +05:30
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/user-activity/${userId}/?per_page=15`)
|
|
|
|
|
.then((response) => response?.data)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getUserProfileIssues(
|
|
|
|
|
workspaceSlug: string,
|
|
|
|
|
userId: string,
|
|
|
|
|
params: any
|
|
|
|
|
): Promise<
|
|
|
|
|
| {
|
|
|
|
|
[key: string]: IIssue[];
|
|
|
|
|
}
|
|
|
|
|
| IIssue[]
|
|
|
|
|
> {
|
|
|
|
|
return this.get(`/api/workspaces/${workspaceSlug}/user-issues/${userId}/`, {
|
|
|
|
|
params,
|
|
|
|
|
})
|
|
|
|
|
.then((response) => response?.data)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
throw error?.response?.data;
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-11-19 19:51:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new UserService();
|