aboutsummaryrefslogtreecommitdiffstats
path: root/helpers/helpers.ts
diff options
context:
space:
mode:
authorMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-04-24 00:34:07 +0200
committerMaks Jopek <maksymilian.jopek@prym-soft.pl>2021-04-24 00:34:07 +0200
commit13dcc2c8fc1d11e3b94432fffc4c4f186bd94d29 (patch)
tree077a963bae31729dffa6c7c678af112680bb6d38 /helpers/helpers.ts
parent457ee1d7caa899bbe86bf7a1390f940b5b3176b7 (diff)
downloadfia-13dcc2c8fc1d11e3b94432fffc4c4f186bd94d29.tar.gz
fia-13dcc2c8fc1d11e3b94432fffc4c4f186bd94d29.tar.zst
fia-13dcc2c8fc1d11e3b94432fffc4c4f186bd94d29.zip
Playing almost working
Diffstat (limited to 'helpers/helpers.ts')
-rw-r--r--helpers/helpers.ts33
1 files changed, 26 insertions, 7 deletions
diff --git a/helpers/helpers.ts b/helpers/helpers.ts
index 03bc7d7..80fb5ab 100644
--- a/helpers/helpers.ts
+++ b/helpers/helpers.ts
@@ -23,8 +23,11 @@ export default class Helpers {
}
static dbResToFiaTable(dbRes: dbRes): fiaTable {
- if (typeof dbRes.data === "string")
+ if (typeof dbRes.data === "string") {
+ console.log("dbRes.data: ", dbRes.data);
+ console.log("dbRes.data as string: ", JSON.stringify(dbRes.data));
dbRes.data = JSON.parse(dbRes.data);
+ }
else
throw new Error("dbResToFiaTable : wrong $1 type; ");
@@ -32,11 +35,11 @@ export default class Helpers {
return dbRes;
}
- static checkApiRes(res: any, nRes = {} as Response): any {
- if (res.api === false) {
+ static checkApiRes(res: any, nRes = {} as Response): boolean {
+ if (res.success === false) {
if (Object.keys(nRes).length === 0) {
// @ts-ignore - here error is because backend tsc is checking this file, where lib: DOM is not present
- alert("API Error!");
+ // alert("API Error!");
throw new Error("API Error!");
} else {
nRes.status(500);
@@ -46,19 +49,24 @@ export default class Helpers {
}
if (Object.keys(nRes).length !== 0)
nRes.status(200);
- return res;
+ return true;
}
static async mFetch(url: string, body: object): Promise<any> {
//@ts-ignore - this doesn't exist for backend, but its never used there
- return fetch(url, {
+ let res: any = await (await fetch(url, {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(body)
- }).then(Helpers.checkApiRes);
+ })).json();
+ if (this.checkApiRes(res) == true)
+ return res;
+ else
+ throw new Error("API Error!");;
+
}
static getRandomInt(min: number, max: number) {
@@ -66,4 +74,15 @@ export default class Helpers {
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive
}
+
+ static Color: Colors = {
+ blue: 0,
+ red: 1,
+ green: 2,
+ yellow: 3,
+ 0: 0,
+ 1: 1,
+ 2: 2,
+ 3: 3
+ };
} \ No newline at end of file