front-hub/src/api/history.ts
2023-11-10 17:51:50 +03:00

38 lines
995 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Tariff, makeRequest } from "@frontend/kitui"
import { parseAxiosError } from "@root/utils/parse-error"
export interface GetHistoryResponse {
totalPages: number;
records: HistoryRecord[];
}
export type HistoryRecord = {
comment: string;
createdAt: string;
id: string;
isDeleted: boolean;
key: string;
rawDetails: [RawDetails, KeyValue];
updatedAt: string;
userId: string;
};
type RawDetails = { Key: string; Value: KeyValue[][] }
type KeyValue = { Key: string; Value: string | number };
export async function getHistory(): Promise<[GetHistoryResponse | null, string?]> {
try {
const historyResponse = await makeRequest<never, GetHistoryResponse>({
url: "https://hub.pena.digital/customer/history?page=1&limit=100&type=payCart",
method: "get",
useToken: true,
})
return [historyResponse]
} catch (nativeError) {
const [error] = parseAxiosError(nativeError)
return [null, `Не удалось получить историю. ${error}`]
}
}