From 3da18b699e15e0cacbaaaf0d30b900eddfa82af8 Mon Sep 17 00:00:00 2001 From: akaeyuhi <54174780+akaeyuhi@users.noreply.github.com> Date: Wed, 14 Jun 2023 17:29:42 +0300 Subject: [PATCH] fix: fixed thunk and service arguments --- .../src/app/actions/account/addFavoriteRecipe.ts | 13 +++++++++---- .../src/app/actions/account/deleteFavoriteRecipe.ts | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) 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; }, );