/* * 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 => { const response = await fetch(getApiUrl() + 'me/history') expectResponseCode(response) return await response.json() as Promise } export const postHistory = async (entries: HistoryEntryPutDto[]): Promise => { 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 => { const response = await fetch(getApiUrl() + 'me/history/' + noteId, { ...defaultFetchConfig, method: 'PUT', body: JSON.stringify(entry) }) expectResponseCode(response) } export const deleteHistoryEntry = async (noteId: string): Promise => { const response = await fetch(getApiUrl() + 'me/history/' + noteId, { ...defaultFetchConfig, method: 'DELETE' }) expectResponseCode(response) } export const deleteHistory = async (): Promise => { const response = await fetch(getApiUrl() + 'me/history', { ...defaultFetchConfig, method: 'DELETE' }) expectResponseCode(response) }