Skip to content

Commit

Permalink
fix: fixed thunk and service arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
akaeyuhi committed Jun 14, 2023
1 parent 4fe0d01 commit 3da18b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/client/src/app/actions/account/addFavoriteRecipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ import { thunkErrorWrapper } from '../../utils/thunkErrorWrapper';
import { RecipeModel } from '../../../services/models/RecipeModel';

export const addFavoriteRecipe = createAppAsyncThunk<RecipeModel,
{ userId: number, recipe: RecipeModel },
RecipeModel,
{ rejectValue: AuthStoreError }>(
'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;
},
);
13 changes: 9 additions & 4 deletions src/client/src/app/actions/account/deleteFavoriteRecipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ import { thunkErrorWrapper } from '../../utils/thunkErrorWrapper';
import { RecipeModel } from '../../../services/models/RecipeModel';

export const deleteFavoriteRecipe = createAppAsyncThunk<RecipeModel,
{ recipe : RecipeModel },
RecipeModel,
{ rejectValue: AuthStoreError }>(
'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;
},
);

0 comments on commit 3da18b6

Please sign in to comment.