hedgedoc/src/api/history/index.ts
Tilman Vatteroth a48b4f60bb
Change schema of url environment variables (#1237)
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2021-05-05 22:33:30 +02:00

48 lines
1.5 KiB
TypeScript

/*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
import { HistoryEntryDto, HistoryEntryPutDto, HistoryEntryUpdateDto } from './types'
export const getHistory = async (): Promise<HistoryEntryDto[]> => {
const response = await fetch(getApiUrl() + 'me/history')
expectResponseCode(response)
return await response.json() as Promise<HistoryEntryDto[]>
}
export const postHistory = async (entries: HistoryEntryPutDto[]): Promise<void> => {
const response = await fetch(getApiUrl() + 'me/history', {
...defaultFetchConfig,
method: 'POST',
body: JSON.stringify(entries)
})
expectResponseCode(response)
}
export const updateHistoryEntryPinStatus = async (noteId: string, entry: HistoryEntryUpdateDto): Promise<void> => {
const response = await fetch(getApiUrl() + 'me/history/' + noteId, {
...defaultFetchConfig,
method: 'PUT',
body: JSON.stringify(entry)
})
expectResponseCode(response)
}
export const deleteHistoryEntry = async (noteId: string): Promise<void> => {
const response = await fetch(getApiUrl() + 'me/history/' + noteId, {
...defaultFetchConfig,
method: 'DELETE'
})
expectResponseCode(response)
}
export const deleteHistory = async (): Promise<void> => {
const response = await fetch(getApiUrl() + 'me/history', {
...defaultFetchConfig,
method: 'DELETE'
})
expectResponseCode(response)
}