This commit is contained in:
2020-06-19 17:20:23 +00:00
parent c1e688d824
commit dbe59f74d9
6 changed files with 25 additions and 56 deletions

View File

@@ -1,6 +1,5 @@
/* Xeslint-disable */
import router from "../router";
import auth from "./auth";
function stringifyPrimitive(v) {
switch (typeof v) {
@@ -74,7 +73,7 @@ function handleError(action, error, route, reject) {
"notify-error",
window.$gz.translation.get("ErrorUserNotAuthenticated")
);
auth.logout();
router.push("/login");
if (reject) {
return reject("[ErrorUserNotAuthenticated]");
@@ -452,7 +451,7 @@ export default {
///////////////////////////////////
// POST / PUT DATA TO API SERVER
//
async upsertEx(route, data, noToken = false) {
async upsert(route, data, isLogin = false) {
try {
let that = this;
//determine if this is a new or existing record
@@ -467,7 +466,7 @@ export default {
if (window.$gz._.endsWith(route, "/0")) {
route = route.slice(0, -2);
}
if (noToken == false) {
if (isLogin == false) {
fetchOptions = that.fetchPostOptions(data);
} else {
fetchOptions = that.fetchPostNoAuthOptions(data);
@@ -479,39 +478,13 @@ export default {
r = await that.extractBodyEx(r);
return r;
} catch (error) {
handleError("UPSERT", error, route);
}
},
upsert(route, data) {
let that = this;
return new Promise(function upsertDataToServer(resolve, reject) {
//determine if this is a new or existing record
let fetchOptions = undefined;
if (data.concurrency) {
//has concurrency token, so this is a PUT as it's updating an existing record
fetchOptions = that.fetchPutOptions(data);
if (isLogin == false) {
handleError("UPSERT", error, route);
} else {
//Does not have a concurrency token so this is a POST as it's posting a new record without a concurrency token
fetchOptions = that.fetchPostOptions(data);
//ensure the route doesn't end in /0 which will happen if it's a new record since the edit forms just send the url here with the ID regardless
if (window.$gz._.endsWith(route, "/0")) {
route = route.slice(0, -2);
}
//specifically this is for the login page
throw error;
}
fetch(that.APIUrl(route), fetchOptions)
.then(that.status)
.then(that.extractBody)
// eslint-disable-next-line
.then((response) => {
//Note: response.error indicates there is an error, however this is not an unusual condition
//it could be validation errors or other general error so we need to treat it here like it's normal
//and let the caller deal with it appropriately
resolve(response);
})
.catch(function handleUpsertError(error) {
handleError("UPSERT", error, route, reject);
});
});
}
},
///////////////////////////////////
// DELETE DATA FROM API SERVER

View File

@@ -31,10 +31,7 @@ export default {
}
//step 2: get it
let transData = await window.$gz.api.upsertEx(
"translation/subset",
needIt
);
let transData = await window.$gz.api.upsert("translation/subset", needIt);
transData.data.forEach(function commitFetchedTranslationItemToStore(
item
) {