dispatch evens for CRUD operations

This commit is contained in:
hay-kot 2021-03-30 17:40:24 -08:00
commit d74b835be7
4 changed files with 9 additions and 5 deletions

View file

@ -63,5 +63,7 @@ const apiReq = {
},
};
export { apiReq };
export { baseURL };

View file

@ -1,6 +1,6 @@
import { baseURL } from "./api-utils";
import { apiReq } from "./api-utils";
import { store } from "../store";
import { store } from "@/store";
const backupBase = baseURL + "backups/";

View file

@ -1,5 +1,6 @@
import { baseURL } from "./api-utils";
import { apiReq } from "./api-utils";
import { store } from "@/store";
const prefix = baseURL + "categories";
@ -20,6 +21,7 @@ export const categoryAPI = {
},
async delete(category) {
let response = await apiReq.delete(categoryURLs.delete_category(category));
store.dispatch("requestCategories");
return response.data;
},
};
@ -43,6 +45,7 @@ export const tagAPI = {
},
async delete(tag) {
let response = await apiReq.delete(tagURLs.deleteTag(tag));
store.dispatch("requestTags");
return response.data;
},
};

View file

@ -43,6 +43,7 @@ export const recipeAPI = {
async create(recipeData) {
let response = await apiReq.post(recipeURLs.create, recipeData);
store.dispatch("requestRecentRecipes");
return response.data;
},
@ -62,15 +63,13 @@ export const recipeAPI = {
},
async update(data) {
const recipeSlug = data.slug;
let response = await apiReq.put(recipeURLs.update(recipeSlug), data);
let response = await apiReq.put(recipeURLs.update(data.slug), data);
store.dispatch("requestRecentRecipes");
return response.data;
},
async delete(recipeSlug) {
apiReq.delete(recipeURLs.delete(recipeSlug));
await apiReq.delete(recipeURLs.delete(recipeSlug));
store.dispatch("requestRecentRecipes");
router.push(`/`);
},