2024-04-16 19:01:22 +00:00
|
|
|
|
import makeRequest from "@root/api/makeRequest";
|
2023-08-08 11:44:53 +00:00
|
|
|
|
|
2023-08-31 12:46:34 +00:00
|
|
|
|
import { parseAxiosError } from "@root/utils/parse-error";
|
|
|
|
|
|
2023-08-08 11:44:53 +00:00
|
|
|
|
type Name = {
|
|
|
|
|
firstname: string;
|
|
|
|
|
secondname: string;
|
|
|
|
|
middlename: string;
|
|
|
|
|
orgname: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type Wallet = {
|
|
|
|
|
currency: string;
|
|
|
|
|
cash: number;
|
|
|
|
|
purchasesAmount: number;
|
|
|
|
|
spent: number;
|
|
|
|
|
money: number;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type Account = {
|
|
|
|
|
_id: string;
|
|
|
|
|
userId: string;
|
|
|
|
|
cart: string[];
|
|
|
|
|
status: string;
|
|
|
|
|
isDeleted: boolean;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
updatedAt: string;
|
|
|
|
|
deletedAt: string;
|
|
|
|
|
name: Name;
|
|
|
|
|
wallet: Wallet;
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-23 18:31:02 +00:00
|
|
|
|
const baseUrl = process.env.REACT_APP_DOMAIN + "/customer"
|
2023-08-31 12:46:34 +00:00
|
|
|
|
|
|
|
|
|
export const getAccountInfo = async (
|
|
|
|
|
id: string
|
|
|
|
|
): Promise<[Account | null, string?]> => {
|
|
|
|
|
try {
|
|
|
|
|
const accountInfoResponse = await makeRequest<never, Account>({
|
2023-09-01 13:17:24 +00:00
|
|
|
|
url: `${baseUrl}/account/${id}`,
|
2023-08-31 12:46:34 +00:00
|
|
|
|
method: "GET",
|
|
|
|
|
useToken: true,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return [accountInfoResponse];
|
|
|
|
|
} catch (nativeError) {
|
|
|
|
|
const [error] = parseAxiosError(nativeError);
|
|
|
|
|
|
|
|
|
|
return [null, `Не удалось получить информацию об аккаунте. ${error}`];
|
|
|
|
|
}
|
|
|
|
|
};
|