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 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 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 todo: remove all use of .then() as it's being used incorrectly
replace with await and async methods replace with await and async methods

View File

@@ -1,6 +1,5 @@
/* Xeslint-disable */ /* Xeslint-disable */
import router from "../router"; import router from "../router";
import auth from "./auth";
function stringifyPrimitive(v) { function stringifyPrimitive(v) {
switch (typeof v) { switch (typeof v) {
@@ -74,7 +73,7 @@ function handleError(action, error, route, reject) {
"notify-error", "notify-error",
window.$gz.translation.get("ErrorUserNotAuthenticated") window.$gz.translation.get("ErrorUserNotAuthenticated")
); );
auth.logout();
router.push("/login"); router.push("/login");
if (reject) { if (reject) {
return reject("[ErrorUserNotAuthenticated]"); return reject("[ErrorUserNotAuthenticated]");
@@ -452,7 +451,7 @@ export default {
/////////////////////////////////// ///////////////////////////////////
// POST / PUT DATA TO API SERVER // POST / PUT DATA TO API SERVER
// //
async upsertEx(route, data, noToken = false) { async upsert(route, data, isLogin = false) {
try { try {
let that = this; let that = this;
//determine if this is a new or existing record //determine if this is a new or existing record
@@ -467,7 +466,7 @@ export default {
if (window.$gz._.endsWith(route, "/0")) { if (window.$gz._.endsWith(route, "/0")) {
route = route.slice(0, -2); route = route.slice(0, -2);
} }
if (noToken == false) { if (isLogin == false) {
fetchOptions = that.fetchPostOptions(data); fetchOptions = that.fetchPostOptions(data);
} else { } else {
fetchOptions = that.fetchPostNoAuthOptions(data); fetchOptions = that.fetchPostNoAuthOptions(data);
@@ -479,39 +478,13 @@ export default {
r = await that.extractBodyEx(r); r = await that.extractBodyEx(r);
return r; return r;
} catch (error) { } catch (error) {
handleError("UPSERT", error, route); if (isLogin == false) {
} 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);
} else { } else {
//Does not have a concurrency token so this is a POST as it's posting a new record without a concurrency token //specifically this is for the login page
fetchOptions = that.fetchPostOptions(data); throw error;
//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);
}
} }
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 // DELETE DATA FROM API SERVER

View File

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

View File

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

View File

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

View File

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