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

@@ -5,10 +5,6 @@ PRIORITY - ALWAYS Lowest level stuff first, i.e. TODO at server, api route chang
WIFI change 5g channel to 52,56,60 and 2g channel to 8
recheck before doing as it seems to vary, maybe someone else's is auto switching
todo: Auth is directly fetching, re-route through gzapi instead
todo: remove all use of .then() as it's being used incorrectly
replace with await and async methods

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
) {

View File

@@ -354,13 +354,13 @@ export default {
}
//call erase
let r = await window.$gz.api.upsertEx(
let r = await window.$gz.api.upsert(
"license/permanently-erase-all-data",
"I understand"
);
//send request
r = await window.$gz.api.upsertEx("license/trialRequest", vm.request);
r = await window.$gz.api.upsert("license/trialRequest", vm.request);
//a string is returned and will start with E1 if it's an error
if (r.startsWith("E1")) {
@@ -402,7 +402,7 @@ export default {
}
//call fetch key on server
let r = await window.$gz.api.upsertEx("license");
let r = await window.$gz.api.upsert("license");
//r should just be a string response unless there is an error in which case it's an object
if (r.error) {
throw r;
@@ -452,7 +452,7 @@ export default {
}
}
//call erase
await window.$gz.api.upsertEx(
await window.$gz.api.upsert(
"license/permanently-erase-all-data",
"I understand"
);

View File

@@ -183,14 +183,14 @@ export default {
return;
}
//call erase
await window.$gz.api.upsertEx(
await window.$gz.api.upsert(
"license/permanently-erase-all-data",
"I understand"
);
}
//call seed route
let jobId = await window.$gz.api.upsertEx(
let jobId = await window.$gz.api.upsert(
`trial/seed/${vm.obj.seedLevel}/${vm.obj.timeZoneOffset}`
);
if (jobId.error) {

View File

@@ -84,7 +84,7 @@
<script>
/* xeslint-disable */
import auth from "../api/auth";
import { processLogin, processLogout } from "../api/authutil";
export default {
@@ -281,14 +281,17 @@ export default {
vm.input.username == "superuser" && vm.input.password == "l3tm3in";
try {
let res = await window.$gz.api.upsertEx("auth", {
login: vm.input.username,
password: vm.input.password
});
let res = await window.$gz.api.upsert(
"auth",
{
login: vm.input.username,
password: vm.input.password
},
true
);
if (res.error) {
//todo, this is shitty if it's just a bad login creds so handle that here instead of in cacth block
debugger;
//don't expect this to ever get called but just in case
throw res.error;
}
await processLogin(res.data, loggedInWithKnownPassword);