Fix Communication between frontend and backend (#1201)

Co-authored-by: Tilman Vatteroth <git@tilmanvatteroth.de>
Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Philip Molares 2021-05-01 23:01:42 +02:00 committed by GitHub
parent 4a18e51c83
commit 9cf7980334
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 268 additions and 164 deletions

View file

@ -5,31 +5,17 @@
*/
import { defaultFetchConfig, expectResponseCode, getApiUrl } from '../utils'
import { NoteDto } from './types'
import { isMockMode } from '../../utils/test-modes'
interface LastChange {
userId: string
timestamp: number
}
export interface Note {
id: string
alias: string
lastChange: LastChange
viewCount: number
createTime: number
content: string
authorship: number[]
preVersionTwoNote: boolean
}
export const getNote = async (noteId: string): Promise<Note> => {
export const getNote = async (noteId: string): Promise<NoteDto> => {
// The "-get" suffix is necessary, because in our mock api (filesystem) the note id might already be a folder.
// TODO: [mrdrogdrog] replace -get with actual api route as soon as api backend is ready.
const response = await fetch(getApiUrl() + `/notes/${ noteId }-get`, {
const response = await fetch(getApiUrl() + `/notes/${ noteId }${ isMockMode() ? '-get' : '' }`, {
...defaultFetchConfig
})
expectResponseCode(response)
return await response.json() as Promise<Note>
return await response.json() as Promise<NoteDto>
}
export const deleteNote = async (noteId: string): Promise<void> => {