import makeRequest from "@root/api/makeRequest"; 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 API_URL = `${process.env.REACT_APP_DOMAIN}/customer`; export const getAccountInfo = async (id: string): Promise<[Account | null, string?]> => { try { const accountInfoResponse = await makeRequest({ method: "GET", url: `${API_URL}/account/${id}`, useToken: true, }); return [accountInfoResponse]; } catch (nativeError) { const [error] = parseAxiosError(nativeError); return [null, `Не удалось получить информацию об аккаунте. ${error}`]; } }; export const editAccount = async (userId: string, status: "org" | "nko"): Promise<[Account | null, string?]> => { try { const editResponse = await makeRequest<{ status: "org" | "nko" }, Account>({ method: "PATCH", url: `${API_URL}/account/${userId}`, body: { status }, useToken: true, }); return [editResponse]; } catch (nativeError) { const [error] = parseAxiosError(nativeError); return [null, `Не удалось отредактировать информацию. ${error}`]; } };