From d928eab3ecefbf778f1cadece9beac010dc42332 Mon Sep 17 00:00:00 2001 From: maksJopek <72977266+maksJopek@users.noreply.github.com> Date: Mon, 5 Apr 2021 00:30:46 +0200 Subject: Small step in good direction --- backend/ts/helpers.ts | 18 --------------- backend/ts/index.ts | 15 +++++++----- helpers/helpers.ts | 52 +++++++++++++++++++++++++++++++++++++++++ package.json | 64 ++++++++++++++++++++++++++------------------------- tsconfig.json | 4 +++- 5 files changed, 97 insertions(+), 56 deletions(-) delete mode 100644 backend/ts/helpers.ts create mode 100644 helpers/helpers.ts diff --git a/backend/ts/helpers.ts b/backend/ts/helpers.ts deleted file mode 100644 index 984ce2d..0000000 --- a/backend/ts/helpers.ts +++ /dev/null @@ -1,18 +0,0 @@ -import fetch from "node-fetch"; - -export async function makeQuery (query: string, params: Array): Promise { - return await ( - await fetch("https://jopek.eu/maks/szkola/apkKli/fiaFiles/fia.php", { - method: "POST", - headers: { - Accept: "application/json", - "Content-Type": "application/json" - }, - body: JSON.stringify({ - apiKey: process.env.API_KEY, - stmt: query, - params: params - }) - }) - ).text(); -} \ No newline at end of file diff --git a/backend/ts/index.ts b/backend/ts/index.ts index fd8f8e1..ead29f2 100644 --- a/backend/ts/index.ts +++ b/backend/ts/index.ts @@ -7,15 +7,18 @@ dotenv.config(); const app = express(); const PORT = 8000; -if (!process.env.SESSION_KEY) - throw Error("SESSION_KEY is undefined"); +if (!process.env.SESSION_KEY) process.env.SESSION_KEY = "ouh2981w1pjd9"; +// throw Error("SESSION_KEY is undefined"); -app.use(session({ secret: process.env.SESSION_KEY, cookie: { maxAge: 60000 } })) +app.use( + session({ secret: process.env.SESSION_KEY, cookie: { maxAge: 60000 } }) +); app.use("/", express.static("./public")); -app.get("/favicon.ico", (req, res) => res.redirect("https://lukesmith.xyz/favicon.ico")); -app.get("/blank", (req, res) => res.send("")); -app.post("/login", (req, res, next) => login(req, res)); +app.get("/favicon.ico", (req, res) => + res.redirect("https://lukesmith.xyz/favicon.ico") +); +app.post("/login", (req, res) => login(req, res)); app.listen(PORT, () => { console.log(`[server]: Server is running at https://localhost:${PORT}`); diff --git a/helpers/helpers.ts b/helpers/helpers.ts new file mode 100644 index 0000000..3a16d18 --- /dev/null +++ b/helpers/helpers.ts @@ -0,0 +1,52 @@ +import fetch from "node-fetch"; + +export async function makeQuery( + query: string, + params: Array +): Promise { + console.log("makeQuery"); + return await ( + await fetch("https://jopek.eu/maks/szkola/apkKli/fiaFiles/fia.php", { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json" + }, + body: JSON.stringify({ + apiKey: process.env.API_KEY, + stmt: query, + params: params + }) + }) + ).text(); +} + +export interface Colors { + blue: number; + red: number; + green: number; + yellow: number; + 0: number; + 1: number; + 2: number; + 3: number; +} + +export const Color: Colors = { + blue: 0, + red: 1, + green: 2, + yellow: 3, + 0: 0, + 1: 1, + 2: 2, + 3: 3 +}; + +export type tColors = typeof Color[keyof typeof Color]; +export type Data = Array<{ id: any; color: tColors; name: string }>; +export interface fiaTable { + id: number; + data: Data; + started: boolean; +} diff --git a/package.json b/package.json index 920f7f1..c11425e 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,34 @@ { - "name": "fia", - "version": "0.0.1", - "repository": "git@github.com:maksJopek/fia.git", - "author": "Maks Jopek ", - "license": "GPL-3.0", - "main": "./src/backend/js/index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start:build-front": "tsc -p ./frontend/tsconfig.json --watch", - "start:build-back": "tsc -p ./backend/tsconfig.json --watch", - "start:run": "nodemon ./backend/js/index.js", - "start": "concurrently \"yarn:start:*\"" - }, - "dependencies": { - "dotenv": "^8.2.0", - "express": "^4.17.1", - "express-session": "^1.17.1", - "node-fetch": "^2.6.1" - }, - "devDependencies": { - "@types/concurrently": "^6.0.1", - "@types/dotenv": "^8.2.0", - "@types/express": "^4.17.11", - "@types/express-session": "1.17.0", - "@types/node-fetch": "^2.5.8", - "@types/nodemon": "^1.19.0", - "concurrently": "^6.0.0", - "nodemon": "^2.0.7", - "typescript": "^4.2.3" - } -} + "name": "fia", + "version": "0.0.1", + "repository": "git@github.com:maksJopek/fia.git", + "author": "Maks Jopek ", + "license": "GPL-3.0", + "main": "./backend/js/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start:build-front": "tsc -p ./frontend/tsconfig.json --watch", + "start:build-back": "tsc -p ./backend/tsconfig.json --watch", + "start:run": "nodemon ./backend/js/index.js", + "start": "concurrently \"yarn:start:*\"" + }, + "dependencies": { + "dotenv": "^8.2.0", + "express": "^4.17.1", + "express-session": "^1.17.1", + "node-fetch": "^2.6.1" + }, + "devDependencies": { + "@types/concurrently": "^6.0.1", + "@types/dotenv": "^8.2.0", + "@types/express": "^4.17.11", + "@types/express-session": "1.17.0", + "@types/node-fetch": "^2.5.8", + "@types/nodemon": "^1.19.0", + "concurrently": "^6.0.0", + "nodemon": "^2.0.7", + "typescript": "^4.2.3" + }, + "keywords": [], + "description": "" +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 12d494c..4478def 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "esModuleInterop": true, "target": "ESNext", "module": "commonjs", + "moduleResolution": "node", "strict": true, "lib": [ "ESNext" @@ -16,7 +17,8 @@ "strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */, "strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. "noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */, - "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */ + "alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */, + "downlevelIteration": true /* END MINE */ }, // "include": [ -- cgit v1.3.1