adminFront/src/api/account.ts

55 lines
1.1 KiB
TypeScript
Raw Normal View History

import { makeRequest } from "@frontend/kitui";
2023-08-31 12:46:34 +00:00
import { parseAxiosError } from "@root/utils/parse-error";
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;
};
const baseUrl =
process.env.NODE_ENV === "production"
2023-08-31 12:46:34 +00:00
? "/customer"
: "https://admin.pena.digital/customer";
export const getAccountInfo = async (
id: string
): Promise<[Account | null, string?]> => {
try {
const accountInfoResponse = await makeRequest<never, Account>({
url: `/account${baseUrl}/${id}`,
method: "GET",
useToken: true,
});
return [accountInfoResponse];
} catch (nativeError) {
const [error] = parseAxiosError(nativeError);
return [null, `Не удалось получить информацию об аккаунте. ${error}`];
}
};