51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import makeRequest from "@root/api/makeRequest";
|
|
|
|
import { parseAxiosError } from "@root/utils/parse-error";
|
|
|
|
type RawDetail = {
|
|
Key: string;
|
|
Value: number | string | RawDetail[];
|
|
};
|
|
|
|
type History = {
|
|
id: string;
|
|
userId: string;
|
|
comment: string;
|
|
key: string;
|
|
rawDetails: RawDetail[];
|
|
isDeleted: boolean;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
};
|
|
|
|
type HistoryResponse = {
|
|
records: History[];
|
|
totalPages: number;
|
|
};
|
|
|
|
const baseUrl = process.env.REACT_APP_DOMAIN + "/customer";
|
|
|
|
const getUserHistory = async (
|
|
accountId: string,
|
|
page: number
|
|
): Promise<[HistoryResponse | null, string?]> => {
|
|
try {
|
|
const historyResponse = await makeRequest<never, HistoryResponse>({
|
|
method: "GET",
|
|
url:
|
|
baseUrl +
|
|
`/history?page=${page}&limit=${100}&accountID=${accountId}&type=payCart`,
|
|
});
|
|
|
|
return [historyResponse];
|
|
} catch (nativeError) {
|
|
const [error] = parseAxiosError(nativeError);
|
|
|
|
return [null, `Ошибка при получении пользователей. ${error}`];
|
|
}
|
|
};
|
|
|
|
export const historyApi = {
|
|
getUserHistory,
|
|
};
|