105 lines
3.0 KiB
TypeScript
105 lines
3.0 KiB
TypeScript
import type { ApiResponse } from '@/types/apiResponse';
|
|
import type { FetchPromise } from '@/types/fetchPromise';
|
|
import type {
|
|
CompleteUserInformationRequest,
|
|
ConfirmEmailOtpRequest,
|
|
ConfirmForgetPassCodeRequest,
|
|
ConfirmOtpResponse,
|
|
ConfirmSmsOtpRequest,
|
|
GetUserStatusByPhoneNumberOrEmailRequest,
|
|
GetUserStatusByPhoneNumberOrEmailResponse,
|
|
LoginOrSignUpWithGoogleRequest,
|
|
LoginOrSignUpWithGoogleResponse,
|
|
LoginRequest,
|
|
LoginResponse,
|
|
PasswordLoginRequest,
|
|
ResetPasswordRequest,
|
|
ResetPasswordResponse,
|
|
SendEmailOtpRequest,
|
|
SendForgetPassCodeRequest,
|
|
SendSmsOtpRequest,
|
|
} from '../types/userTypes';
|
|
|
|
const API_URL = 'https://accounts.business-harmony.com/api';
|
|
|
|
export const fetchRequest = <T = ApiResponse>(
|
|
url: string,
|
|
body: Object | null,
|
|
): FetchPromise<T> => {
|
|
return fetch(`${API_URL}/${url}`, {
|
|
body: JSON.stringify(body),
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
});
|
|
};
|
|
|
|
// GetUserStatusByPhoneNumberOrEmail
|
|
|
|
export const getUserStatusByPhoneNumberOrEmail = async (
|
|
body: GetUserStatusByPhoneNumberOrEmailRequest,
|
|
) => {
|
|
return fetchRequest<GetUserStatusByPhoneNumberOrEmailResponse>(
|
|
'User/GetUserStatusByPhoneNumberOrEmail',
|
|
body,
|
|
);
|
|
};
|
|
|
|
export const loginOrSignUpWithOtp = async (body: LoginRequest) => {
|
|
return fetchRequest<LoginResponse>('User/LoginOrSignUpWithOtp', body);
|
|
};
|
|
|
|
export const loginWithPassword = async (body: PasswordLoginRequest) => {
|
|
return fetchRequest<LoginResponse>('User/LoginWithPassword', body);
|
|
};
|
|
|
|
export const sendSmsOtp = async (body: SendSmsOtpRequest) => {
|
|
return fetchRequest<ApiResponse>('User/SendSmsOtp', body);
|
|
};
|
|
|
|
export const sendEmailOtp = async (body: SendEmailOtpRequest) => {
|
|
return fetchRequest<ApiResponse>('User/SendEmailOtp', body);
|
|
};
|
|
|
|
export const confirmSmsOtp = async (body: ConfirmSmsOtpRequest) => {
|
|
return fetchRequest<ConfirmOtpResponse>('User/ConfirmSmsOtp', body);
|
|
};
|
|
|
|
export const confirmEmailOtp = async (body: ConfirmEmailOtpRequest) => {
|
|
return fetchRequest<ConfirmOtpResponse>('User/ConfirmEmailOtp', body);
|
|
};
|
|
|
|
export const resetPassword = async (body: ResetPasswordRequest) => {
|
|
return fetchRequest<ResetPasswordResponse>('User/ResetPassword', body);
|
|
};
|
|
|
|
export const sendForgetPassCode = async (body: SendForgetPassCodeRequest) => {
|
|
return fetchRequest<ApiResponse>('User/SendForgetPassCode', body);
|
|
};
|
|
|
|
export const confirmForgetPassCode = async (
|
|
body: ConfirmForgetPassCodeRequest,
|
|
) => {
|
|
return fetchRequest<ConfirmOtpResponse>('User/ConfirmForgetPassCode', body);
|
|
};
|
|
|
|
export const loginOrSignUpWithGoogle = async (
|
|
body: LoginOrSignUpWithGoogleRequest,
|
|
) => {
|
|
return fetchRequest<LoginOrSignUpWithGoogleResponse>(
|
|
'User/LoginOrSignUpWithGoogle',
|
|
body,
|
|
);
|
|
};
|
|
|
|
export const completeUserInformation = async (
|
|
body: CompleteUserInformationRequest,
|
|
) => {
|
|
return fetchRequest<ApiResponse>('User/CompleteUserInformation', body);
|
|
};
|
|
|
|
export const logOut = async () => {
|
|
return fetchRequest<ApiResponse>('User/LogOut', {});
|
|
};
|