mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 09:54:55 -06:00
44 lines
859 B
JavaScript
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,
|
|
},
|
|
});
|
|
});
|