65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import { Chart } from '@baseline/types/chart';
|
|
import { getRequestHandler } from './request-handler';
|
|
|
|
export const getChart = async (chartId: string): Promise<Chart> => {
|
|
const response = await getRequestHandler().request<Chart>({
|
|
method: 'GET',
|
|
url: `chart/admin/${chartId}`,
|
|
hasAuthentication: true,
|
|
});
|
|
if ('data' in response) {
|
|
return response.data;
|
|
}
|
|
throw response;
|
|
};
|
|
|
|
export const getAllCharts = async (): Promise<Chart[]> => {
|
|
const response = await getRequestHandler().request<Chart[]>({
|
|
method: 'GET',
|
|
url: `chart/admin/list`,
|
|
hasAuthentication: true,
|
|
});
|
|
if ('data' in response) {
|
|
return response.data;
|
|
}
|
|
throw response;
|
|
};
|
|
|
|
export const deleteChart = async (chartId: string): Promise<boolean> => {
|
|
const response = await getRequestHandler().request<boolean>({
|
|
method: 'DELETE',
|
|
url: `chart/admin/${chartId}`,
|
|
hasAuthentication: true,
|
|
});
|
|
if ('data' in response) {
|
|
return response.data;
|
|
}
|
|
throw response;
|
|
};
|
|
|
|
export const createChart = async (chart: Partial<Chart>): Promise<Chart> => {
|
|
const response = await getRequestHandler().request<Chart>({
|
|
method: 'POST',
|
|
url: `chart/admin`,
|
|
hasAuthentication: true,
|
|
data: chart,
|
|
});
|
|
if ('data' in response) {
|
|
return response.data;
|
|
}
|
|
throw response;
|
|
};
|
|
|
|
export const updateChart = async (chart: Partial<Chart>): Promise<Chart> => {
|
|
const response = await getRequestHandler().request<Chart>({
|
|
method: 'PATCH',
|
|
url: `chart/admin`,
|
|
hasAuthentication: true,
|
|
data: chart,
|
|
});
|
|
if ('data' in response) {
|
|
return response.data;
|
|
}
|
|
throw response;
|
|
};
|