chore: authorization module name changed and backend type and request functions added
This commit is contained in:
96
src/features/authorization/api/authorizationAPI.ts
Normal file
96
src/features/authorization/api/authorizationAPI.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import type { ApiResponse } from '@/types/apiResponse';
|
||||
import type { FetchPromise } from '@/types/fetchPromise';
|
||||
import type {
|
||||
ConfirmEmailOtpRequest,
|
||||
ConfirmForgetPassCodeRequest,
|
||||
ConfirmOtpResponse,
|
||||
ConfirmSmsOtpRequest,
|
||||
GetUserStatusByPhoneNumberOrEmailRequest,
|
||||
GetUserStatusByPhoneNumberOrEmailResponse,
|
||||
LoginOrSignUpWithGoogleRequest,
|
||||
LoginOrSignUpWithGoogleResponse,
|
||||
LoginRequest,
|
||||
LoginResponse,
|
||||
ResetPasswordRequest,
|
||||
ResetPasswordResponse,
|
||||
SendEmailOtpRequest,
|
||||
SendForgetPassCodeRequest,
|
||||
SendSmsOtpRequest,
|
||||
} from '../types/userTypes';
|
||||
|
||||
const API_URL = 'https://account.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: LoginRequest) => {
|
||||
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 logOut = async () => {
|
||||
return fetchRequest<ApiResponse>('User/LogOut', {});
|
||||
};
|
||||
Reference in New Issue
Block a user