2022-08-28 22:52:57 +02:00
|
|
|
import { DashboardContent } from '@/utils/dashboard/parseDashboard'
|
2022-08-23 23:35:36 +02:00
|
|
|
import { request } from './request'
|
|
|
|
|
|
|
|
|
|
export type DashboardInfo = {
|
|
|
|
|
id: string
|
|
|
|
|
contents: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const getDashboards = () => request<DashboardInfo[]>('/api/dashboards')
|
|
|
|
|
|
|
|
|
|
export const getDashboard = (id: string) =>
|
|
|
|
|
request<DashboardInfo>(`/api/dashboards/${encodeURI(id)}`)
|
|
|
|
|
|
|
|
|
|
export const createDashboard = (body: {
|
|
|
|
|
id: string
|
|
|
|
|
contents: DashboardContent
|
|
|
|
|
}) =>
|
|
|
|
|
request<DashboardInfo>(`/api/dashboards`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'content-type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
...body,
|
|
|
|
|
contents: JSON.stringify(body.contents),
|
|
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const updateDashboard = ({
|
|
|
|
|
id,
|
|
|
|
|
...body
|
|
|
|
|
}: {
|
|
|
|
|
id: string
|
|
|
|
|
contents: DashboardContent
|
|
|
|
|
}) =>
|
|
|
|
|
request<DashboardInfo>(`/api/dashboards/${encodeURI(id)}`, {
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
headers: { 'content-type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
...body,
|
|
|
|
|
contents: JSON.stringify(body.contents),
|
|
|
|
|
}),
|
|
|
|
|
})
|