53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
import { DashboardContent } from '@/utils/dashboard/parseDashboard'
|
|
import { request } from './request'
|
|
|
|
export type DashboardInfo = {
|
|
id: number
|
|
name: string
|
|
contents: string
|
|
}
|
|
|
|
export const getDashboards = () => request<DashboardInfo[]>('/api/dashboards')
|
|
|
|
export const getDashboard = (id: number) =>
|
|
request<DashboardInfo>(`/api/dashboards/${id}`)
|
|
|
|
export const createDashboard = (body: {
|
|
name: 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: number
|
|
name: string
|
|
contents: DashboardContent
|
|
}) =>
|
|
request<DashboardInfo>(`/api/dashboards/${id}`, {
|
|
method: 'PUT',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify({
|
|
...body,
|
|
contents: JSON.stringify(body.contents),
|
|
}),
|
|
})
|
|
|
|
export const deleteDashboard = (id: number) =>
|
|
request<DashboardInfo>(
|
|
`/api/dashboards/${id}`,
|
|
{
|
|
method: 'DELETE',
|
|
},
|
|
'void'
|
|
)
|