diff --git a/src/client/src/app/actions/account/addFavoriteRecipe.ts b/src/client/src/app/actions/account/addFavoriteRecipe.ts index 8727d5e..ad55525 100644 --- a/src/client/src/app/actions/account/addFavoriteRecipe.ts +++ b/src/client/src/app/actions/account/addFavoriteRecipe.ts @@ -4,19 +4,24 @@ import { thunkErrorWrapper } from '../../utils/thunkErrorWrapper'; import { RecipeModel } from '../../../services/models/RecipeModel'; export const addFavoriteRecipe = createAppAsyncThunk( 'account/addFavoriteRecipe', - async ({ userId, recipe }, thunkAPI) => { + async (recipe, thunkAPI) => { + const user = thunkAPI.getState().account.user; + const token = thunkAPI.getState().account.token; if (!thunkAPI.extra.userService.token) { - thunkAPI.extra.userService.setToken(thunkAPI.getState().account.token); + thunkAPI.extra.userService.setToken(token); + } + if (!user) { + return thunkAPI.rejectWithValue(new Error('No user provided')); } const thunk = thunkErrorWrapper( thunkAPI.extra.userService.addFavoriteRecipe, thunkAPI.rejectWithValue, thunkAPI.extra.userService ); - await thunk(userId, recipe.id); + await thunk(user.id, recipe.id); return recipe; }, ); diff --git a/src/client/src/app/actions/account/deleteFavoriteRecipe.ts b/src/client/src/app/actions/account/deleteFavoriteRecipe.ts index fb46831..1d1b67c 100644 --- a/src/client/src/app/actions/account/deleteFavoriteRecipe.ts +++ b/src/client/src/app/actions/account/deleteFavoriteRecipe.ts @@ -4,19 +4,24 @@ import { thunkErrorWrapper } from '../../utils/thunkErrorWrapper'; import { RecipeModel } from '../../../services/models/RecipeModel'; export const deleteFavoriteRecipe = createAppAsyncThunk( 'account/deleteFavoriteRecipe', - async ({ recipe }, thunkAPI) => { + async (recipe, thunkAPI) => { + const user = thunkAPI.getState().account.user; + const token = thunkAPI.getState().account.token; if (!thunkAPI.extra.userService.token) { - thunkAPI.extra.userService.setToken(thunkAPI.getState().account.token); + thunkAPI.extra.userService.setToken(token); + } + if (!user) { + return thunkAPI.rejectWithValue(new Error('No user provided')); } const thunk = thunkErrorWrapper( thunkAPI.extra.userService.deleteFavoriteRecipe, thunkAPI.rejectWithValue, thunkAPI.extra.userService ); - await thunk(recipe.id); + await thunk(user.id, recipe.id); return recipe; }, );