2019-12-16 08:49:10 +00:00
|
|
|
import { AxiosPromise } from "axios";
|
2021-03-22 09:22:24 +00:00
|
|
|
import Api from "api/Api";
|
2019-12-16 08:49:10 +00:00
|
|
|
import { ApiResponse } from "./ApiResponses";
|
|
|
|
|
|
|
|
|
|
export interface LoginUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
password: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
password: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreateUserResponse extends ApiResponse {
|
|
|
|
|
email: string;
|
|
|
|
|
id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ForgotPasswordRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
export interface TokenPasswordUpdateRequest {
|
2019-12-16 08:49:10 +00:00
|
|
|
token: string;
|
2020-01-06 09:07:30 +00:00
|
|
|
password: string;
|
|
|
|
|
email: string;
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
export interface VerifyTokenRequest {
|
2019-12-16 08:49:10 +00:00
|
|
|
email: string;
|
|
|
|
|
token: string;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-23 12:16:33 +00:00
|
|
|
export interface FetchUserResponse extends ApiResponse {
|
|
|
|
|
id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface FetchUserRequest {
|
|
|
|
|
id: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InviteUserRequest {
|
|
|
|
|
email: string;
|
|
|
|
|
groupIds: string[];
|
|
|
|
|
status?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 09:37:02 +00:00
|
|
|
export interface UpdateUserRequest {
|
2021-05-20 12:03:08 +00:00
|
|
|
name?: string;
|
|
|
|
|
email?: string;
|
2021-03-04 09:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
class UserApi extends Api {
|
2020-01-06 09:07:30 +00:00
|
|
|
static usersURL = "v1/users";
|
|
|
|
|
static forgotPasswordURL = `${UserApi.usersURL}/forgotPassword`;
|
|
|
|
|
static verifyResetPasswordTokenURL = `${UserApi.usersURL}/verifyPasswordResetToken`;
|
|
|
|
|
static resetPasswordURL = `${UserApi.usersURL}/resetPassword`;
|
2019-12-23 12:16:33 +00:00
|
|
|
static inviteUserURL = "v1/users/invite";
|
2020-01-06 09:07:30 +00:00
|
|
|
static verifyInviteTokenURL = `${UserApi.inviteUserURL}/verify`;
|
|
|
|
|
static confirmUserInviteURL = `${UserApi.inviteUserURL}/confirm`;
|
2020-02-03 10:37:03 +00:00
|
|
|
static addOrgURL = `${UserApi.usersURL}/addOrganization`;
|
2020-01-22 12:26:25 +00:00
|
|
|
static logoutURL = "v1/logout";
|
2020-07-08 10:14:03 +00:00
|
|
|
static currentUserURL = "v1/users/me";
|
2021-05-20 12:03:08 +00:00
|
|
|
static photoURL = "v1/users/photo";
|
2020-01-06 09:07:30 +00:00
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
static createUser(
|
|
|
|
|
request: CreateUserRequest,
|
|
|
|
|
): AxiosPromise<CreateUserResponse> {
|
2020-01-06 09:07:30 +00:00
|
|
|
return Api.post(UserApi.usersURL, request);
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-04 09:37:02 +00:00
|
|
|
static updateUser(request: UpdateUserRequest): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(UserApi.usersURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
static fetchUser(request: FetchUserRequest): AxiosPromise<FetchUserResponse> {
|
|
|
|
|
return Api.get(UserApi.usersURL + "/" + request.id);
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-08 10:14:03 +00:00
|
|
|
static getCurrentUser(): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.currentUserURL);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
static forgotPassword(
|
|
|
|
|
request: ForgotPasswordRequest,
|
2019-12-16 08:49:10 +00:00
|
|
|
): AxiosPromise<ApiResponse> {
|
2020-01-06 09:07:30 +00:00
|
|
|
return Api.post(UserApi.forgotPasswordURL, request);
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static verifyResetPasswordToken(
|
2020-01-06 09:07:30 +00:00
|
|
|
request: VerifyTokenRequest,
|
2019-12-16 08:49:10 +00:00
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.verifyResetPasswordTokenURL, request);
|
|
|
|
|
}
|
2019-12-23 12:16:33 +00:00
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
static resetPassword(
|
|
|
|
|
request: TokenPasswordUpdateRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(UserApi.resetPasswordURL, request);
|
2019-12-23 12:16:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inviteUser(request: InviteUserRequest): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.post(UserApi.inviteUserURL, request);
|
|
|
|
|
}
|
2020-01-03 08:49:47 +00:00
|
|
|
|
2020-01-06 09:07:30 +00:00
|
|
|
static verifyUserInvite(
|
|
|
|
|
request: VerifyTokenRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.get(UserApi.verifyInviteTokenURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static confirmInvitedUserSignup(
|
|
|
|
|
request: TokenPasswordUpdateRequest,
|
|
|
|
|
): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.put(UserApi.confirmUserInviteURL, request);
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-03 08:49:47 +00:00
|
|
|
static logoutUser(): AxiosPromise<ApiResponse> {
|
2020-01-22 12:26:25 +00:00
|
|
|
return Api.post(UserApi.logoutURL);
|
2020-01-03 08:49:47 +00:00
|
|
|
}
|
2021-05-20 12:03:08 +00:00
|
|
|
|
|
|
|
|
static uploadPhoto(request: { file: File }): AxiosPromise<ApiResponse> {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
if (request.file) {
|
|
|
|
|
formData.append("file", request.file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Api.post(UserApi.photoURL, formData, null, {
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "multipart/form-data",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static deletePhoto(): AxiosPromise<ApiResponse> {
|
|
|
|
|
return Api.delete(UserApi.photoURL);
|
|
|
|
|
}
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default UserApi;
|