diff options
Diffstat (limited to 'helpers/helpers.ts')
| -rw-r--r-- | helpers/helpers.ts | 33 |
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 |
