42 lines
955 B
TypeScript
42 lines
955 B
TypeScript
|
|
import { DashboardContent } from '@/utils/parseDashboard'
|
||
|
|
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),
|
||
|
|
}),
|
||
|
|
})
|