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 { apiReq };
export { baseURL }; export { baseURL };

View file

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

View file

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

View file

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