From e512ae52b0fe4989813188eb9eaa08a821c73f36 Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Thu, 25 Mar 2021 10:08:41 +0000 Subject: [PATCH] Server is now receiving messages DB server set up --- .gitignore | 3 +- db/database.env | 3 + db/docker-compose.yml | 14 + db/setup/init.sql | 242 +++++++++++++++ db/users.db | Bin 0 -> 16384 bytes package.json | 13 +- server/commonjs/server.d.ts | 7 - server/commonjs/server.d.ts.map | 1 - server/commonjs/server.js | 19 -- server/commonjs/server.js.map | 1 - server/db/connect.d.ts | 2 - server/db/connect.js | 10 - server/db/connect.js.map | 1 - server/db/loginmanager.d.ts | 2 - server/db/loginmanager.js | 17 -- server/db/loginmanager.js.map | 1 - server/development.d.ts | 1 - server/development.js | 24 -- server/development.js.map | 1 - server/es/development.d.ts | 2 - server/es/development.d.ts.map | 1 - server/es/development.js | 3 - server/es/development.js.map | 1 - server/es/server.d.ts | 7 - server/es/server.d.ts.map | 1 - server/es/server.js | 14 - server/es/server.js.map | 1 - server/handlers/LoginHandler.d.ts | 3 - server/handlers/LoginHandler.js | 79 ----- server/handlers/LoginHandler.js.map | 1 - server/lib/ValidateRequest.d.ts | 3 - server/lib/ValidateRequest.js | 20 -- server/lib/ValidateRequest.js.map | 1 - server/lib/authenticator.d.ts | 3 - server/lib/authenticator.js | 47 --- server/lib/authenticator.js.map | 1 - server/routes/login.d.ts | 1 - server/routes/login.js | 21 -- server/routes/login.js.map | 1 - server/server.d.ts | 5 - server/server.js | 66 ----- server/server.js.map | 1 - src/controllers/AccessController.ts | 28 +- src/controllers/ECGController.ts | 18 +- src/controllers/IncidentsController.ts | 30 +- src/controllers/IncidentsV2Controller.ts | 358 +++++++++++++---------- src/controllers/ReceiveController.ts | 67 ++--- src/controllers/TestController.ts | 18 +- src/controllers/TestsController.ts | 67 ++--- src/controllers/UsersController.ts | 68 ++--- src/controllers/ValuesController.ts | 67 ++--- src/db/connectPG.ts | 13 + src/db/incidentV2PG.ts | 55 ++++ src/db/loginmanagerPG.ts | 17 ++ src/development.ts | 4 +- src/handlers/LoginHandler.ts | 6 +- src/lib/ValidateRequest.ts | 28 +- src/lib/authenticator.ts | 46 ++- src/lib/constants.ts | 20 +- src/middleware/jwt.ts | 37 ++- src/models/Casualty.ts | 42 +-- src/models/Chat.ts | 10 +- src/models/ChatStatus.ts | 15 +- src/models/IncidentItemV2.ts | 44 +-- src/models/StartIncident.ts | 21 ++ src/models/User.ts | 10 +- src/routes/index.ts | 75 +++-- src/server.ts | 38 +-- 68 files changed, 951 insertions(+), 896 deletions(-) create mode 100644 db/database.env create mode 100644 db/docker-compose.yml create mode 100644 db/setup/init.sql create mode 100644 db/users.db delete mode 100644 server/commonjs/server.d.ts delete mode 100644 server/commonjs/server.d.ts.map delete mode 100644 server/commonjs/server.js delete mode 100644 server/commonjs/server.js.map delete mode 100644 server/db/connect.d.ts delete mode 100644 server/db/connect.js delete mode 100644 server/db/connect.js.map delete mode 100644 server/db/loginmanager.d.ts delete mode 100644 server/db/loginmanager.js delete mode 100644 server/db/loginmanager.js.map delete mode 100644 server/development.d.ts delete mode 100644 server/development.js delete mode 100644 server/development.js.map delete mode 100644 server/es/development.d.ts delete mode 100644 server/es/development.d.ts.map delete mode 100644 server/es/development.js delete mode 100644 server/es/development.js.map delete mode 100644 server/es/server.d.ts delete mode 100644 server/es/server.d.ts.map delete mode 100644 server/es/server.js delete mode 100644 server/es/server.js.map delete mode 100644 server/handlers/LoginHandler.d.ts delete mode 100644 server/handlers/LoginHandler.js delete mode 100644 server/handlers/LoginHandler.js.map delete mode 100644 server/lib/ValidateRequest.d.ts delete mode 100644 server/lib/ValidateRequest.js delete mode 100644 server/lib/ValidateRequest.js.map delete mode 100644 server/lib/authenticator.d.ts delete mode 100644 server/lib/authenticator.js delete mode 100644 server/lib/authenticator.js.map delete mode 100644 server/routes/login.d.ts delete mode 100644 server/routes/login.js delete mode 100644 server/routes/login.js.map delete mode 100644 server/server.d.ts delete mode 100644 server/server.js delete mode 100644 server/server.js.map create mode 100644 src/db/connectPG.ts create mode 100644 src/db/incidentV2PG.ts create mode 100644 src/db/loginmanagerPG.ts create mode 100644 src/models/StartIncident.ts diff --git a/.gitignore b/.gitignore index df8d3bb..0ef8a8a 100755 --- a/.gitignore +++ b/.gitignore @@ -156,7 +156,6 @@ artefacts/*.json /update.sh /setup/web/ /backup/ -/db/ /archive.tar.gz /user/ @@ -165,4 +164,4 @@ artefacts/*.json menu.db menu.db.backup -/server +server/* diff --git a/db/database.env b/db/database.env new file mode 100644 index 0000000..4d7bf31 --- /dev/null +++ b/db/database.env @@ -0,0 +1,3 @@ +POSTGRES_USER=aiber_user +POSTGRES_PASSWORD=Copper.Nifleheim.246 +POSTGRES_DB=aiber_database diff --git a/db/docker-compose.yml b/db/docker-compose.yml new file mode 100644 index 0000000..9745709 --- /dev/null +++ b/db/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3' +services: + database: + image: "postgres:alpine" # use latest official postgres version + ports: + - 5432:5432 + # restart: always + env_file: + - database.env # configure postgres + volumes: + - database-data:/var/lib/postgresql/data/ # persist data even if container shuts down + - ./setup/init.sql:/docker-entrypoint-initdb.d/init.sql +volumes: + database-data: # named volumes can be managed easier using docker-compose diff --git a/db/setup/init.sql b/db/setup/init.sql new file mode 100644 index 0000000..a4cfd6e --- /dev/null +++ b/db/setup/init.sql @@ -0,0 +1,242 @@ +DROP SCHEMA public; + +CREATE SCHEMA public AUTHORIZATION aiber_user; + +COMMENT ON SCHEMA public IS 'standard public schema'; + +-- DROP SEQUENCE public.casualty_id_seq; + +CREATE SEQUENCE public.casualty_id_seq + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 + START 1 + CACHE 1 + NO CYCLE; + +-- Permissions + +ALTER SEQUENCE public.casualty_id_seq OWNER TO aiber_user; +GRANT ALL ON SEQUENCE public.casualty_id_seq TO aiber_user; + +-- DROP SEQUENCE public.incidentitems_id_seq; + +CREATE SEQUENCE public.incidentitems_id_seq + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 + START 1 + CACHE 1 + NO CYCLE; + +-- Permissions + +ALTER SEQUENCE public.incidentitems_id_seq OWNER TO aiber_user; +GRANT ALL ON SEQUENCE public.incidentitems_id_seq TO aiber_user; + +-- DROP SEQUENCE public.incidentitemsv2_id_seq; + +CREATE SEQUENCE public.incidentitemsv2_id_seq + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 + START 1 + CACHE 1 + NO CYCLE; + +-- Permissions + +ALTER SEQUENCE public.incidentitemsv2_id_seq OWNER TO aiber_user; +GRANT ALL ON SEQUENCE public.incidentitemsv2_id_seq TO aiber_user; + +-- DROP SEQUENCE public.users_id_seq; + +CREATE SEQUENCE public.users_id_seq + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 2147483647 + START 1 + CACHE 1 + NO CYCLE; + +-- Permissions + +ALTER SEQUENCE public.users_id_seq OWNER TO aiber_user; +GRANT ALL ON SEQUENCE public.users_id_seq TO aiber_user; +-- public.casualty definition + +-- Drop table + +-- DROP TABLE public.casualty; + +CREATE TABLE public.casualty ( + id int4 NOT NULL GENERATED ALWAYS AS IDENTITY, + incidentid varchar(255) NOT NULL, + gender varchar(20) NULL DEFAULT ''::character varying, + dob varchar(12) NULL DEFAULT ''::character varying, + age int2 NULL, + alcohol varchar(5) NULL DEFAULT ''::character varying, + allergies varchar(20) NULL DEFAULT ''::character varying, + allergydetails text NULL DEFAULT ''::text, + medicinetaken text NULL DEFAULT ''::text, + medhist text NULL DEFAULT ''::text, + flight varchar(100) NULL DEFAULT ''::character varying, + seat varchar(100) NULL DEFAULT ''::character varying, + arrivalairport varchar(100) NULL DEFAULT ''::character varying, + lastmeal text NULL DEFAULT ''::text, + detailsadded int8 NOT NULL, + complaint text NULL DEFAULT ''::text, + history text NULL DEFAULT ''::text, + deleted int8 NULL DEFAULT 0, + CONSTRAINT casualty_incidentid_key UNIQUE (incidentid) +); + +-- Permissions + +ALTER TABLE public.casualty OWNER TO aiber_user; +GRANT ALL ON TABLE public.casualty TO aiber_user; + + +-- public.incidentitems definition + +-- Drop table + +-- DROP TABLE public.incidentitems; + +CREATE TABLE public.incidentitems ( + id int4 NOT NULL GENERATED ALWAYS AS IDENTITY, + incidentdate timestamp(0) NOT NULL, + description text NOT NULL, + username varchar(50) NOT NULL, + reportdate timestamp(0) NOT NULL, + reportlog text NULL, + incidentid int4 NULL +); + +-- Permissions + +ALTER TABLE public.incidentitems OWNER TO aiber_user; +GRANT ALL ON TABLE public.incidentitems TO aiber_user; + + +-- public.incidentitemsv2 definition + +-- Drop table + +-- DROP TABLE public.incidentitemsv2; + +CREATE TABLE public.incidentitemsv2 ( + id int4 NOT NULL GENERATED ALWAYS AS IDENTITY, + incidentid varchar(255) NOT NULL, + incidenttime int8 NOT NULL, + reporttime int8 NOT NULL, + latitude numeric(12,9) NOT NULL DEFAULT 0, + longitude numeric(12,9) NOT NULL DEFAULT 0, + message_type varchar(20) NULL, + entry_type varchar(20) NULL, + entry_val1 varchar(255) NULL, + entry_val2 text NULL, + ackground int8 NULL DEFAULT 0, + ackair int8 NULL DEFAULT 0, + typingtime int8 NOT NULL DEFAULT 0, + battery int2 NOT NULL DEFAULT 0, + pluggedin int2 NULL DEFAULT 0, + username varchar(50) NOT NULL, + reportlog text NULL, + ecgtrace varchar(255) NULL +); + +-- Permissions + +ALTER TABLE public.incidentitemsv2 OWNER TO aiber_user; +GRANT ALL ON TABLE public.incidentitemsv2 TO aiber_user; + + +-- public.users definition + +-- Drop table + +-- DROP TABLE public.users; + +CREATE TABLE public.users ( + id int4 NOT NULL GENERATED ALWAYS AS IDENTITY, + username varchar NOT NULL, + "password" varchar NOT NULL, + email varchar NOT NULL, + "_id" varchar NOT NULL +); +CREATE INDEX users_id_idx ON public.users USING btree (id); +CREATE INDEX users_username_idx ON public.users USING btree (username); + +-- Permissions + +ALTER TABLE public.users OWNER TO aiber_user; +GRANT ALL ON TABLE public.users TO aiber_user; + + + +CREATE OR REPLACE FUNCTION public.upsertcasualty(_incidentid character varying, _gender character varying, _dob character varying, _age smallint, _alcohol character varying, _allergies character varying, _allergydetails text, _medicinetaken text, _medhist text, _flight character varying, _seat character varying, _arrivalairport character varying, _lastmeal text, _detailsadded bigint, _complaint text, _history text, _deleted bigint) + RETURNS void + LANGUAGE plpgsql +AS $function$ + begin + INSERT INTO public.casualty +(incidentid, gender, dob, age, alcohol, allergies, allergydetails, medicinetaken, medhist, flight, seat, arrivalairport, lastmeal, detailsadded, complaint, history, deleted) +VALUES(_incidentid , +_gender ::character varying, +_dob ::character varying, +_age , +_alcohol ::character varying, +_allergies ::character varying, +_allergydetails ::text, +_medicinetaken ::text, +_medhist ::text, +_flight ::character varying, +_seat ::character varying, +_arrivalairport ::character varying, +_lastmeal ::text, +_detailsadded , +_complaint ::text, +_history ::text, +_deleted) + +on conflict (incidentid) + do update set gender = excluded.gender, dob = excluded.dob, age = excluded.age, alcohol = excluded.alcohol, + allergies = excluded.allergies, allergydetails = excluded.allergydetails, medicinetaken = excluded.medicinetaken, medhist = excluded.medhist, + flight = excluded.flight, seat = excluded.seat, arrivalairport = excluded.arrivalairport, lastmeal = excluded.lastmeal, + detailsadded = excluded.detailsadded, complaint = excluded.complaint, history = excluded.history, deleted = excluded.deleted; + end +$function$ +; + +-- Permissions + +ALTER FUNCTION public.upsertcasualty(varchar,varchar,varchar,int2,varchar,varchar,text,text,text,varchar,varchar,varchar,text,int8,text,text,int8) OWNER TO aiber_user; +GRANT ALL ON FUNCTION public.upsertcasualty(varchar,varchar,varchar,int2,varchar,varchar,text,text,text,varchar,varchar,varchar,text,int8,text,text,int8) TO aiber_user; + +CREATE OR REPLACE FUNCTION public.upserttest(_incidentid character varying, _gender character varying) + RETURNS void + LANGUAGE plpgsql +AS $function$ + begin + INSERT INTO public.casualty +(incidentid, gender) +VALUES(_incidentid , +_gender ::character varying) + +on conflict (incidentid) + do update set gender = excluded.gender; + end +$function$ +; + +-- Permissions + +ALTER FUNCTION public.upserttest(varchar,varchar) OWNER TO aiber_user; +GRANT ALL ON FUNCTION public.upserttest(varchar,varchar) TO aiber_user; + + +-- Permissions + +GRANT ALL ON SCHEMA public TO aiber_user; +GRANT ALL ON SCHEMA public TO public; diff --git a/db/users.db b/db/users.db new file mode 100644 index 0000000000000000000000000000000000000000..e3fabade7ef77ecf6d17c662505dbf145126dcd1 GIT binary patch literal 16384 zcmeI(v2L3{7zgk>96PmDN|(yYVClpZD^_YuVuvkYE|nVxCoY!i$)ffpvSe^$u-Y|! zf{uNVzCfowO7=`uryfp_T35!y3<6k^Z6nS5@wR8gi>xQgZQDo!iKFtF6Z1ZII_@k;7NKU;b>b3Uu$>)3aMhF5BfB*y_009U<00Izz z00jP2;OZsaELSS@!$lIjnTcRLo-d;$&bCUs&uyPG-*&p3>DjQ(wo65QI?;d4q13o%TB?c7Mo@`H6v#Na~UsgQ5f0L*BTq%^>6-uVjM7+OCGgv0`RezLS&ykU}a`J|Hl-^XT ztW^6%rRn8V$!X>!xcNCU4tycaJxC zWB1X|6)E{{WO94Q|gJ literal 0 HcmV?d00001 diff --git a/package.json b/package.json index 0786bf0..d58ca69 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,12 @@ "compile:ts": "tsc --outDir './server'", "compile": "npm run prebuild && npm run compile:es && npm run compile:commonjs", "run_server": "npm run run:ts", - "watch_server": "npm-watch run_server" + "watch_server": "npm-watch run_server", + "docker:start": "cd ./db && docker-compose up -d --build", + "docker:stop": "cd ./db && docker-compose down", + "docker:cleanup": "cd ./db && docker-compose down -v --remove-orphans", + "docker:logs": "cd ./db && docker-compose logs -f", + "quick_start": "npm run docker:start && npm run watch_server" }, "keywords": [], "author": "", @@ -49,19 +54,23 @@ "log4js": "^6.3.0", "mongoose": "^5.10.11", "morgan": "^1.10.0", + "pg-promise": "^10.9.5", "short-hash": "^1.0.0", - "sqlite3": "^5.0.2" + "sqlite3": "^5.0.2", + "ts-postgres": "^1.1.3" }, "devDependencies": { "@types/cors": "^2.8.10", "@types/express": "^4.17.8", "@types/express-serve-static-core": "^4.17.18", "@types/express-session": "^1.17.0", + "@types/http-codes": "^1.0.1", "@types/jsonwebtoken": "^8.5.0", "@types/morgan": "^1.9.2", "@typescript-eslint/eslint-plugin": "^4.18.0", "@typescript-eslint/parser": "^4.18.0", "eslint": "7.22.0", + "http-codes": "^1.0.0", "prettier": "^2.2.1", "rimraf": "^3.0.2", "rollup": "^2.33.1", diff --git a/server/commonjs/server.d.ts b/server/commonjs/server.d.ts deleted file mode 100644 index 10507a0..0000000 --- a/server/commonjs/server.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import 'dotenv'; -import express from 'express'; -export declare class App { - protected app: express.Application; - constructor(NODE_ENV?: string, PORT?: number); -} -//# sourceMappingURL=server.d.ts.map \ No newline at end of file diff --git a/server/commonjs/server.d.ts.map b/server/commonjs/server.d.ts.map deleted file mode 100644 index 7471a38..0000000 --- a/server/commonjs/server.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,CAAC;AAEhB,OAAO,OAAO,MAAM,SAAS,CAAC;AAQ9B,qBAAa,GAAG;IACd,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC;gBAEvB,QAAQ,GAAE,MAAsB,EAAE,IAAI,GAAE,MAAa;CAoBlE"} \ No newline at end of file diff --git a/server/commonjs/server.js b/server/commonjs/server.js deleted file mode 100644 index b89462e..0000000 --- a/server/commonjs/server.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.App = void 0; -require("dotenv"); -const express_1 = __importDefault(require("express")); -class App { - constructor(NODE_ENV = 'development', PORT = 8080) { - const serverPort = process.env.PORT || 8120; - this.app = express_1.default(); - this.app.listen(serverPort, function () { - console.log('The server is running in port localhost: ', serverPort); - }); - } -} -exports.App = App; -//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/server/commonjs/server.js.map b/server/commonjs/server.js.map deleted file mode 100644 index 3b5a2aa..0000000 --- a/server/commonjs/server.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":";;;;;;AAAA,kBAAgB;AAEhB,sDAA8B;AAQ9B,MAAa,GAAG;IAGd,YAAY,WAAmB,aAAa,EAAE,OAAe,IAAI;QAC/D,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;QAE5C,IAAI,CAAC,GAAG,GAAG,iBAAO,EAAE,CAAC;QAIrB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE;YAC1B,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,UAAU,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC;CAUF;AAvBD,kBAuBC"} \ No newline at end of file diff --git a/server/db/connect.d.ts b/server/db/connect.d.ts deleted file mode 100644 index f0bdfe0..0000000 --- a/server/db/connect.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import sqlite3 from 'sqlite3'; -export declare const db: sqlite3.Database; diff --git a/server/db/connect.js b/server/db/connect.js deleted file mode 100644 index 510f89a..0000000 --- a/server/db/connect.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.db = void 0; -const sqlite3_1 = __importDefault(require("sqlite3")); -console.log(`${__dirname}/../../db/users.db`); -exports.db = new sqlite3_1.default.Database(`${__dirname}/../../db/users.db`); -//# sourceMappingURL=connect.js.map \ No newline at end of file diff --git a/server/db/connect.js.map b/server/db/connect.js.map deleted file mode 100644 index 539ef5b..0000000 --- a/server/db/connect.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/db/connect.ts"],"names":[],"mappings":";;;;;;AACA,sDAA8B;AAC9B,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,oBAAoB,CAAC,CAAC;AACjC,QAAA,EAAE,GAAG,IAAI,iBAAO,CAAC,QAAQ,CAAC,GAAG,SAAS,oBAAoB,CAAC,CAAC"} \ No newline at end of file diff --git a/server/db/loginmanager.d.ts b/server/db/loginmanager.d.ts deleted file mode 100644 index 43b0c41..0000000 --- a/server/db/loginmanager.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { User } from '../models/User'; -export declare const getOne: (username: string, password: string) => User | any; diff --git a/server/db/loginmanager.js b/server/db/loginmanager.js deleted file mode 100644 index 7bfd537..0000000 --- a/server/db/loginmanager.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getOne = void 0; -const connect_1 = require("./connect"); -const getOne = (username, password) => { - const sql = 'SELECT * FROM accounts WHERE username = ? and password = ?'; - return new Promise((resolve, reject) => { - connect_1.db.get(sql, [username, password], (err, row) => { - if (err) - reject(err); - if (!err) - resolve(row); - }); - }); -}; -exports.getOne = getOne; -//# sourceMappingURL=loginmanager.js.map \ No newline at end of file diff --git a/server/db/loginmanager.js.map b/server/db/loginmanager.js.map deleted file mode 100644 index a91277b..0000000 --- a/server/db/loginmanager.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"loginmanager.js","sourceRoot":"","sources":["../../src/db/loginmanager.ts"],"names":[],"mappings":";;;AAAA,uCAA+B;AAGxB,MAAM,MAAM,GAAG,CAAC,QAAgB,EAAE,QAAgB,EAAc,EAAE;IACvE,MAAM,GAAG,GAAG,6DAA6D,CAAC;IAE1E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,YAAE,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAQ,EAAE,GAAS,EAAE,EAAE;YACxD,IAAI,GAAG;gBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;YAErB,IAAI,CAAC,GAAG;gBAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAVW,QAAA,MAAM,UAUjB"} \ No newline at end of file diff --git a/server/development.d.ts b/server/development.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/server/development.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/server/development.js b/server/development.js deleted file mode 100644 index f0bd2de..0000000 --- a/server/development.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const server = __importStar(require("./server")); -new server.App; -//# sourceMappingURL=development.js.map \ No newline at end of file diff --git a/server/development.js.map b/server/development.js.map deleted file mode 100644 index 6ca450d..0000000 --- a/server/development.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"development.js","sourceRoot":"","sources":["../src/development.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,IAAI,MAAM,CAAC,GAAG,CAAA"} \ No newline at end of file diff --git a/server/es/development.d.ts b/server/es/development.d.ts deleted file mode 100644 index de2c7d6..0000000 --- a/server/es/development.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export {}; -//# sourceMappingURL=development.d.ts.map \ No newline at end of file diff --git a/server/es/development.d.ts.map b/server/es/development.d.ts.map deleted file mode 100644 index 5ace288..0000000 --- a/server/es/development.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"development.d.ts","sourceRoot":"","sources":["../../src/development.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/server/es/development.js b/server/es/development.js deleted file mode 100644 index 5ce6f99..0000000 --- a/server/es/development.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as server from "./server"; -new server.App; -//# sourceMappingURL=development.js.map \ No newline at end of file diff --git a/server/es/development.js.map b/server/es/development.js.map deleted file mode 100644 index 8e62595..0000000 --- a/server/es/development.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"development.js","sourceRoot":"","sources":["../../src/development.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,IAAI,MAAM,CAAC,GAAG,CAAA"} \ No newline at end of file diff --git a/server/es/server.d.ts b/server/es/server.d.ts deleted file mode 100644 index 10507a0..0000000 --- a/server/es/server.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import 'dotenv'; -import express from 'express'; -export declare class App { - protected app: express.Application; - constructor(NODE_ENV?: string, PORT?: number); -} -//# sourceMappingURL=server.d.ts.map \ No newline at end of file diff --git a/server/es/server.d.ts.map b/server/es/server.d.ts.map deleted file mode 100644 index db2f82c..0000000 --- a/server/es/server.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,CAAC;AAEhB,OAAO,OAAO,MAAM,SAAS,CAAC;AAQ9B,qBAAa,GAAG;IACd,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC;gBAEvB,QAAQ,GAAE,MAAsB,EAAE,IAAI,GAAE,MAAa;CAqBlE"} \ No newline at end of file diff --git a/server/es/server.js b/server/es/server.js deleted file mode 100644 index f112fe0..0000000 --- a/server/es/server.js +++ /dev/null @@ -1,14 +0,0 @@ -import 'dotenv'; -import express from 'express'; -import helmet from 'helmet'; -export class App { - constructor(NODE_ENV = 'development', PORT = 8080) { - const serverPort = process.env.PORT || PORT; - this.app = express(); - this.app.use(helmet()); - this.app.listen(serverPort, function () { - console.log('The server is running in port localhost: ', serverPort); - }); - } -} -//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/server/es/server.js.map b/server/es/server.js.map deleted file mode 100644 index 6afd5b6..0000000 --- a/server/es/server.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,CAAC;AAEhB,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAK5B,MAAM,OAAO,GAAG;IAGd,YAAY,WAAmB,aAAa,EAAE,OAAe,IAAI;QAC/D,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;QAE5C,IAAI,CAAC,GAAG,GAAG,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;QAIvB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE;YAC1B,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,UAAU,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC;CAUF"} \ No newline at end of file diff --git a/server/handlers/LoginHandler.d.ts b/server/handlers/LoginHandler.d.ts deleted file mode 100644 index da671f1..0000000 --- a/server/handlers/LoginHandler.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import express from 'express'; -export declare const ProcessLogin: (req: express.Request, res: express.Response) => any; -export declare const authenticate: (req: express.Request, res: express.Response, next: express.NextFunction) => void; diff --git a/server/handlers/LoginHandler.js b/server/handlers/LoginHandler.js deleted file mode 100644 index 32bc1ab..0000000 --- a/server/handlers/LoginHandler.js +++ /dev/null @@ -1,79 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.authenticate = exports.ProcessLogin = void 0; -const loginManager = __importStar(require("../db/loginmanager")); -const authenticator_1 = require("../lib/authenticator"); -const ProcessLogin = (req, res) => { - console.log('request.body', req.body); - const username = req.body.username; - const password = req.body.password; - console.log('username', username); - console.log('password', password); - if (username && password) { - console.log('>> can try to login'); - return loginManager - .getOne(username, password) - .then((data) => { - if (!data) { - console.warn('No data!'); - return res.sendStatus(401); - } - else { - console.log('>> WE have data!', data); - const token = authenticator_1.generateAccessToken(username); - console.log(token); - } - }) - .catch((err) => { - console.error(err); - return res.status(500).send({ - message: err.message || 'Some error occurred while querying the database.', - }); - }); - } - else { - console.log('No shit'); - return res.sendStatus(401); - } -}; -exports.ProcessLogin = ProcessLogin; -async function processLoginV2(username, password) { - console.log('>> LoginHandler::processLoginV2'); - console.log('username', username); - console.log('password', password); - const user = await loginManager.getOne(username, password); - if (!user) - throw 'Username or password is incorrect'; - const id = user.id; - const token = authenticator_1.generateAccessToken(username); - console.log('>> LoginHandler::processLoginV2 : return ', { id: id, token }); - return { id: id, token }; -} -const authenticate = (req, res, next) => { - console.log('>> LoginHandler::authenticate'); - const { username, password } = req.body; - processLoginV2(username, password) - .then((user) => res.json(user)) - .catch(next); -}; -exports.authenticate = authenticate; -//# sourceMappingURL=LoginHandler.js.map \ No newline at end of file diff --git a/server/handlers/LoginHandler.js.map b/server/handlers/LoginHandler.js.map deleted file mode 100644 index 9b0966f..0000000 --- a/server/handlers/LoginHandler.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"LoginHandler.js","sourceRoot":"","sources":["../../src/handlers/LoginHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,iEAAmD;AAGnD,wDAA2D;AAEpD,MAAM,YAAY,GAAG,CAAC,GAAoB,EAAE,GAAqB,EAAE,EAAE;IAE1E,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAEtC,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;IAC3C,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;IAE3C,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAClC,IAAI,QAAQ,IAAI,QAAQ,EAAE;QACxB,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnC,OAAO,YAAY;aAChB,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC;aAC1B,IAAI,CAAC,CAAC,IAAS,EAAE,EAAE;YAClB,IAAI,CAAC,IAAI,EAAE;gBAET,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBACzB,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;aAC5B;iBAAM;gBACL,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;gBACtC,MAAM,KAAK,GAAG,mCAAmB,CAAC,QAAQ,CAAC,CAAC;gBAC5C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;aAIpB;QACH,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAO,EAAE,EAAE;YACjB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,OAAO,EAAE,GAAG,CAAC,OAAO,IAAI,kDAAkD;aAC3E,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;KACN;SAAM;QACL,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEvB,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;KAC5B;AAGH,CAAC,CAAC;AAxCW,QAAA,YAAY,gBAwCvB;AAEF,KAAK,UAAU,cAAc,CAAC,QAAgB,EAAE,QAAgB;IAC9D,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAG/C,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAElC,MAAM,IAAI,GAAQ,MAAM,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAEhE,IAAI,CAAC,IAAI;QAAE,MAAM,mCAAmC,CAAC;IAErD,MAAM,EAAE,GAAG,IAAI,CAAC,EAAG,CAAC;IAGpB,MAAM,KAAK,GAAG,mCAAmB,CAAC,QAAQ,CAAC,CAAC;IAE5C,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAE5E,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AAC3B,CAAC;AAEM,MAAM,YAAY,GAAG,CAAC,GAAoB,EAAE,GAAqB,EAAE,IAA0B,EAAE,EAAE;IACtG,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAC7C,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;IACxC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC;SAC/B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC9B,KAAK,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC,CAAC;AANW,QAAA,YAAY,gBAMvB"} \ No newline at end of file diff --git a/server/lib/ValidateRequest.d.ts b/server/lib/ValidateRequest.d.ts deleted file mode 100644 index 8a5553f..0000000 --- a/server/lib/ValidateRequest.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import express from 'express'; -import Joi from 'joi'; -export declare function validateRequest(req: express.Request, next: express.NextFunction, schema: Joi.Schema): void; diff --git a/server/lib/ValidateRequest.js b/server/lib/ValidateRequest.js deleted file mode 100644 index baa3578..0000000 --- a/server/lib/ValidateRequest.js +++ /dev/null @@ -1,20 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.validateRequest = void 0; -function validateRequest(req, next, schema) { - const options = { - abortEarly: false, - allowUnknown: true, - stripUnknown: true - }; - const { error, value } = schema.validate(req.body, options); - if (error) { - next(`Validation error: ${error.details.map(x => x.message).join(', ')}`); - } - else { - req.body = value; - next(); - } -} -exports.validateRequest = validateRequest; -//# sourceMappingURL=ValidateRequest.js.map \ No newline at end of file diff --git a/server/lib/ValidateRequest.js.map b/server/lib/ValidateRequest.js.map deleted file mode 100644 index 1da0763..0000000 --- a/server/lib/ValidateRequest.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"ValidateRequest.js","sourceRoot":"","sources":["../../src/lib/ValidateRequest.ts"],"names":[],"mappings":";;;AAGA,SAAgB,eAAe,CAAC,GAAmB,EAAE,IAAyB,EAAE,MAAiB;IAC7F,MAAM,OAAO,GAAG;QACZ,UAAU,EAAE,KAAK;QACjB,YAAY,EAAE,IAAI;QAClB,YAAY,EAAE,IAAI;KACrB,CAAC;IACF,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC5D,IAAI,KAAK,EAAE;QACP,IAAI,CAAC,qBAAqB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;KAC7E;SAAM;QACH,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC;QACjB,IAAI,EAAE,CAAC;KACV;AACL,CAAC;AAbD,0CAaC"} \ No newline at end of file diff --git a/server/lib/authenticator.d.ts b/server/lib/authenticator.d.ts deleted file mode 100644 index 0bffd3e..0000000 --- a/server/lib/authenticator.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import express from "express"; -export declare function authenticateToken(req: any, res: express.Response, next: express.NextFunction): express.Response> | undefined; -export declare function generateAccessToken(username: string): string; diff --git a/server/lib/authenticator.js b/server/lib/authenticator.js deleted file mode 100644 index 0e5e94f..0000000 --- a/server/lib/authenticator.js +++ /dev/null @@ -1,47 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.generateAccessToken = exports.authenticateToken = void 0; -const jwt = __importStar(require("jsonwebtoken")); -function authenticateToken(req, res, next) { - const authHeader = req.headers['authorization']; - const token = authHeader && authHeader.split(' ')[1]; - if (!token) - return res.sendStatus(401); - console.log("token", token); - jwt.verify(token, process.env.TOKEN_SECRET, (err, user) => { - console.error(err); - if (err) - return res.sendStatus(403); - req.user = user; - next(); - }); -} -exports.authenticateToken = authenticateToken; -function generateAccessToken(username) { - const payload = { - username - }; - const tokenSecret = process.env.TOKEN_SECRET; - return jwt.sign(payload, tokenSecret, { expiresIn: '3h' }); -} -exports.generateAccessToken = generateAccessToken; -//# sourceMappingURL=authenticator.js.map \ No newline at end of file diff --git a/server/lib/authenticator.js.map b/server/lib/authenticator.js.map deleted file mode 100644 index 2f64dd9..0000000 --- a/server/lib/authenticator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"authenticator.js","sourceRoot":"","sources":["../../src/lib/authenticator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,kDAAoC;AAEpC,SAAgB,iBAAiB,CAAC,GAAQ,EAAG,GAAqB,EAAE,IAA0B;IAC1F,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAEhD,MAAM,KAAK,GACP,UAAU,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAE3C,IAAI,CAAC,KAAK;QAAE,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAEvC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAE5B,GAAG,CAAC,MAAM,CACN,KAAe,EACf,OAAO,CAAC,GAAG,CAAC,YAAsB,EAClC,CAAC,GAAQ,EAAE,IAAS,EAAE,EAAE;QACpB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACpC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;QAChB,IAAI,EAAE,CAAC;IACX,CAAC,CACJ,CAAC;AAEN,CAAC;AArBD,8CAqBC;AAED,SAAgB,mBAAmB,CAAC,QAAe;IAE/C,MAAM,OAAO,GAAG;QACZ,QAAQ;KACX,CAAC;IACF,MAAM,WAAW,GAAW,OAAO,CAAC,GAAG,CAAC,YAAa,CAAC;IACtD,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC/D,CAAC;AAPD,kDAOC"} \ No newline at end of file diff --git a/server/routes/login.d.ts b/server/routes/login.d.ts deleted file mode 100644 index 35fbb85..0000000 --- a/server/routes/login.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const Login: (app: any) => void; diff --git a/server/routes/login.js b/server/routes/login.js deleted file mode 100644 index ecac974..0000000 --- a/server/routes/login.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Login = void 0; -const LoginHandler_1 = require("../handlers/LoginHandler"); -const joi_1 = __importDefault(require("joi")); -const ValidateRequest_1 = require("../lib/ValidateRequest"); -function loginSchema(req, res, next) { - const schema = joi_1.default.object({ - username: joi_1.default.string().required(), - password: joi_1.default.string().required(), - }); - ValidateRequest_1.validateRequest(req, next, schema); -} -const Login = (app) => { - app.route('/login').post(loginSchema, LoginHandler_1.authenticate); -}; -exports.Login = Login; -//# sourceMappingURL=login.js.map \ No newline at end of file diff --git a/server/routes/login.js.map b/server/routes/login.js.map deleted file mode 100644 index aee1eb0..0000000 --- a/server/routes/login.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/routes/login.ts"],"names":[],"mappings":";;;;;;AACA,2DAAsE;AAEtE,8CAAsB;AAEtB,4DAAyD;AAEzD,SAAS,WAAW,CAAC,GAAoB,EAAE,GAAqB,EAAE,IAA0B;IAC1F,MAAM,MAAM,GAAG,aAAG,CAAC,MAAM,CAAC;QACxB,QAAQ,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QACjC,QAAQ,EAAE,aAAG,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KAClC,CAAC,CAAC;IACH,iCAAe,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACrC,CAAC;AAEM,MAAM,KAAK,GAAG,CAAC,GAAQ,EAAE,EAAE;IAChC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,2BAAY,CAAC,CAAC;AACtD,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB"} \ No newline at end of file diff --git a/server/server.d.ts b/server/server.d.ts deleted file mode 100644 index 2f98b85..0000000 --- a/server/server.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Application } from 'express'; -export declare class App { - protected app: Application; - constructor(NODE_ENV?: string, PORT?: number); -} diff --git a/server/server.js b/server/server.js deleted file mode 100644 index f058f3a..0000000 --- a/server/server.js +++ /dev/null @@ -1,66 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.App = void 0; -const dotenv = __importStar(require("dotenv")); -const express_1 = __importDefault(require("express")); -const helmet_1 = __importDefault(require("helmet")); -const cors_1 = __importDefault(require("cors")); -const morgan_1 = __importDefault(require("morgan")); -const path = __importStar(require("path")); -const login_1 = require("./routes/login"); -const index_1 = __importDefault(require("./routes/index")); -const constants_1 = require("./lib/constants"); -dotenv.config(); -class App { - constructor(NODE_ENV = 'development', PORT = 8080) { - const serverPort = process.env.PORT || PORT; - const sitePath = 'public'; - const corsOptions = { credentials: false }; - this.app = express_1.default(); - this.app.use(morgan_1.default('dev')); - this.app.use(express_1.default.json()); - this.app.use(express_1.default.urlencoded({ extended: false })); - this.app.use(cors_1.default(corsOptions)); - this.app.use(helmet_1.default()); - this.app.set('trust proxy', 1); - const login = login_1.Login(this.app); - this.app.get('/', (req, res) => { - console.log('p', path.join(process.cwd(), sitePath)); - res.sendFile('index.html', { root: path.join(process.cwd(), sitePath) }); - }); - this.app.use(`${process.env.URL_PREFIX}`, index_1.default); - this.app.use('*', (req, res) => { - return res.status(404).json({ - success: false, - message: constants_1.ERROR_MESSAGES.ENDPOINT_NOT_FOUND, - }); - }); - this.app.listen(serverPort, function () { - console.log('The server is running in port localhost: ', serverPort); - }); - } -} -exports.App = App; -//# sourceMappingURL=server.js.map \ No newline at end of file diff --git a/server/server.js.map b/server/server.js.map deleted file mode 100644 index a426528..0000000 --- a/server/server.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,sDAA+C;AAC/C,oDAA4B;AAC5B,gDAAyC;AACzC,oDAA4B;AAE5B,2CAA6B;AAE7B,0CAAuC;AAEvC,2DAAyC;AAEzC,+CAAiD;AAEjD,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAa,GAAG;IAGd,YAAY,QAAQ,GAAG,aAAa,EAAE,IAAI,GAAG,IAAI;QAC/C,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;QAC5C,MAAM,QAAQ,GAAG,QAAQ,CAAC;QAC1B,MAAM,WAAW,GAAgB,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;QAExD,IAAI,CAAC,GAAG,GAAG,iBAAO,EAAE,CAAC;QACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAE5B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAEtD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,cAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QAChC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAM,EAAE,CAAC,CAAC;QAEvB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;QAG/B,MAAM,KAAK,GAAG,aAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAE9B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAoB,EAAE,GAAqB,EAAE,EAAE;YAChE,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;YACrD,GAAG,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC3E,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,eAAW,CAAC,CAAC;QAEvD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YAC7B,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;gBAC1B,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,0BAAc,CAAC,kBAAkB;aAC3C,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE;YAC1B,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,UAAU,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC;IACL,CAAC;CA2BF;AAlED,kBAkEC"} \ No newline at end of file diff --git a/src/controllers/AccessController.ts b/src/controllers/AccessController.ts index 55a34dc..e74951b 100644 --- a/src/controllers/AccessController.ts +++ b/src/controllers/AccessController.ts @@ -1,12 +1,22 @@ -import express from "express"; +import express from 'express'; + +import { ERROR_MESSAGES, STATUS_CODES } from '../lib/constants'; + +const IAM = 'AccessController'; export default { - onLogin: async (req: any, res: express.Response): Promise => { - return res.status(200).json({ - success: true, - token: req.authToken, - userId: req.userId, - }) - } -} + onLogin: async (req: any, res: express.Response): Promise => { + if (!req.userId) return res.status(STATUS_CODES.UNAUTHORIZED).json({ success: false, message: ERROR_MESSAGES.UNAUTHORIZED }); + console.log(req.body.username, req.body.password); + // const user =await getOne(req.body.username, req.body.password); + + console.log(`${IAM}::onLogin`, req.userId); + + return res.status(STATUS_CODES.OK).json({ + success: true, + token: req.authToken, + userId: req.userId, + }); + }, +}; diff --git a/src/controllers/ECGController.ts b/src/controllers/ECGController.ts index ab6124d..4957df8 100644 --- a/src/controllers/ECGController.ts +++ b/src/controllers/ECGController.ts @@ -1,9 +1,11 @@ -const MyID = 'ECGController'; +import express from 'express'; + +const IAM = 'ECGController'; export default { - onGetECG: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetECG` - }) - } -} + onGetECG: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGetECG`, + }); + }, +}; diff --git a/src/controllers/IncidentsController.ts b/src/controllers/IncidentsController.ts index 333a47b..e817d6d 100644 --- a/src/controllers/IncidentsController.ts +++ b/src/controllers/IncidentsController.ts @@ -1,15 +1,17 @@ -const MyID = 'IncidentsController'; +import express from 'express'; + +const IAM = 'IncidentsController'; export default { - onGetIncident: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetIncident` - }) - }, - onUploadFiles: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onUploadFiles` - }) - } -} + onGetIncident: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGetIncident`, + }); + }, + onUploadFiles: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onUploadFiles`, + }); + }, +}; diff --git a/src/controllers/IncidentsV2Controller.ts b/src/controllers/IncidentsV2Controller.ts index adeb6a2..1c46961 100644 --- a/src/controllers/IncidentsV2Controller.ts +++ b/src/controllers/IncidentsV2Controller.ts @@ -1,153 +1,207 @@ -const MyID = 'IncidentsV2Controller'; +import express from 'express'; +import { Casualty } from '../models/Casualty'; +import { StartIncidentPacket } from '../models/StartIncident'; + +import { ERROR_MESSAGES, STATUS_CODES } from '../lib/constants'; + +import * as incidentV2PG from '../db/incidentV2PG'; + +const IAM = 'IncidentsV2Controller'; export default { - onUpdateCasualty: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onUpdateCasualty` - }) - }, - onStartIncident: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onStartIncident` - }) - }, - onSubmit: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onSubmit` - }) - }, - onControllerVersion: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onControllerVersion` - }) - }, - onGetChats: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetChats` - }) - }, - onGetCasualty: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetCasualty` - }) - }, - onGetGroundChat: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetGroundChat` - }) - }, - onChat: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onChat` - }) - }, - onGetPanelInfo: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetPanelInfo` - }) - }, - onListIncidents: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onListIncidents` - }) - }, - onListClosedIncidents: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onListClosedIncidents` - }) - }, - onListActiveIncidents: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onListActiveIncidents` - }) - }, - onListEvents: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onListEvents` - }) - }, - onListClosedEvents: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onStartIncident` - }) - }, - onAcknowledgeAir: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onAcknowledgeAir` - }) - }, - onAcknowledgeGround: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onAcknowledgeGround` - }) - }, - onTypingAir: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onTypingAir` - }) - }, - onTypingGround: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onTypingGround` - }) - }, - onNotTypingGround: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onNotTypingGround` - }) - }, - onCheckTypingGround: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onCheckTypingGround` - }) - }, - onCheckTypingAir: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onCheckTypingAir` - }) - }, - onOnlineAir: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onOnlineAir` - }) - }, - onOnlineGround: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onOnlineGround` - }) - }, - onCheckOnlineGround: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onCheckOnlineGround` - }) - }, - onCheckOnlineAir: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onCheckOnlineAir` - }) - } -} + onUpdateCasualty: async (req: any, res: express.Response) => { + console.log(`${IAM}::onUpdateCasualty req.body`, req.body); + + const casualtyRec:Casualty = req.body; + + console.log(`${IAM}::onUpdateCasualty casualtyRec`, casualtyRec); + + incidentV2PG.upsertCasualty(casualtyRec).then(()=> { + return res.status(STATUS_CODES.OK).json({ + success: true, + message: `${IAM}::onUpdateCasualty`, + }); + + }).catch((err) => { + console.error(IAM, err); + return res.status(STATUS_CODES.INTERNAL_SERVER_ERROR).json({ + success: false, + message: err.message, + }); + + }); + + }, + onStartIncident: async (req: any, res: express.Response) => { + console.log(`${IAM}::onStartIncident req.body`, req.body); + + const newIncident:StartIncidentPacket = req.body; + + console.log(`${IAM}::onStartIncident newIncident`, newIncident); + + return res.status(200).json({ + success: true, + message: `${IAM}::onStartIncident`, + }); + }, + onSubmit: async (req: any, res: express.Response) => { + console.log(`${IAM}::onSubmit req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onSubmit`, + }); + }, + onControllerVersion: async (req: any, res: express.Response) => { + console.log(`${IAM}::onControllerVersion req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onControllerVersion`, + }); + }, + onGetChats: async (req: any, res: express.Response) => { + console.log(`${IAM}::onGetChats req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onGetChats`, + }); + }, + onGetCasualty: async (req: any, res: express.Response) => { + console.log(`${IAM}::onGetCasualty req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onGetCasualty`, + }); + }, + onGetGroundChat: async (req: any, res: express.Response) => { + console.log(`${IAM}::onGetGroundChat req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onGetGroundChat`, + }); + }, + onChat: async (req: any, res: express.Response) => { + console.log(`${IAM}::onChat req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onChat`, + }); + }, + onGetPanelInfo: async (req: any, res: express.Response) => { + console.log(`${IAM}::onGetPanelInfo req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onGetPanelInfo`, + }); + }, + onListIncidents: async (req: any, res: express.Response) => { + console.log(`${IAM}::onListIncidents req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onListIncidents`, + }); + }, + onListClosedIncidents: async (req: any, res: express.Response) => { + console.log(`${IAM}::onListClosedIncidents req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onListClosedIncidents`, + }); + }, + onListActiveIncidents: async (req: any, res: express.Response) => { + console.log(`${IAM}::onListActiveIncidents req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onListActiveIncidents`, + }); + }, + onListEvents: async (req: any, res: express.Response) => { + console.log(`${IAM}::onListEvents req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onListEvents`, + }); + }, + onListClosedEvents: async (req: any, res: express.Response) => { + console.log(`${IAM}::onListClosedEvents req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onStartIncident`, + }); + }, + onAcknowledgeAir: async (req: any, res: express.Response) => { + console.log(`${IAM}::onAcknowledgeAir req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onAcknowledgeAir`, + }); + }, + onAcknowledgeGround: async (req: any, res: express.Response) => { + console.log(`${IAM}::onAcknowledgeGround req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onAcknowledgeGround`, + }); + }, + onTypingAir: async (req: any, res: express.Response) => { + console.log(`${IAM}::onTypingAir req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onTypingAir`, + }); + }, + onTypingGround: async (req: any, res: express.Response) => { + console.log(`${IAM}::onTypingGround req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onTypingGround`, + }); + }, + onNotTypingGround: async (req: any, res: express.Response) => { + console.log(`${IAM}::onNotTypingGround req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onNotTypingGround`, + }); + }, + onCheckTypingGround: async (req: any, res: express.Response) => { + console.log(`${IAM}::onCheckTypingGround req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onCheckTypingGround`, + }); + }, + onCheckTypingAir: async (req: any, res: express.Response) => { + console.log(`${IAM}::onCheckTypingAir req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onCheckTypingAir`, + }); + }, + onOnlineAir: async (req: any, res: express.Response) => { + console.log(`${IAM}::onOnlineAir req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onOnlineAir`, + }); + }, + onOnlineGround: async (req: any, res: express.Response) => { + console.log(`${IAM}::onOnlineGround req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onOnlineGround`, + }); + }, + onCheckOnlineGround: async (req: any, res: express.Response) => { + console.log(`${IAM}::onCheckOnlineGround req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onCheckOnlineGround`, + }); + }, + onCheckOnlineAir: async (req: any, res: express.Response) => { + console.log(`${IAM}::onCheckOnlineAir req.body`, req.body); + return res.status(200).json({ + success: true, + message: `${IAM}::onCheckOnlineAir`, + }); + }, +}; diff --git a/src/controllers/ReceiveController.ts b/src/controllers/ReceiveController.ts index d5ce5f0..231ab82 100644 --- a/src/controllers/ReceiveController.ts +++ b/src/controllers/ReceiveController.ts @@ -1,34 +1,35 @@ -const MyID = 'ReceiveController'; -export default { - onGet: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGet` - }) - }, - onGetById: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetById` - }) - }, - onPost: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onPost` - }) - }, - onPut: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onPut` - }) - }, - onDelete: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onDelete` - }) - } +import express from 'express'; -} +const IAM = 'ReceiveController'; +export default { + onGet: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGet`, + }); + }, + onGetById: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGetById`, + }); + }, + onPost: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onPost`, + }); + }, + onPut: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onPut`, + }); + }, + onDelete: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onDelete`, + }); + }, +}; diff --git a/src/controllers/TestController.ts b/src/controllers/TestController.ts index ff6930c..38cff08 100644 --- a/src/controllers/TestController.ts +++ b/src/controllers/TestController.ts @@ -1,9 +1,11 @@ -const MyID = 'TestController'; +import express from 'express'; + +const IAM = 'TestController'; export default { - onGet: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGet` - }) - } -} + onGet: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGet`, + }); + }, +}; diff --git a/src/controllers/TestsController.ts b/src/controllers/TestsController.ts index 0109eec..5587386 100644 --- a/src/controllers/TestsController.ts +++ b/src/controllers/TestsController.ts @@ -1,34 +1,35 @@ -const MyID = 'TestsController'; -export default { - onGet: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGet` - }) - }, - onGetById: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetById` - }) - }, - onPost: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onPost` - }) - }, - onPut: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onPut` - }) - }, - onDelete: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onDelete` - }) - } +import express from 'express'; -} +const IAM = 'TestsController'; +export default { + onGet: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGet`, + }); + }, + onGetById: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGetById`, + }); + }, + onPost: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onPost`, + }); + }, + onPut: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onPut`, + }); + }, + onDelete: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onDelete`, + }); + }, +}; diff --git a/src/controllers/UsersController.ts b/src/controllers/UsersController.ts index bd0fefb..6a3bd47 100644 --- a/src/controllers/UsersController.ts +++ b/src/controllers/UsersController.ts @@ -1,34 +1,36 @@ -const MyID = 'UsersController'; -export default { - onGet: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGet` - }) - }, - onGetById: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetById` - }) - }, - onPost: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onPost` - }) - }, - onPut: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onPut` - }) - }, - onDelete: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onDelete` - }) - } +import express from 'express'; -} +const IAM = 'UsersController'; + +export default { + onGet: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGet`, + }); + }, + onGetById: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGetById`, + }); + }, + onPost: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onPost`, + }); + }, + onPut: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onPut`, + }); + }, + onDelete: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onDelete`, + }); + }, +}; diff --git a/src/controllers/ValuesController.ts b/src/controllers/ValuesController.ts index 0f3a378..af01ef7 100644 --- a/src/controllers/ValuesController.ts +++ b/src/controllers/ValuesController.ts @@ -1,34 +1,35 @@ -const MyID = 'ValuesController'; -export default { - onGet: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGet` - }) - }, - onGetById: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onGetById` - }) - }, - onPost: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onPost` - }) - }, - onPut: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onPut` - }) - }, - onDelete: async (req: any, res: any, next: any) => { - return res.status(200).json({ - success: true, - message: `${MyID}::onDelete` - }) - } +import express from 'express'; -} +const IAM = 'ValuesController'; +export default { + onGet: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGet`, + }); + }, + onGetById: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onGetById`, + }); + }, + onPost: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onPost`, + }); + }, + onPut: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onPut`, + }); + }, + onDelete: async (req: any, res: express.Response) => { + return res.status(200).json({ + success: true, + message: `${IAM}::onDelete`, + }); + }, +}; diff --git a/src/db/connectPG.ts b/src/db/connectPG.ts new file mode 100644 index 0000000..0428348 --- /dev/null +++ b/src/db/connectPG.ts @@ -0,0 +1,13 @@ +import pgPromise from 'pg-promise'; + +const IAM = 'connectPG'; + +const pgp = pgPromise(); + +const login = `${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASSWORD}`; + +const conn = `postgres://${login}@localhost:5432/${process.env.POSTGRES_DB}`; + +console.log(`${IAM}::URL_PREFIX`, process.env.URL_PREFIX); + +export const db = pgp(conn); diff --git a/src/db/incidentV2PG.ts b/src/db/incidentV2PG.ts new file mode 100644 index 0000000..72141b6 --- /dev/null +++ b/src/db/incidentV2PG.ts @@ -0,0 +1,55 @@ +import { db } from './connectPG'; +import { Casualty } from '../models/Casualty'; + +import { ERROR_MESSAGES } from '../lib/constants'; + +const IAM = 'incidentV2PG'; + +export const upsertCasualty = async (casualtyRecord: Casualty): Promise => { + console.log(`${IAM}::upsertCasualty`); + + const { + incidentid, + gender, + dob, + age, + alcohol, + allergies, + allergydetails, + medicinetaken, + medhist, + flight, + seat, + arrivalairport, + lastmeal, + detailsadded, + complaint, + history, + deleted, + } = casualtyRecord; + + const sql = `select * from upsertcasualty($1::varchar, $2::varchar, $3::varchar, $4::smallint, $5::varchar, $6::varchar, $7::varchar, $8::varchar, $9::varchar, $10::varchar, $11::varchar, $12::varchar, $13::varchar, $14::bigint, $15::varchar, $16::varchar, $17::bigint);`; + const shouldbevoid: null = await db.oneOrNone(sql, [ + incidentid, + gender, + dob, + age, + alcohol, + allergies, + allergydetails, + medicinetaken, + medhist, + flight, + seat, + arrivalairport, + lastmeal, + detailsadded, + complaint, + history, + deleted, + ]); + + // if (!user) throw { message: ERROR_MESSAGES.USER_NOT_FOUND }; + + return shouldbevoid; +}; diff --git a/src/db/loginmanagerPG.ts b/src/db/loginmanagerPG.ts new file mode 100644 index 0000000..33156cc --- /dev/null +++ b/src/db/loginmanagerPG.ts @@ -0,0 +1,17 @@ +import { db } from './connectPG'; +import { User } from '../models/User'; + +import { ERROR_MESSAGES } from '../lib/constants'; + +const IAM = 'loginmanagerPG'; + +export const findByUsernamePassword = async (username: string, password: string): Promise => { + console.log(`${IAM}::findByUsernamePassword`); + + const sql = 'SELECT * FROM users WHERE username = $1 and password = $2'; + const user: User[] | null = await db.oneOrNone(sql, [username, password]); + + if (!user) throw { message: ERROR_MESSAGES.USER_NOT_FOUND }; + + return user; +}; diff --git a/src/development.ts b/src/development.ts index 2e63785..15848f9 100644 --- a/src/development.ts +++ b/src/development.ts @@ -1,2 +1,2 @@ -import * as server from "./server"; -new server.App +import * as server from './server'; +new server.App(); diff --git a/src/handlers/LoginHandler.ts b/src/handlers/LoginHandler.ts index 47e1475..1e250f5 100644 --- a/src/handlers/LoginHandler.ts +++ b/src/handlers/LoginHandler.ts @@ -1,7 +1,7 @@ import express from 'express'; import * as loginManager from '../db/loginmanager'; -import {User} from '../models/User'; +import { User } from '../models/User'; import { generateAccessToken } from '../lib/authenticator'; @@ -18,7 +18,7 @@ export const ProcessLogin = (req: express.Request, res: express.Response) => { console.log('>> can try to login'); return loginManager .getOne(username, password) - .then((data:User) => { + .then((data: User) => { if (!data) { // response.redirect('/'); console.warn('No data!'); @@ -32,7 +32,7 @@ export const ProcessLogin = (req: express.Request, res: express.Response) => { response.redirect('/menu');*/ } }) - .catch((err:any) => { + .catch((err: any) => { console.error(err); return res.status(500).send({ message: err.message || 'Some error occurred while querying the database.', diff --git a/src/lib/ValidateRequest.ts b/src/lib/ValidateRequest.ts index afa5872..b226529 100644 --- a/src/lib/ValidateRequest.ts +++ b/src/lib/ValidateRequest.ts @@ -1,17 +1,17 @@ import express from 'express'; -import Joi from 'joi' +import Joi from 'joi'; -export function validateRequest(req:express.Request, next:express.NextFunction, schema:Joi.Schema):void { - const options = { - abortEarly: false, // include all errors - allowUnknown: true, // ignore unknown props - stripUnknown: true // remove unknown props - }; - const { error, value } = schema.validate(req.body, options); - if (error) { - next(`Validation error: ${error.details.map(x => x.message).join(', ')}`); - } else { - req.body = value; - next(); - } +export function validateRequest(req: express.Request, next: express.NextFunction, schema: Joi.Schema): void { + const options = { + abortEarly: false, // include all errors + allowUnknown: true, // ignore unknown props + stripUnknown: true, // remove unknown props + }; + const { error, value } = schema.validate(req.body, options); + if (error) { + next(`Validation error: ${error.details.map((x) => x.message).join(', ')}`); + } else { + req.body = value; + next(); + } } diff --git a/src/lib/authenticator.ts b/src/lib/authenticator.ts index d14af60..ad683f9 100644 --- a/src/lib/authenticator.ts +++ b/src/lib/authenticator.ts @@ -1,34 +1,28 @@ -import express from "express"; -import * as jwt from "jsonwebtoken"; +import express from 'express'; +import * as jwt from 'jsonwebtoken'; -export function authenticateToken(req: any, res: express.Response, next: express.NextFunction,) { - const authHeader = req.headers['authorization']; +export function authenticateToken(req: any, res: express.Response, next: express.NextFunction) { + const authHeader = req.headers['authorization']; - const token: '' | undefined | string = - authHeader && authHeader.split(' ')[1]; + const token: '' | undefined | string = authHeader && authHeader.split(' ')[1]; - if (!token) return res.sendStatus(401); + if (!token) return res.sendStatus(401); - console.log("token", token); - - jwt.verify( - token as string, - process.env.TOKEN_SECRET as string, - (err: any, user: any) => { - console.error(err); - if (err) return res.sendStatus(403); - req.user = user; - next(); - }, - ); + console.log('token', token); + jwt.verify(token as string, process.env.TOKEN_SECRET as string, (err: any, user: any) => { + console.error(err); + if (err) return res.sendStatus(403); + req.user = user; + next(); + }); } -export function generateAccessToken(username:string) { - // expires after half and hour (1800 seconds = 30 minutes) - const payload = { - username - }; - const tokenSecret: string = process.env.TOKEN_SECRET!; - return jwt.sign(payload, tokenSecret, { expiresIn: '3h' }); +export function generateAccessToken(username: string) { + // expires after half and hour (1800 seconds = 30 minutes) + const payload = { + username, + }; + const tokenSecret: string = process.env.TOKEN_SECRET!; + return jwt.sign(payload, tokenSecret, { expiresIn: '3h' }); } diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 68f820d..5fabe39 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -1,10 +1,14 @@ +import * as statusCodes from 'http-codes'; + export const ERROR_MESSAGES = { - USER_NOT_FOUND: 'User does not exist', - NO_TOKEN: 'No access token provided', - UNAUTHORIZED: "Sorry, we can't find an account with these credentials. Please try again or create a new account.", - ENDPOINT_NOT_FOUND: "API endpoint doesn't exist", - ERRA1: "Incident or item does not exist", - ERRA2: "Invalid timestamp", - ERRA3: "Item already acknowledged", - ERRTG1: "No incident supplied" + USER_NOT_FOUND: 'User does not exist', + NO_TOKEN: 'No access token provided', + UNAUTHORIZED: "Sorry, we can't find an account with these credentials. Please try again or create a new account.", + ENDPOINT_NOT_FOUND: "API endpoint doesn't exist", + ERRA1: 'Incident or item does not exist', + ERRA2: 'Invalid timestamp', + ERRA3: 'Item already acknowledged', + ERRTG1: 'No incident supplied', }; + +export const STATUS_CODES = statusCodes; diff --git a/src/middleware/jwt.ts b/src/middleware/jwt.ts index 1edb135..61a87eb 100644 --- a/src/middleware/jwt.ts +++ b/src/middleware/jwt.ts @@ -1,51 +1,49 @@ import jwt from 'jsonwebtoken'; -import { ERROR_MESSAGES } from '../lib/constants'; +import { ERROR_MESSAGES, STATUS_CODES } from '../lib/constants'; -import { getOne } from '../db/loginmanager'; -import {User} from '../models/User'; -import express from "express"; +import * as PG from '../db/loginmanagerPG'; +import { User } from '../models/User'; +import express from 'express'; const IAM = 'jwt'; -export const encode = async (req: any, res: express.Response, next: express.NextFunction) => { +export const encode = async (req: any, res: express.Response, next: express.NextFunction): Promise => { try { console.log(`>> ${IAM}::encode`); const username: string = req.body.username; const password: string = req.body.password; - console.log(`>> ${IAM}::encode - username`, username); - console.log(`>> ${IAM}::encode - password`, password); - - const user:User = await getOne(username,password); + const user: User = await PG.findByUsernamePassword(username, password); if (user) { console.log(`>> ${IAM}::encode - user`, user); const authToken = jwt.sign( - { - userId: user._id - }, - process.env.TOKEN_SECRET! + { + userId: user._id, + }, + process.env.TOKEN_SECRET!, ); console.log('Auth', authToken); req.authToken = authToken; req.userId = user._id; next(); - } else { throw new Error(ERROR_MESSAGES.UNAUTHORIZED); } } catch (error) { - console.log(error); - return res.status(400).json({ success: false, message: error.message }); + console.log(`${IAM}::caught error`); + console.error(error); + return res.status(STATUS_CODES.BAD_REQUEST).json({ success: false, message: error.message || error.error }); } }; - export const decode = (req: any, res: any, next: any) => { + return next(); + if (!req.headers['authorization']) { - return res.status(401).json({ success: false, message: ERROR_MESSAGES.NO_TOKEN }); + return res.status(STATUS_CODES.UNAUTHORIZED).json({ success: false, message: ERROR_MESSAGES.NO_TOKEN }); } try { const accessToken = req.headers.authorization.split(' ')[1]; @@ -54,7 +52,6 @@ export const decode = (req: any, res: any, next: any) => { return next(); } catch (error) { console.log(error); - return res.status(401).json({ success: false, message: error.message }); + return res.status(STATUS_CODES.UNAUTHORIZED).json({ success: false, message: error.message }); } - }; diff --git a/src/models/Casualty.ts b/src/models/Casualty.ts index eef6134..e78a623 100644 --- a/src/models/Casualty.ts +++ b/src/models/Casualty.ts @@ -1,22 +1,24 @@ export interface Casualty { - id: number; - incidentid: string; - gender: string; - dob: string; - age: number; - alcohol: string; - allergies: string; - allergydetails: string; - medicinetaken: string; - medhist: string; - flight: string; - seat: string; - arrivalairport: string; - lastmeal: string; - detailsadded: number; - detailssent: number; - detailsack: number; - deleted: number; - complain: string; - history: string; + // id: number; + incidentid: string; + gender: string; + dob: string; + age: number; + alcohol: string; + allergies: string; + allergydetails: string; + medicinetaken: string; + medhist: string; + flight: string; + seat: string; + arrivalairport: string; + lastmeal: string; + detailsadded: number; + // detailssent: number; + // detailsack: number; + complaint: string; + history: string; + deleted: number; + + } diff --git a/src/models/Chat.ts b/src/models/Chat.ts index eeef6b7..e182000 100644 --- a/src/models/Chat.ts +++ b/src/models/Chat.ts @@ -1,10 +1,10 @@ export interface Chat { id: number; incidentid: string; - aibermsg:string; + aibermsg: string; controlmsg: string; - msgtime:number; - msgrecd:number; - msgread:number; - deleted:number; + msgtime: number; + msgrecd: number; + msgread: number; + deleted: number; } diff --git a/src/models/ChatStatus.ts b/src/models/ChatStatus.ts index f1bb4a2..2043607 100644 --- a/src/models/ChatStatus.ts +++ b/src/models/ChatStatus.ts @@ -1,10 +1,9 @@ export interface ChatStatus { - id: number; - incidentid: string; - typingair: number; - typingground: number; - lasttypingair: number; - lasttypingground: number; - deleted: number; - + id: number; + incidentid: string; + typingair: number; + typingground: number; + lasttypingair: number; + lasttypingground: number; + deleted: number; } diff --git a/src/models/IncidentItemV2.ts b/src/models/IncidentItemV2.ts index 00d0fed..d4ac63a 100644 --- a/src/models/IncidentItemV2.ts +++ b/src/models/IncidentItemV2.ts @@ -1,23 +1,25 @@ export interface IncidentItem { - Id: number; - incidentid: string; - incidenttime: number; - username: string; - reporttime: number; - latitude: number; - longitude: number; - message_type: string; - entry_type: string; - entry_val1: string; - entry_val2: string; - ackground: number; - ackair: number; - battery: number; - pluggedin: boolean; - reportlog: string; - ecgtrace: string; - typingair: number; - typingground: number; - onlineair: number; - onlineground: number; + Id: number; + incidentid: string; + incidenttime: number; + username: string; + reporttime: number; + latitude: number; + longitude: number; + message_type: string; + entry_type: string; + entry_val1: string; + entry_val2: string; + ackground: number; + ackair: number; + battery: number; + pluggedin: boolean; + reportlog: string; + ecgtrace: string; + typingair: number; + typingground: number; + onlineair: number; + onlineground: number; } + + diff --git a/src/models/StartIncident.ts b/src/models/StartIncident.ts new file mode 100644 index 0000000..c53683d --- /dev/null +++ b/src/models/StartIncident.ts @@ -0,0 +1,21 @@ +export interface StartIncidentPacket { + incidentid?: string; + username?: string; + incidenttime?: number; + reporttime?: number; + latitude?: string; + longitude?: string; + AVPU?: string; + avpustatus?: string; + A?: string; + astatus?: string; + B?: string; + bstatus?: string; + C?: string; + cstatus?: string; + U?: string; + ustatus?: string; + battery?: number; + pluggedin?: number; + reportlog?: string; +} diff --git a/src/models/User.ts b/src/models/User.ts index 2bd4b5d..9c6aba8 100644 --- a/src/models/User.ts +++ b/src/models/User.ts @@ -1,7 +1,7 @@ export interface User { - id: number; - username: string; - password: string; - email:string; - _id: string; + id: number; + username: string; + password: string; + email: string; + _id: string; } diff --git a/src/routes/index.ts b/src/routes/index.ts index 24b91dc..53d9929 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,19 +1,21 @@ import express, { Router } from 'express'; import { decode, encode } from '../middleware/jwt'; -import Checks from "../middleware/Checks"; +import { STATUS_CODES } from '../lib/constants'; +import Checks from '../middleware/Checks'; import accessController from '../controllers/AccessController'; import ecgController from '../controllers/ECGController'; import incidentsController from '../controllers/IncidentsController'; import incidentsV2Controller from '../controllers/IncidentsV2Controller'; +const IAM = 'Index'; const router: Router = express.Router(); router.post('/login', encode, accessController.onLogin); router.get('/test', decode, async (req: express.Request, res: express.Response) => { - return res.status(200).json({ + return res.status(STATUS_CODES.OK).json({ success: true, message: 'You are good to go', }); @@ -28,35 +30,44 @@ router.get('/Incidents/GetIncident', decode, incidentsController.onGetIncident); router.post('/Incidents/UploadFiles', decode, incidentsController.onUploadFiles); // -router.post('/IncidentsV2/updatecasualty', decode, incidentsV2Controller.onUpdateCasualty); -router.post('/IncidentsV2/startincident', decode, incidentsV2Controller.onStartIncident); -router.post('/IncidentsV2/submit', decode, incidentsV2Controller.onSubmit); -router.post('/IncidentsV2/ControllerVersion', decode, incidentsV2Controller.onControllerVersion); -router.post('/IncidentsV2/getchats', decode, incidentsV2Controller.onGetChats); -router.post('/IncidentsV2/getcasualty', decode, incidentsV2Controller.onGetCasualty); -router.post('/IncidentsV2/getgroundchat', decode, incidentsV2Controller.onGetGroundChat); -router.post('/IncidentsV2/chat', decode, incidentsV2Controller.onChat); -router.post('/IncidentsV2/GetPanelInfo', decode, Checks.incidentNotNull, incidentsV2Controller.onGetPanelInfo); -router.post('/IncidentsV2/listincidents', decode, incidentsV2Controller.onListIncidents); -router.post('/IncidentsV2/listclosedincidents', decode, incidentsV2Controller.onListClosedIncidents); -router.post('/IncidentsV2/listactiveincidents', decode, incidentsV2Controller.onListActiveIncidents); -router.post('/IncidentsV2/listevents', decode, Checks.incidentExists, incidentsV2Controller.onListEvents); -router.post('/IncidentsV2/listclosedevents', decode, incidentsV2Controller.onListClosedEvents); -router.post('/IncidentsV2/acknowledgeair', decode, Checks.incidentExists, Checks.alreadyAcknowledged, Checks.validTimestamp, incidentsV2Controller.onAcknowledgeAir); -router.post('/IncidentsV2/acknowledgeground', decode, Checks.incidentExists, Checks.alreadyAcknowledged, Checks.validTimestamp, incidentsV2Controller.onAcknowledgeGround); -router.post('/IncidentsV2/typingair', decode, Checks.incidentExists, incidentsV2Controller.onTypingAir); -router.post('/IncidentsV2/typingground', decode, Checks.incidentExists, incidentsV2Controller.onTypingGround); -router.post('/IncidentsV2/nottypingground', decode, Checks.incidentExists, incidentsV2Controller.onTypingGround); -router.post('/IncidentsV2/checktypingground', decode, Checks.incidentNotNull, incidentsV2Controller.onCheckTypingGround); -router.post('/IncidentsV2/onlineair', decode, Checks.incidentExists, incidentsV2Controller.onOnlineAir); -router.post('/IncidentsV2/onlineground', decode, Checks.incidentExists, incidentsV2Controller.onOnlineGround); -router.post('/IncidentsV2/checkonlineground', decode, Checks.incidentExists, incidentsV2Controller.onCheckOnlineGround); -router.post('/IncidentsV2/checkonlineair', decode, Checks.incidentExists, incidentsV2Controller.onCheckOnlineAir); - - - - - - +// router.post('/incidentsV2/updatecasualty', decode, incidentsV2Controller.onUpdateCasualty); +router.post('/incidentsV2/updatecasualty', incidentsV2Controller.onUpdateCasualty); +router.post('/incidentsV2/startincident', decode, incidentsV2Controller.onStartIncident); +router.post('/incidentsV2/submit', decode, incidentsV2Controller.onSubmit); +router.post('/incidentsV2/ControllerVersion', decode, incidentsV2Controller.onControllerVersion); +router.post('/incidentsV2/getchats', decode, incidentsV2Controller.onGetChats); +router.post('/incidentsV2/getcasualty', decode, incidentsV2Controller.onGetCasualty); +router.post('/incidentsV2/getgroundchat', decode, incidentsV2Controller.onGetGroundChat); +router.post('/incidentsV2/chat', decode, incidentsV2Controller.onChat); +router.post('/incidentsV2/GetPanelInfo', decode, Checks.incidentNotNull, incidentsV2Controller.onGetPanelInfo); +router.post('/incidentsV2/listincidents', decode, incidentsV2Controller.onListIncidents); +router.post('/incidentsV2/listclosedincidents', decode, incidentsV2Controller.onListClosedIncidents); +router.post('/incidentsV2/listactiveincidents', decode, incidentsV2Controller.onListActiveIncidents); +router.post('/incidentsV2/listevents', decode, Checks.incidentExists, incidentsV2Controller.onListEvents); +router.post('/incidentsV2/listclosedevents', decode, incidentsV2Controller.onListClosedEvents); +router.post( + '/incidentsV2/acknowledgeair', + decode, + Checks.incidentExists, + Checks.alreadyAcknowledged, + Checks.validTimestamp, + incidentsV2Controller.onAcknowledgeAir, +); +router.post( + '/incidentsV2/acknowledgeground', + decode, + Checks.incidentExists, + Checks.alreadyAcknowledged, + Checks.validTimestamp, + incidentsV2Controller.onAcknowledgeGround, +); +router.post('/incidentsV2/typingair', decode, Checks.incidentExists, incidentsV2Controller.onTypingAir); +router.post('/incidentsV2/typingground', decode, Checks.incidentExists, incidentsV2Controller.onTypingGround); +router.post('/incidentsV2/nottypingground', decode, Checks.incidentExists, incidentsV2Controller.onTypingGround); +router.post('/incidentsV2/checktypingground', decode, Checks.incidentNotNull, incidentsV2Controller.onCheckTypingGround); +router.post('/incidentsV2/onlineair', decode, Checks.incidentExists, incidentsV2Controller.onOnlineAir); +router.post('/incidentsV2/onlineground', decode, Checks.incidentExists, incidentsV2Controller.onOnlineGround); +router.post('/incidentsV2/checkonlineground', decode, Checks.incidentExists, incidentsV2Controller.onCheckOnlineGround); +router.post('/incidentsV2/checkonlineair', decode, Checks.incidentExists, incidentsV2Controller.onCheckOnlineAir); export default router; diff --git a/src/server.ts b/src/server.ts index f77f967..02c7ce8 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,4 +1,5 @@ import * as dotenv from 'dotenv'; +dotenv.config(); import express, { Application } from 'express'; import helmet from 'helmet'; @@ -7,13 +8,9 @@ import logger from 'morgan'; import * as path from 'path'; -import { Login } from './routes/login'; - import indexRouter from './routes/index'; -import { ERROR_MESSAGES } from './lib/constants'; - -dotenv.config(); +import { ERROR_MESSAGES, STATUS_CODES } from './lib/constants'; export class App { protected app: Application; @@ -34,9 +31,6 @@ export class App { this.app.set('trust proxy', 1); - // /// - const login = Login(this.app); - this.app.get('/', (req: express.Request, res: express.Response) => { console.log('p', path.join(process.cwd(), sitePath)); res.sendFile('index.html', { root: path.join(process.cwd(), sitePath) }); @@ -45,7 +39,7 @@ export class App { this.app.use(`${process.env.URL_PREFIX}`, indexRouter); this.app.use('*', (req, res) => { - return res.status(404).json({ + return res.status(STATUS_CODES.NOT_FOUND).json({ success: false, message: ERROR_MESSAGES.ENDPOINT_NOT_FOUND, }); @@ -55,30 +49,4 @@ export class App { console.log('The server is running in port localhost: ', serverPort); }); } - - /* authenticateToken( - req: any, - res: express.Response, - next: express.NextFunction, - ) { - const authHeader = req.headers['authorization']; - - const token: '' | undefined | string = - authHeader && authHeader.split(' ')[1]; - - if (!token) return res.sendStatus(401); - - console.log("token", token); - - jwt.verify( - token as string, - process.env.TOKEN_SECRET as string, - (err: any, user: any) => { - console.error(err); - if (err) return res.sendStatus(403); - req.user = user; - next(); - }, - ); - }*/ }