mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-11-26 05:34:21 -05:00
feature/recipe-patch-improvements (#382)
* automated docs update * recipe rating component * recipe partial updates - closes #25 * use Vue.delete to update store * format * arrow functions * fix tests * format * initial context menu * localize * add confirmation dialog * context menu * fix bare exception * update line length * format all file with prettier * update changelog * download as json * update python dependencies * update javascript dependencies Co-authored-by: hay-kot <hay-kot@pm.me>
This commit is contained in:
@@ -3,18 +3,16 @@ import axios from "axios";
|
||||
import { store } from "../store";
|
||||
import utils from "@/utils";
|
||||
|
||||
axios.defaults.headers.common[
|
||||
"Authorization"
|
||||
] = `Bearer ${store.getters.getToken}`;
|
||||
axios.defaults.headers.common["Authorization"] = `Bearer ${store.getters.getToken}`;
|
||||
|
||||
function handleError(error, getText) {
|
||||
if(getText) {
|
||||
if (getText) {
|
||||
utils.notify.error(getText(error.response));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function handleResponse(response, getText) {
|
||||
if(response && getText) {
|
||||
if (response && getText) {
|
||||
const successText = getText(response);
|
||||
utils.notify.success(successText);
|
||||
}
|
||||
@@ -31,26 +29,36 @@ function defaultSuccessText(response) {
|
||||
|
||||
const apiReq = {
|
||||
post: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||
const response = await axios.post(url, data).catch(function(error) { handleError(error, getErrorText) });
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
put: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||
const response = await axios.put(url, data).catch(function(error) { handleError(error, getErrorText) });
|
||||
const response = await axios.post(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
|
||||
put: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||
const response = await axios.put(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
patch: async function(url, data, getErrorText = defaultErrorText, getSuccessText) {
|
||||
const response = await axios.patch(url, data).catch(function(error) { handleError(error, getErrorText) });
|
||||
const response = await axios.patch(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
get: function(url, data, getErrorText = defaultErrorText) {
|
||||
return axios.get(url, data).catch(function(error) { handleError(error, getErrorText) });
|
||||
return axios.get(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
},
|
||||
|
||||
delete: async function(url, data, getErrorText = defaultErrorText, getSuccessText = defaultSuccessText ) {
|
||||
const response = await axios.delete(url, data).catch( function(error) { handleError(error, getErrorText) } );
|
||||
delete: async function(url, data, getErrorText = defaultErrorText, getSuccessText = defaultSuccessText) {
|
||||
const response = await axios.delete(url, data).catch(function(error) {
|
||||
handleError(error, getErrorText);
|
||||
});
|
||||
return handleResponse(response, getSuccessText);
|
||||
},
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import { store } from "@/store";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
|
||||
const backupBase = baseURL + "backups/";
|
||||
|
||||
@@ -14,8 +14,6 @@ export const backupURLs = {
|
||||
downloadBackup: fileName => `${backupBase}${fileName}/download`,
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const backupAPI = {
|
||||
/**
|
||||
* Request all backups available on the server
|
||||
@@ -44,8 +42,8 @@ export const backupAPI = {
|
||||
return apiReq.delete(
|
||||
backupURLs.deleteBackup(fileName),
|
||||
null,
|
||||
function() { return i18n.t('settings.backup.unable-to-delete-backup'); },
|
||||
function() { return i18n.t('settings.backup.backup-deleted'); }
|
||||
() => i18n.t("settings.backup.unable-to-delete-backup"),
|
||||
() => i18n.t("settings.backup.backup-deleted")
|
||||
);
|
||||
},
|
||||
/**
|
||||
@@ -55,10 +53,12 @@ export const backupAPI = {
|
||||
*/
|
||||
async create(options) {
|
||||
return apiReq.post(
|
||||
backupURLs.createBackup,
|
||||
backupURLs.createBackup,
|
||||
options,
|
||||
function() { return i18n.t('settings.backup.error-creating-backup-see-log-file'); },
|
||||
function(response) { return i18n.t('settings.backup.backup-created-at-response-export_path', {path: response.data.export_path}); }
|
||||
() => i18n.t("settings.backup.error-creating-backup-see-log-file"),
|
||||
response => {
|
||||
return i18n.t("settings.backup.backup-created-at-response-export_path", { path: response.data.export_path });
|
||||
}
|
||||
);
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import { store } from "@/store";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
|
||||
const prefix = baseURL + "categories";
|
||||
|
||||
@@ -24,12 +24,12 @@ export const categoryAPI = {
|
||||
},
|
||||
async create(name) {
|
||||
const response = await apiReq.post(
|
||||
categoryURLs.getAll,
|
||||
categoryURLs.getAll,
|
||||
{ name: name },
|
||||
function() { return i18n.t('category.category-creation-failed'); },
|
||||
function() { return i18n.t('category.category-created'); }
|
||||
() => i18n.t("category.category-creation-failed"),
|
||||
() => i18n.t("category.category-created")
|
||||
);
|
||||
if(response) {
|
||||
if (response) {
|
||||
store.dispatch("requestCategories");
|
||||
return response.data;
|
||||
}
|
||||
@@ -40,10 +40,10 @@ export const categoryAPI = {
|
||||
},
|
||||
async update(name, newName, overrideRequest = false) {
|
||||
const response = await apiReq.put(
|
||||
categoryURLs.updateCategory(name),
|
||||
categoryURLs.updateCategory(name),
|
||||
{ name: newName },
|
||||
function() { return i18n.t('category.category-update-failed'); },
|
||||
function() { return i18n.t('category.category-updated'); }
|
||||
() => i18n.t("category.category-update-failed"),
|
||||
() => i18n.t("category.category-updated")
|
||||
);
|
||||
if (response && !overrideRequest) {
|
||||
store.dispatch("requestCategories");
|
||||
@@ -54,8 +54,8 @@ export const categoryAPI = {
|
||||
const response = await apiReq.delete(
|
||||
categoryURLs.deleteCategory(category),
|
||||
null,
|
||||
function() { return i18n.t('category.category-deletion-failed'); },
|
||||
function() { return i18n.t('category.category-deleted'); }
|
||||
() => i18n.t("category.category-deletion-failed"),
|
||||
() => i18n.t("category.category-deleted")
|
||||
);
|
||||
if (response && !overrideRequest) {
|
||||
store.dispatch("requestCategories");
|
||||
@@ -85,12 +85,12 @@ export const tagAPI = {
|
||||
},
|
||||
async create(name) {
|
||||
const response = await apiReq.post(
|
||||
tagURLs.getAll,
|
||||
tagURLs.getAll,
|
||||
{ name: name },
|
||||
function() { return i18n.t('tag.tag-creation-failed'); },
|
||||
function() { return i18n.t('tag.tag-created'); }
|
||||
() => i18n.t("tag.tag-creation-failed"),
|
||||
() => i18n.t("tag.tag-created")
|
||||
);
|
||||
if(response) {
|
||||
if (response) {
|
||||
store.dispatch("requestTags");
|
||||
return response.data;
|
||||
}
|
||||
@@ -101,13 +101,13 @@ export const tagAPI = {
|
||||
},
|
||||
async update(name, newName, overrideRequest = false) {
|
||||
const response = await apiReq.put(
|
||||
tagURLs.updateTag(name),
|
||||
tagURLs.updateTag(name),
|
||||
{ name: newName },
|
||||
function() { return i18n.t('tag.tag-update-failed'); },
|
||||
function() { return i18n.t('tag.tag-updated'); }
|
||||
() => i18n.t("tag.tag-update-failed"),
|
||||
() => i18n.t("tag.tag-updated")
|
||||
);
|
||||
|
||||
if(response) {
|
||||
if (response) {
|
||||
if (!overrideRequest) {
|
||||
store.dispatch("requestTags");
|
||||
}
|
||||
@@ -118,10 +118,10 @@ export const tagAPI = {
|
||||
const response = await apiReq.delete(
|
||||
tagURLs.deleteTag(tag),
|
||||
null,
|
||||
function() { return i18n.t('tag.tag-deletion-failed'); },
|
||||
function() { return i18n.t('tag.tag-deleted'); }
|
||||
() => i18n.t("tag.tag-deletion-failed"),
|
||||
() => i18n.t("tag.tag-deleted")
|
||||
);
|
||||
if(response) {
|
||||
if (response) {
|
||||
if (!overrideRequest) {
|
||||
store.dispatch("requestTags");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
const groupPrefix = baseURL + "groups";
|
||||
|
||||
const groupsURLs = {
|
||||
@@ -12,18 +12,18 @@ const groupsURLs = {
|
||||
};
|
||||
|
||||
function deleteErrorText(response) {
|
||||
switch(response.data.detail) {
|
||||
case 'GROUP_WITH_USERS':
|
||||
return i18n.t('group.cannot-delete-group-with-users');
|
||||
|
||||
case 'GROUP_NOT_FOUND':
|
||||
return i18n.t('group.group-not-found');
|
||||
|
||||
case 'DEFAULT_GROUP':
|
||||
return i18n.t('group.cannot-delete-default-group');
|
||||
switch (response.data.detail) {
|
||||
case "GROUP_WITH_USERS":
|
||||
return i18n.t("group.cannot-delete-group-with-users");
|
||||
|
||||
case "GROUP_NOT_FOUND":
|
||||
return i18n.t("group.group-not-found");
|
||||
|
||||
case "DEFAULT_GROUP":
|
||||
return i18n.t("group.cannot-delete-default-group");
|
||||
|
||||
default:
|
||||
return i18n.t('group.group-deletion-failed');
|
||||
return i18n.t("group.group-deletion-failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,33 +36,27 @@ export const groupAPI = {
|
||||
return apiReq.post(
|
||||
groupsURLs.create,
|
||||
{ name: name },
|
||||
function() { return i18n.t('group.user-group-creation-failed'); },
|
||||
function() { return i18n.t('group.user-group-created'); }
|
||||
() => i18n.t("group.user-group-creation-failed"),
|
||||
() => i18n.t("group.user-group-created")
|
||||
);
|
||||
},
|
||||
delete(id) {
|
||||
return apiReq.delete(
|
||||
groupsURLs.delete(id),
|
||||
null,
|
||||
deleteErrorText,
|
||||
function() { return i18n.t('group.group-deleted'); }
|
||||
);
|
||||
return apiReq.delete(groupsURLs.delete(id), null, deleteErrorText, function() {
|
||||
return i18n.t("group.group-deleted");
|
||||
});
|
||||
},
|
||||
async current() {
|
||||
const response = await apiReq.get(
|
||||
groupsURLs.current,
|
||||
null,
|
||||
null);
|
||||
if(response) {
|
||||
const response = await apiReq.get(groupsURLs.current, null, null);
|
||||
if (response) {
|
||||
return response.data;
|
||||
}
|
||||
},
|
||||
update(data) {
|
||||
return apiReq.put(
|
||||
groupsURLs.update(data.id),
|
||||
data,
|
||||
function() { return i18n.t('group.error-updating-group'); },
|
||||
function() { return i18n.t('settings.group-settings-updated'); }
|
||||
groupsURLs.update(data.id),
|
||||
data,
|
||||
() => i18n.t("group.error-updating-group"),
|
||||
() => i18n.t("settings.group-settings-updated")
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
|
||||
const prefix = baseURL + "meal-plans/";
|
||||
|
||||
@@ -18,10 +18,10 @@ const mealPlanURLs = {
|
||||
export const mealplanAPI = {
|
||||
create(postBody) {
|
||||
return apiReq.post(
|
||||
mealPlanURLs.create,
|
||||
mealPlanURLs.create,
|
||||
postBody,
|
||||
function() { return i18n.t('meal-plan.mealplan-creation-failed')},
|
||||
function() { return i18n.t('meal-plan.mealplan-created'); }
|
||||
() => i18n.t("meal-plan.mealplan-creation-failed"),
|
||||
() => i18n.t("meal-plan.mealplan-created")
|
||||
);
|
||||
},
|
||||
|
||||
@@ -41,19 +41,20 @@ export const mealplanAPI = {
|
||||
},
|
||||
|
||||
delete(id) {
|
||||
return apiReq.delete(mealPlanURLs.delete(id),
|
||||
return apiReq.delete(
|
||||
mealPlanURLs.delete(id),
|
||||
null,
|
||||
function() { return i18n.t('meal-plan.mealplan-deletion-failed'); },
|
||||
function() { return i18n.t('meal-plan.mealplan-deleted'); }
|
||||
() => i18n.t("meal-plan.mealplan-deletion-failed"),
|
||||
() => i18n.t("meal-plan.mealplan-deleted")
|
||||
);
|
||||
},
|
||||
|
||||
update(id, body) {
|
||||
return apiReq.put(
|
||||
mealPlanURLs.update(id),
|
||||
mealPlanURLs.update(id),
|
||||
body,
|
||||
function() { return i18n.t('meal-plan.mealplan-update-failed'); },
|
||||
function() { return i18n.t('meal-plan.mealplan-updated'); }
|
||||
() => i18n.t("meal-plan.mealplan-update-failed"),
|
||||
() => i18n.t("meal-plan.mealplan-updated")
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import { store } from "../store";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
|
||||
const migrationBase = baseURL + "migrations";
|
||||
|
||||
@@ -21,8 +21,8 @@ export const migrationAPI = {
|
||||
const response = await apiReq.delete(
|
||||
migrationURLs.delete(folder, file),
|
||||
null,
|
||||
function() { return i18n.t('general.file-folder-not-found'); },
|
||||
function() { return i18n.t('migration.migration-data-removed'); }
|
||||
() => i18n.t("general.file-folder-not-found"),
|
||||
() => i18n.t("migration.migration-data-removed")
|
||||
);
|
||||
return response;
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import { store } from "../store";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
|
||||
const prefix = baseURL + "recipes/";
|
||||
|
||||
@@ -27,10 +27,10 @@ export const recipeAPI = {
|
||||
*/
|
||||
async createByURL(recipeURL) {
|
||||
const response = await apiReq.post(
|
||||
recipeURLs.createByURL,
|
||||
recipeURLs.createByURL,
|
||||
{ url: recipeURL },
|
||||
function() { return i18n.t('recipe.recipe-creation-failed'); },
|
||||
function() { return i18n.t('recipe.recipe-created'); }
|
||||
() => i18n.t("recipe.recipe-creation-failed"),
|
||||
() => i18n.t("recipe.recipe-created")
|
||||
);
|
||||
|
||||
store.dispatch("requestRecentRecipes");
|
||||
@@ -38,19 +38,16 @@ export const recipeAPI = {
|
||||
},
|
||||
|
||||
async getAllByCategory(categories) {
|
||||
let response = await apiReq.post(
|
||||
recipeURLs.allRecipesByCategory,
|
||||
categories
|
||||
);
|
||||
let response = await apiReq.post(recipeURLs.allRecipesByCategory, categories);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
async create(recipeData) {
|
||||
const response = await apiReq.post(
|
||||
recipeURLs.create,
|
||||
recipeURLs.create,
|
||||
recipeData,
|
||||
function() { return i18n.t('recipe.recipe-creation-failed'); },
|
||||
function() { return i18n.t('recipe.recipe-created'); }
|
||||
() => i18n.t("recipe.recipe-creation-failed"),
|
||||
() => i18n.t("recipe.recipe-created")
|
||||
);
|
||||
store.dispatch("requestRecentRecipes");
|
||||
return response.data;
|
||||
@@ -67,18 +64,20 @@ export const recipeAPI = {
|
||||
formData.append("extension", fileObject.name.split(".").pop());
|
||||
|
||||
let successMessage = null;
|
||||
if(!overrideSuccessMsg) {
|
||||
successMessage = function() { return overrideSuccessMsg ? null : i18n.t('recipe.recipe-image-updated'); };
|
||||
if (!overrideSuccessMsg) {
|
||||
successMessage = function() {
|
||||
return overrideSuccessMsg ? null : i18n.t("recipe.recipe-image-updated");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return apiReq.put(
|
||||
recipeURLs.updateImage(recipeSlug),
|
||||
recipeURLs.updateImage(recipeSlug),
|
||||
formData,
|
||||
function() { return i18n.t('general.image-upload-failed'); },
|
||||
() => i18n.t("general.image-upload-failed"),
|
||||
successMessage
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
async createAsset(recipeSlug, fileObject, name, icon) {
|
||||
const fd = new FormData();
|
||||
fd.append("file", fileObject);
|
||||
@@ -88,24 +87,24 @@ export const recipeAPI = {
|
||||
let response = apiReq.post(recipeURLs.createAsset(recipeSlug), fd);
|
||||
return response;
|
||||
},
|
||||
|
||||
|
||||
updateImagebyURL(slug, url) {
|
||||
return apiReq.post(
|
||||
recipeURLs.updateImage(slug),
|
||||
recipeURLs.updateImage(slug),
|
||||
{ url: url },
|
||||
function() { return i18n.t('general.image-upload-failed'); },
|
||||
function() { return i18n.t('recipe.recipe-image-updated'); }
|
||||
() => i18n.t("general.image-upload-failed"),
|
||||
() => i18n.t("recipe.recipe-image-updated")
|
||||
);
|
||||
},
|
||||
|
||||
async update(data) {
|
||||
let response = await apiReq.put(
|
||||
recipeURLs.update(data.slug),
|
||||
data,
|
||||
function() { return i18n.t('recipe.recipe-update-failed'); },
|
||||
function() { return i18n.t('recipe.recipe-updated'); }
|
||||
data,
|
||||
() => i18n.t("recipe.recipe-update-failed"),
|
||||
() => i18n.t("recipe.recipe-updated")
|
||||
);
|
||||
if(response) {
|
||||
if (response) {
|
||||
store.dispatch("patchRecipe", response.data);
|
||||
return response.data.slug; // ! Temporary until I rewrite to refresh page without additional request
|
||||
}
|
||||
@@ -117,13 +116,15 @@ export const recipeAPI = {
|
||||
return response.data;
|
||||
},
|
||||
|
||||
delete(recipeSlug) {
|
||||
return apiReq.delete(
|
||||
async delete(recipeSlug) {
|
||||
const response = await apiReq.delete(
|
||||
recipeURLs.delete(recipeSlug),
|
||||
null,
|
||||
function() { return i18n.t('recipe.unable-to-delete-recipe'); },
|
||||
function() { return i18n.t('recipe.recipe-deleted'); }
|
||||
() => i18n.t("recipe.unable-to-delete-recipe"),
|
||||
() => i18n.t("recipe.recipe-deleted")
|
||||
);
|
||||
store.dispatch("dropRecipe", response.data);
|
||||
return response;
|
||||
},
|
||||
|
||||
async allSummary(start = 0, limit = 9999) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
|
||||
const signUpPrefix = baseURL + "users/sign-ups";
|
||||
|
||||
@@ -18,24 +18,27 @@ export const signupAPI = {
|
||||
},
|
||||
async createToken(data) {
|
||||
let response = await apiReq.post(
|
||||
signUpURLs.createToken,
|
||||
signUpURLs.createToken,
|
||||
data,
|
||||
function() { return i18n.t('signup.sign-up-link-creation-failed'); },
|
||||
function() { return i18n.t('signup.sign-up-link-created'); }
|
||||
() => i18n.t("signup.sign-up-link-creation-failed"),
|
||||
() => i18n.t("signup.sign-up-link-created")
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
async deleteToken(token) {
|
||||
return await apiReq.delete(signUpURLs.deleteToken(token),
|
||||
null,
|
||||
function() { return i18n.t('signup.sign-up-token-deletion-failed'); },
|
||||
function() { return i18n.t('signup.sign-up-token-deleted'); }
|
||||
return await apiReq.delete(
|
||||
signUpURLs.deleteToken(token),
|
||||
null,
|
||||
() => i18n.t("signup.sign-up-token-deletion-failed"),
|
||||
() => i18n.t("signup.sign-up-token-deleted")
|
||||
);
|
||||
},
|
||||
async createUser(token, data) {
|
||||
return apiReq.post(signUpURLs.createUser(token), data,
|
||||
function() { return i18n.t('user.you-are-not-allowed-to-create-a-user'); },
|
||||
function() { return i18n.t('user.user-created'); }
|
||||
return apiReq.post(
|
||||
signUpURLs.createUser(token),
|
||||
data,
|
||||
() => i18n.t("user.you-are-not-allowed-to-create-a-user"),
|
||||
() => i18n.t("user.user-created")
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import { store } from "@/store";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
|
||||
const settingsBase = baseURL + "site-settings";
|
||||
|
||||
@@ -21,12 +21,12 @@ export const siteSettingsAPI = {
|
||||
|
||||
async update(body) {
|
||||
const response = await apiReq.put(
|
||||
settingsURLs.updateSiteSettings,
|
||||
settingsURLs.updateSiteSettings,
|
||||
body,
|
||||
function() { return i18n.t('settings.settings-update-failed'); },
|
||||
function() { return i18n.t('settings.settings-updated'); }
|
||||
() => i18n.t("settings.settings-update-failed"),
|
||||
() => i18n.t("settings.settings-updated")
|
||||
);
|
||||
if(response) {
|
||||
if (response) {
|
||||
store.dispatch("requestSiteSettings");
|
||||
}
|
||||
return response;
|
||||
@@ -44,10 +44,10 @@ export const siteSettingsAPI = {
|
||||
|
||||
createPage(body) {
|
||||
return apiReq.post(
|
||||
settingsURLs.customPages,
|
||||
settingsURLs.customPages,
|
||||
body,
|
||||
function() { return i18n.t('page.page-creation-failed'); },
|
||||
function() { return i18n.t('page.new-page-created'); }
|
||||
() => i18n.t("page.page-creation-failed"),
|
||||
() => i18n.t("page.new-page-created")
|
||||
);
|
||||
},
|
||||
|
||||
@@ -55,25 +55,26 @@ export const siteSettingsAPI = {
|
||||
return await apiReq.delete(
|
||||
settingsURLs.customPage(id),
|
||||
null,
|
||||
function() { return i18n.t('page.page-deletion-failed'); },
|
||||
function() { return i18n.t('page.page-deleted'); });
|
||||
() => i18n.t("page.page-deletion-failed"),
|
||||
() => i18n.t("page.page-deleted")
|
||||
);
|
||||
},
|
||||
|
||||
updatePage(body) {
|
||||
return apiReq.put(
|
||||
settingsURLs.customPage(body.id),
|
||||
body,
|
||||
function() { return i18n.t('page.page-update-failed'); },
|
||||
function() { return i18n.t('page.page-updated'); }
|
||||
() => i18n.t("page.page-update-failed"),
|
||||
() => i18n.t("page.page-updated")
|
||||
);
|
||||
},
|
||||
|
||||
async updateAllPages(allPages) {
|
||||
let response = await apiReq.put(
|
||||
settingsURLs.customPages,
|
||||
settingsURLs.customPages,
|
||||
allPages,
|
||||
function() { return i18n.t('page.pages-update-failed'); },
|
||||
function() { return i18n.t('page.pages-updated'); }
|
||||
() => i18n.t("page.pages-update-failed"),
|
||||
() => i18n.t("page.pages-updated")
|
||||
);
|
||||
return response;
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
|
||||
const prefix = baseURL + "themes";
|
||||
|
||||
@@ -25,10 +25,11 @@ export const themeAPI = {
|
||||
|
||||
async create(postBody) {
|
||||
return await apiReq.post(
|
||||
settingsURLs.createTheme,
|
||||
settingsURLs.createTheme,
|
||||
postBody,
|
||||
function() { return i18n.t('settings.theme.error-creating-theme-see-log-file'); },
|
||||
function() { return i18n.t('settings.theme.theme-saved'); });
|
||||
() => i18n.t("settings.theme.error-creating-theme-see-log-file"),
|
||||
() => i18n.t("settings.theme.theme-saved")
|
||||
);
|
||||
},
|
||||
|
||||
update(themeName, colors) {
|
||||
@@ -37,18 +38,19 @@ export const themeAPI = {
|
||||
colors: colors,
|
||||
};
|
||||
return apiReq.put(
|
||||
settingsURLs.updateTheme(themeName),
|
||||
settingsURLs.updateTheme(themeName),
|
||||
body,
|
||||
function() { return i18n.t('settings.theme.error-updating-theme'); },
|
||||
function() { return i18n.t('settings.theme.theme-updated'); });
|
||||
() => i18n.t("settings.theme.error-updating-theme"),
|
||||
() => i18n.t("settings.theme.theme-updated")
|
||||
);
|
||||
},
|
||||
|
||||
delete(themeName) {
|
||||
return apiReq.delete(
|
||||
settingsURLs.deleteTheme(themeName),
|
||||
null,
|
||||
function() { return i18n.t('settings.theme.error-deleting-theme'); },
|
||||
function() { return i18n.t('settings.theme.theme-deleted'); }
|
||||
() => i18n.t("settings.theme.error-deleting-theme"),
|
||||
() => i18n.t("settings.theme.theme-deleted")
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { apiReq } from "./api-utils";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
|
||||
export const utilsAPI = {
|
||||
// import { api } from "@/api";
|
||||
@@ -9,8 +9,8 @@ export const utilsAPI = {
|
||||
return apiReq.post(
|
||||
url,
|
||||
fileObject,
|
||||
function() { return i18n.t('general.failure-uploading-file'); },
|
||||
function() { return i18n.t('general.file-uploaded'); }
|
||||
() => i18n.t("general.failure-uploading-file"),
|
||||
() => i18n.t("general.file-uploaded")
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import axios from "axios";
|
||||
import i18n from '@/i18n.js';
|
||||
import i18n from "@/i18n.js";
|
||||
const authPrefix = baseURL + "auth";
|
||||
const userPrefix = baseURL + "users";
|
||||
|
||||
@@ -19,22 +19,19 @@ const usersURLs = {
|
||||
};
|
||||
|
||||
function deleteErrorText(response) {
|
||||
switch(response.data.detail) {
|
||||
case 'SUPER_USER':
|
||||
return i18n.t('user.error-cannot-delete-super-user');
|
||||
switch (response.data.detail) {
|
||||
case "SUPER_USER":
|
||||
return i18n.t("user.error-cannot-delete-super-user");
|
||||
|
||||
default:
|
||||
return i18n.t('user.you-are-not-allowed-to-delete-this-user');
|
||||
return i18n.t("user.you-are-not-allowed-to-delete-this-user");
|
||||
}
|
||||
}
|
||||
export const userAPI = {
|
||||
async login(formData) {
|
||||
let response = await apiReq.post(
|
||||
authURLs.token,
|
||||
formData,
|
||||
null,
|
||||
function() { return i18n.t('user.user-successfully-logged-in'); }
|
||||
);
|
||||
let response = await apiReq.post(authURLs.token, formData, null, function() {
|
||||
return i18n.t("user.user-successfully-logged-in");
|
||||
});
|
||||
return response;
|
||||
},
|
||||
async refresh() {
|
||||
@@ -49,10 +46,10 @@ export const userAPI = {
|
||||
},
|
||||
create(user) {
|
||||
return apiReq.post(
|
||||
usersURLs.users,
|
||||
usersURLs.users,
|
||||
user,
|
||||
function() { return i18n.t('user.user-creation-failed'); },
|
||||
function() { return i18n.t('user.user-created'); }
|
||||
() => i18n.t("user.user-creation-failed"),
|
||||
() => i18n.t("user.user-created")
|
||||
);
|
||||
},
|
||||
async self() {
|
||||
@@ -65,35 +62,32 @@ export const userAPI = {
|
||||
},
|
||||
update(user) {
|
||||
return apiReq.put(
|
||||
usersURLs.userID(user.id),
|
||||
usersURLs.userID(user.id),
|
||||
user,
|
||||
function() { return i18n.t('user.user-update-failed'); },
|
||||
function() { return i18n.t('user.user-updated'); }
|
||||
() => i18n.t("user.user-update-failed"),
|
||||
() => i18n.t("user.user-updated")
|
||||
);
|
||||
},
|
||||
changePassword(id, password) {
|
||||
return apiReq.put(
|
||||
usersURLs.password(id),
|
||||
usersURLs.password(id),
|
||||
password,
|
||||
function() { return i18n.t('user.existing-password-does-not-match'); },
|
||||
function() { return i18n.t('user.password-updated'); }
|
||||
);
|
||||
},
|
||||
|
||||
delete(id) {
|
||||
return apiReq.delete(
|
||||
usersURLs.userID(id),
|
||||
null,
|
||||
deleteErrorText,
|
||||
function() { return i18n.t('user.user-deleted'); }
|
||||
() => i18n.t("user.existing-password-does-not-match"),
|
||||
() => i18n.t("user.password-updated")
|
||||
);
|
||||
},
|
||||
|
||||
delete(id) {
|
||||
return apiReq.delete(usersURLs.userID(id), null, deleteErrorText, function() {
|
||||
return i18n.t("user.user-deleted");
|
||||
});
|
||||
},
|
||||
resetPassword(id) {
|
||||
return apiReq.put(
|
||||
usersURLs.resetPassword(id),
|
||||
null,
|
||||
function() { return i18n.t('user.password-reset-failed'); },
|
||||
function() { return i18n.t('user.password-has-been-reset-to-the-default-password'); }
|
||||
() => i18n.t("user.password-reset-failed"),
|
||||
() => i18n.t("user.password-has-been-reset-to-the-default-password")
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user