diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index 20f740e8..42d7cc51 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -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 diff --git a/ayanova/src/api/gzapi.js b/ayanova/src/api/gzapi.js index 5c11afa4..1314369f 100644 --- a/ayanova/src/api/gzapi.js +++ b/ayanova/src/api/gzapi.js @@ -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 diff --git a/ayanova/src/api/translation.js b/ayanova/src/api/translation.js index 3dd94683..115fa742 100644 --- a/ayanova/src/api/translation.js +++ b/ayanova/src/api/translation.js @@ -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 ) { diff --git a/ayanova/src/views/adm-license.vue b/ayanova/src/views/adm-license.vue index 6db6b682..9dbef8bc 100644 --- a/ayanova/src/views/adm-license.vue +++ b/ayanova/src/views/adm-license.vue @@ -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" ); diff --git a/ayanova/src/views/ay-evaluate.vue b/ayanova/src/views/ay-evaluate.vue index edd211dc..e7fa7d98 100644 --- a/ayanova/src/views/ay-evaluate.vue +++ b/ayanova/src/views/ay-evaluate.vue @@ -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) { diff --git a/ayanova/src/views/login.vue b/ayanova/src/views/login.vue index 9ad117da..03a66cfd 100644 --- a/ayanova/src/views/login.vue +++ b/ayanova/src/views/login.vue @@ -84,7 +84,7 @@