From 994bc43d488eefc0ee39f39dd7fae5515322b17b Mon Sep 17 00:00:00 2001 From: piotrruss Date: Sun, 22 May 2022 13:49:12 +0100 Subject: move api & helpers to utils --- utils/api.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 utils/api.js (limited to 'utils/api.js') diff --git a/utils/api.js b/utils/api.js new file mode 100644 index 0000000..3441967 --- /dev/null +++ b/utils/api.js @@ -0,0 +1,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 }, +}) -- cgit v1.2.3