45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { adminHttp, adminRequest } from "@/lib/admin-http";
|
|
import { withAdminAuthHeader } from "@/lib/admin-auth";
|
|
import { withAdminLocaleHeaders } from "@/lib/admin-locale";
|
|
|
|
import { API_V1_PREFIX } from "./paths";
|
|
|
|
import type {
|
|
AdminReportJobCreateResponse,
|
|
AdminReportJobListData,
|
|
} from "@/types/api/admin-reports";
|
|
|
|
const A = `${API_V1_PREFIX}/admin`;
|
|
|
|
export async function getAdminReportJobs(params?: {
|
|
page?: number;
|
|
per_page?: number;
|
|
}): Promise<AdminReportJobListData> {
|
|
return adminRequest.get<AdminReportJobListData>(`${A}/report-jobs`, {
|
|
params,
|
|
});
|
|
}
|
|
|
|
export async function postAdminReportJob(body: {
|
|
report_type: string;
|
|
export_format?: "csv" | "xlsx";
|
|
parameters?: Record<string, unknown> | null;
|
|
filter_json?: Record<string, unknown> | null;
|
|
}): Promise<AdminReportJobCreateResponse> {
|
|
return adminRequest.post<AdminReportJobCreateResponse>(
|
|
`${A}/report-jobs`,
|
|
body,
|
|
);
|
|
}
|
|
|
|
export async function downloadAdminReportJob(jobId: number): Promise<Blob> {
|
|
const res = await adminHttp.request<Blob>(
|
|
withAdminAuthHeader(withAdminLocaleHeaders({
|
|
url: `${A}/report-jobs/${jobId}/download`,
|
|
method: "GET",
|
|
responseType: "blob",
|
|
})),
|
|
);
|
|
return res.data;
|
|
}
|