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 = {
|
2024-05-21 07:41:31 +00:00
|
|
|
|
firstname: string;
|
|
|
|
|
secondname: string;
|
|
|
|
|
middlename: string;
|
|
|
|
|
orgname: string;
|
2023-08-08 11:44:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type Wallet = {
|
2024-05-21 07:41:31 +00:00
|
|
|
|
currency: string;
|
|
|
|
|
cash: number;
|
|
|
|
|
purchasesAmount: number;
|
|
|
|
|
spent: number;
|
|
|
|
|
money: number;
|
2023-08-08 11:44:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type Account = {
|
2024-05-21 07:41:31 +00:00
|
|
|
|
_id: string;
|
|
|
|
|
userId: string;
|
|
|
|
|
cart: string[];
|
|
|
|
|
status: string;
|
|
|
|
|
isDeleted: boolean;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
updatedAt: string;
|
|
|
|
|
deletedAt: string;
|
|
|
|
|
name: Name;
|
|
|
|
|
wallet: Wallet;
|
2023-08-08 11:44:53 +00:00
|
|
|
|
};
|
|
|
|
|
|
2024-07-22 19:32:01 +00:00
|
|
|
|
const API_URL = `${process.env.REACT_APP_DOMAIN}/customer/v1.0.1`;
|
2023-08-31 12:46:34 +00:00
|
|
|
|
|
2024-05-21 07:41:31 +00:00
|
|
|
|
export const getAccountInfo = async (id: string): Promise<[Account | null, string?]> => {
|
|
|
|
|
try {
|
|
|
|
|
const accountInfoResponse = await makeRequest<never, Account>({
|
|
|
|
|
method: "GET",
|
2024-05-22 13:48:38 +00:00
|
|
|
|
url: `${API_URL}/account/${id}`,
|
2024-05-21 07:41:31 +00:00
|
|
|
|
useToken: true,
|
|
|
|
|
});
|
2023-08-31 12:46:34 +00:00
|
|
|
|
|
2024-05-21 07:41:31 +00:00
|
|
|
|
return [accountInfoResponse];
|
|
|
|
|
} catch (nativeError) {
|
|
|
|
|
const [error] = parseAxiosError(nativeError);
|
2023-08-31 12:46:34 +00:00
|
|
|
|
|
2024-05-21 07:41:31 +00:00
|
|
|
|
return [null, `Не удалось получить информацию об аккаунте. ${error}`];
|
|
|
|
|
}
|
2023-08-31 12:46:34 +00:00
|
|
|
|
};
|
2024-05-21 14:10:02 +00:00
|
|
|
|
|
2024-05-22 13:48:38 +00:00
|
|
|
|
export const editAccount = async (userId: string, status: "org" | "nko"): Promise<[Account | null, string?]> => {
|
2024-05-21 14:10:02 +00:00
|
|
|
|
try {
|
2024-05-22 13:48:38 +00:00
|
|
|
|
const editResponse = await makeRequest<{ status: "org" | "nko" }, Account>({
|
|
|
|
|
method: "PATCH",
|
2024-05-21 14:10:02 +00:00
|
|
|
|
url: `${API_URL}/account/${userId}`,
|
|
|
|
|
body: { status },
|
2024-05-22 13:48:38 +00:00
|
|
|
|
useToken: true,
|
2024-05-21 14:10:02 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return [editResponse];
|
|
|
|
|
} catch (nativeError) {
|
|
|
|
|
const [error] = parseAxiosError(nativeError);
|
|
|
|
|
|
|
|
|
|
return [null, `Не удалось отредактировать информацию. ${error}`];
|
|
|
|
|
}
|
|
|
|
|
};
|