mirror of
https://gitlab.com/wheres-the-tp/ui-mobile.git
synced 2026-01-25 04:24:56 -06:00
45 lines
876 B
JavaScript
45 lines
876 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, productId, photoUrl) => {
|
|
return fetchRequest({
|
|
endpoint: '/fave',
|
|
method: 'PUT',
|
|
body: {
|
|
email,
|
|
productId,
|
|
photoUrl,
|
|
},
|
|
});
|
|
});
|
|
|
|
export const deleteFaves = withLoggedInEmail(async (email, productIds) => {
|
|
return fetchRequest({
|
|
endpoint: '/fave',
|
|
method: 'DELETE',
|
|
body: {
|
|
email,
|
|
productIds,
|
|
},
|
|
});
|
|
});
|