buster/web/src/api/buster_rest/metrics/requests.ts

122 lines
3.5 KiB
TypeScript
Raw Normal View History

import { mainApi } from '../instances';
import { serverFetch } from '@/api/createServerInstance';
2025-03-11 03:58:50 +08:00
import type {
2025-03-25 01:25:34 +08:00
BusterChartConfigProps,
2025-03-11 03:58:50 +08:00
BusterMetric,
BusterMetricData,
BusterMetricListItem
} from '@/api/asset_interfaces/metric';
2025-03-24 23:51:30 +08:00
import type {
2025-03-20 06:22:46 +08:00
ShareDeleteRequest,
SharePostRequest,
ShareUpdateRequest
} from '@/api/asset_interfaces/shared_interfaces';
2025-03-24 23:51:30 +08:00
import { VerificationStatus } from '@/api/asset_interfaces/share';
2025-03-25 01:25:34 +08:00
export const getMetric = async ({
id,
password,
version_number
}: {
id: string;
password?: string;
version_number?: number; //api will default to latest if not provided
}) => {
return mainApi
2025-03-12 07:01:39 +08:00
.get<BusterMetric>(`/metrics/${id}`, {
2025-03-20 01:06:52 +08:00
params: { password, version_number }
})
.then((res) => res.data);
};
2025-03-25 01:25:34 +08:00
export const getMetric_server = async ({ id, password }: Parameters<typeof getMetric>[0]) => {
2025-03-12 07:01:39 +08:00
return await serverFetch<BusterMetric>(`/metrics/${id}`, {
params: { ...(password && { password }) }
});
};
2025-03-20 04:47:15 +08:00
export const getMetricData = async ({
id,
version_number
}: {
id: string;
version_number?: number;
}) => {
return mainApi
.get<BusterMetricData>(`/metrics/${id}/data`, { params: { version_number } })
.then((res) => res.data);
2025-03-12 07:01:39 +08:00
};
2025-03-24 23:51:30 +08:00
export const listMetrics = async (params: {
/** The token representing the current page number for pagination */
page_token: number;
/** The number of items to return per page */
page_size: number;
/** Filtering options for metrics based on verification status */
status?: VerificationStatus[] | null;
}) => {
2025-03-12 23:21:54 +08:00
return mainApi.get<BusterMetricListItem[]>('/metrics', { params }).then((res) => res.data);
};
2025-03-24 23:51:30 +08:00
export const listMetrics_server = async (params: Parameters<typeof listMetrics>[0]) => {
2025-03-12 23:21:54 +08:00
return await serverFetch<BusterMetricListItem[]>('/metrics', { params });
};
2025-03-11 03:58:50 +08:00
2025-03-25 01:25:34 +08:00
export const updateMetric = async (params: {
/** The unique identifier of the metric to update */
id: string;
/** New title for the metric */
name?: string;
/** SQL query associated with the metric */
sql?: string;
chart_config?: BusterChartConfigProps;
/** Flag to save the current draft state */
save_draft?: boolean;
/** Admin only: verification status update */
status?: VerificationStatus;
/** file in yaml format to update */
file?: string;
2025-03-27 00:40:26 +08:00
/** update the version number of the metric - default is true */
update_version?: boolean;
/** restore the metric to a specific version */
restore_to_version?: number;
2025-03-25 01:25:34 +08:00
}) => {
2025-03-15 04:04:10 +08:00
return mainApi.put<BusterMetric>(`/metrics/${params.id}`, params).then((res) => res.data);
};
export const deleteMetrics = async (params: { ids: string[] }) => {
2025-03-24 23:51:30 +08:00
return mainApi
.delete<null>(`/metrics`, {
data: { ids: params.ids }
})
.then((res) => res.data);
};
2025-03-11 23:38:49 +08:00
export const duplicateMetric = async (params: {
id: string;
message_id: string;
share_with_same_people: boolean;
}) => {
2025-03-19 12:29:46 +08:00
return mainApi.post<BusterMetric>(`/metrics/duplicate`, params).then((res) => res.data);
};
2025-03-20 06:22:46 +08:00
// share metrics
export const shareMetric = async ({ id, params }: { id: string; params: SharePostRequest }) => {
return mainApi.post<BusterMetric>(`/metrics/${id}/sharing`, params).then((res) => res.data);
};
export const unshareMetric = async ({ id, data }: { id: string; data: ShareDeleteRequest }) => {
return mainApi.delete<BusterMetric>(`/metrics/${id}/sharing`, { data }).then((res) => res.data);
};
export const updateMetricShare = async ({
params,
id
}: {
id: string;
params: ShareUpdateRequest;
}) => {
2025-03-20 06:32:41 +08:00
return mainApi.put<BusterMetric>(`/metrics/${id}/sharing`, params).then((res) => res.data);
2025-03-20 06:22:46 +08:00
};