aboutsummaryrefslogtreecommitdiffstats
path: root/api.js
blob: 344196786edc5e88f62005e87bf75dcfeb5bbe51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const API = 'https://apps.pruss.it/api'

export const login = ({ email, password }) => fetch(`${API}/login`, {
  method: 'POST',
  headers: { 'Content-Type': 'plain/text; charset=utf-8' },
  body: JSON.stringify({ email, password })
})

export const getList = ({ session }) => fetch(`${API}/notes`, {
  'Cookie': session.cookies
})

export const getNote = ({ note, session }) => fetch(`${API}/notes/${note.noteId}`, {
  method: 'GET', headers: { 'Cookie': session.cookies },
})

export const createNote = ({ title, content, session }) => fetch(`${API}/notes`, {
  method: 'POST',
  headers: { 'Content-Type': 'plain/text; charset=utf-8', 'Cookie': session.cookies },
  body: JSON.stringify({ title, content })
})

export const editNote = ({ note, title, content, session }) => fetch(`${API}/notes/${note._id}`, {
  method: 'PUT',
  headers: { 'Content-Type': 'plain/text; charset=utf-8', 'Cookie': session.cookies },
  body: JSON.stringify({ title, noteId: note.noteId, content })
})

export const removeNote = ({ note, session }) => fetch(`${API}/notes/${note._id}`, {
  method: 'DELETE', headers: { 'Cookie': session.cookies },
})