aretherecookies-mobile/js/apis/FavesApi.js
2020-03-29 19:47:33 +00:00

44 lines
859 B
JavaScript

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,
},
});
});