bms-repository/shared/client-api/chart.ts
pfych 0029086b3f
Some checks failed
Build & Lint / build-lint (push) Failing after 2m10s
Deploy / setup (push) Failing after 1m3s
Init
2024-10-12 14:08:09 +11:00

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;
};