import { fetchRequest } from './FetchApi'; import AuthManager from '../AuthManager'; const withLoggedInEmail = fn => async (...args) => { await AuthManager.checkIsAuthed(); const email = AuthManager.getEmail(); if (!email) { throw new Error('you must be logged in to view favorites'); } return fn(email, ...args); }; export const fetchFaves = withLoggedInEmail(async email => { return fetchRequest({ endpoint: `/faves`, method: 'POST', body: { email }, }); }); export const putFaves = withLoggedInEmail(async (email, foodItemIds) => { return fetchRequest({ endpoint: '/fave', method: 'PUT', body: { email, foodItemIds, }, }); }); export const deleteFaves = withLoggedInEmail(async (email, foodItemIds) => { return fetchRequest({ endpoint: '/fave', method: 'DELETE', body: { email, foodItemIds, }, }); });