Server is now receiving messages
DB server set up
This commit is contained in:
parent
e250908de3
commit
e512ae52b0
3
.gitignore
vendored
3
.gitignore
vendored
@ -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/*
|
||||
|
3
db/database.env
Normal file
3
db/database.env
Normal file
@ -0,0 +1,3 @@
|
||||
POSTGRES_USER=aiber_user
|
||||
POSTGRES_PASSWORD=Copper.Nifleheim.246
|
||||
POSTGRES_DB=aiber_database
|
14
db/docker-compose.yml
Normal file
14
db/docker-compose.yml
Normal file
@ -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
|
242
db/setup/init.sql
Normal file
242
db/setup/init.sql
Normal file
@ -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;
|
BIN
db/users.db
Normal file
BIN
db/users.db
Normal file
Binary file not shown.
13
package.json
13
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",
|
||||
|
7
server/commonjs/server.d.ts
vendored
7
server/commonjs/server.d.ts
vendored
@ -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
|
@ -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"}
|
@ -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
|
@ -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"}
|
2
server/db/connect.d.ts
vendored
2
server/db/connect.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import sqlite3 from 'sqlite3';
|
||||
export declare const db: sqlite3.Database;
|
@ -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
|
@ -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"}
|
2
server/db/loginmanager.d.ts
vendored
2
server/db/loginmanager.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
import { User } from '../models/User';
|
||||
export declare const getOne: (username: string, password: string) => User | any;
|
@ -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
|
@ -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"}
|
1
server/development.d.ts
vendored
1
server/development.d.ts
vendored
@ -1 +0,0 @@
|
||||
export {};
|
@ -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
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"development.js","sourceRoot":"","sources":["../src/development.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AACnC,IAAI,MAAM,CAAC,GAAG,CAAA"}
|
2
server/es/development.d.ts
vendored
2
server/es/development.d.ts
vendored
@ -1,2 +0,0 @@
|
||||
export {};
|
||||
//# sourceMappingURL=development.d.ts.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"development.d.ts","sourceRoot":"","sources":["../../src/development.ts"],"names":[],"mappings":""}
|
@ -1,3 +0,0 @@
|
||||
import * as server from "./server";
|
||||
new server.App;
|
||||
//# sourceMappingURL=development.js.map
|
@ -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"}
|
7
server/es/server.d.ts
vendored
7
server/es/server.d.ts
vendored
@ -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
|
@ -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"}
|
@ -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
|
@ -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"}
|
3
server/handlers/LoginHandler.d.ts
vendored
3
server/handlers/LoginHandler.d.ts
vendored
@ -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;
|
@ -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
|
@ -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"}
|
3
server/lib/ValidateRequest.d.ts
vendored
3
server/lib/ValidateRequest.d.ts
vendored
@ -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;
|
@ -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
|
@ -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"}
|
3
server/lib/authenticator.d.ts
vendored
3
server/lib/authenticator.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
import express from "express";
|
||||
export declare function authenticateToken(req: any, res: express.Response, next: express.NextFunction): express.Response<any, Record<string, any>> | undefined;
|
||||
export declare function generateAccessToken(username: string): string;
|
@ -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
|
@ -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"}
|
1
server/routes/login.d.ts
vendored
1
server/routes/login.d.ts
vendored
@ -1 +0,0 @@
|
||||
export declare const Login: (app: any) => void;
|
@ -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
|
@ -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"}
|
5
server/server.d.ts
vendored
5
server/server.d.ts
vendored
@ -1,5 +0,0 @@
|
||||
import { Application } from 'express';
|
||||
export declare class App {
|
||||
protected app: Application;
|
||||
constructor(NODE_ENV?: string, PORT?: number);
|
||||
}
|
@ -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
|
@ -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"}
|
@ -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<express.Response> => {
|
||||
return res.status(200).json({
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -1,9 +1,11 @@
|
||||
const MyID = 'ECGController';
|
||||
import express from 'express';
|
||||
|
||||
const IAM = 'ECGController';
|
||||
export default {
|
||||
onGetECG: async (req: any, res: any, next: any) => {
|
||||
onGetECG: async (req: any, res: express.Response) => {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onGetECG`
|
||||
})
|
||||
}
|
||||
}
|
||||
message: `${IAM}::onGetECG`,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -1,15 +1,17 @@
|
||||
const MyID = 'IncidentsController';
|
||||
import express from 'express';
|
||||
|
||||
const IAM = 'IncidentsController';
|
||||
export default {
|
||||
onGetIncident: async (req: any, res: any, next: any) => {
|
||||
onGetIncident: async (req: any, res: express.Response) => {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onGetIncident`
|
||||
})
|
||||
message: `${IAM}::onGetIncident`,
|
||||
});
|
||||
},
|
||||
onUploadFiles: async (req: any, res: any, next: any) => {
|
||||
onUploadFiles: async (req: any, res: express.Response) => {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onUploadFiles`
|
||||
})
|
||||
}
|
||||
}
|
||||
message: `${IAM}::onUploadFiles`,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -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({
|
||||
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: `${MyID}::onUpdateCasualty`
|
||||
})
|
||||
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: any, next: any) => {
|
||||
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: `${MyID}::onStartIncident`
|
||||
})
|
||||
message: `${IAM}::onStartIncident`,
|
||||
});
|
||||
},
|
||||
onSubmit: async (req: any, res: any, next: any) => {
|
||||
onSubmit: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onSubmit req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onSubmit`
|
||||
})
|
||||
message: `${IAM}::onSubmit`,
|
||||
});
|
||||
},
|
||||
onControllerVersion: async (req: any, res: any, next: any) => {
|
||||
onControllerVersion: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onControllerVersion req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onControllerVersion`
|
||||
})
|
||||
message: `${IAM}::onControllerVersion`,
|
||||
});
|
||||
},
|
||||
onGetChats: async (req: any, res: any, next: any) => {
|
||||
onGetChats: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onGetChats req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onGetChats`
|
||||
})
|
||||
message: `${IAM}::onGetChats`,
|
||||
});
|
||||
},
|
||||
onGetCasualty: async (req: any, res: any, next: any) => {
|
||||
onGetCasualty: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onGetCasualty req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onGetCasualty`
|
||||
})
|
||||
message: `${IAM}::onGetCasualty`,
|
||||
});
|
||||
},
|
||||
onGetGroundChat: async (req: any, res: any, next: any) => {
|
||||
onGetGroundChat: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onGetGroundChat req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onGetGroundChat`
|
||||
})
|
||||
message: `${IAM}::onGetGroundChat`,
|
||||
});
|
||||
},
|
||||
onChat: async (req: any, res: any, next: any) => {
|
||||
onChat: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onChat req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onChat`
|
||||
})
|
||||
message: `${IAM}::onChat`,
|
||||
});
|
||||
},
|
||||
onGetPanelInfo: async (req: any, res: any, next: any) => {
|
||||
onGetPanelInfo: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onGetPanelInfo req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onGetPanelInfo`
|
||||
})
|
||||
message: `${IAM}::onGetPanelInfo`,
|
||||
});
|
||||
},
|
||||
onListIncidents: async (req: any, res: any, next: any) => {
|
||||
onListIncidents: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onListIncidents req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onListIncidents`
|
||||
})
|
||||
message: `${IAM}::onListIncidents`,
|
||||
});
|
||||
},
|
||||
onListClosedIncidents: async (req: any, res: any, next: any) => {
|
||||
onListClosedIncidents: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onListClosedIncidents req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onListClosedIncidents`
|
||||
})
|
||||
message: `${IAM}::onListClosedIncidents`,
|
||||
});
|
||||
},
|
||||
onListActiveIncidents: async (req: any, res: any, next: any) => {
|
||||
onListActiveIncidents: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onListActiveIncidents req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onListActiveIncidents`
|
||||
})
|
||||
message: `${IAM}::onListActiveIncidents`,
|
||||
});
|
||||
},
|
||||
onListEvents: async (req: any, res: any, next: any) => {
|
||||
onListEvents: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onListEvents req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onListEvents`
|
||||
})
|
||||
message: `${IAM}::onListEvents`,
|
||||
});
|
||||
},
|
||||
onListClosedEvents: async (req: any, res: any, next: any) => {
|
||||
onListClosedEvents: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onListClosedEvents req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onStartIncident`
|
||||
})
|
||||
message: `${IAM}::onStartIncident`,
|
||||
});
|
||||
},
|
||||
onAcknowledgeAir: async (req: any, res: any, next: any) => {
|
||||
onAcknowledgeAir: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onAcknowledgeAir req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onAcknowledgeAir`
|
||||
})
|
||||
message: `${IAM}::onAcknowledgeAir`,
|
||||
});
|
||||
},
|
||||
onAcknowledgeGround: async (req: any, res: any, next: any) => {
|
||||
onAcknowledgeGround: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onAcknowledgeGround req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onAcknowledgeGround`
|
||||
})
|
||||
message: `${IAM}::onAcknowledgeGround`,
|
||||
});
|
||||
},
|
||||
onTypingAir: async (req: any, res: any, next: any) => {
|
||||
onTypingAir: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onTypingAir req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onTypingAir`
|
||||
})
|
||||
message: `${IAM}::onTypingAir`,
|
||||
});
|
||||
},
|
||||
onTypingGround: async (req: any, res: any, next: any) => {
|
||||
onTypingGround: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onTypingGround req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onTypingGround`
|
||||
})
|
||||
message: `${IAM}::onTypingGround`,
|
||||
});
|
||||
},
|
||||
onNotTypingGround: async (req: any, res: any, next: any) => {
|
||||
onNotTypingGround: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onNotTypingGround req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onNotTypingGround`
|
||||
})
|
||||
message: `${IAM}::onNotTypingGround`,
|
||||
});
|
||||
},
|
||||
onCheckTypingGround: async (req: any, res: any, next: any) => {
|
||||
onCheckTypingGround: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onCheckTypingGround req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onCheckTypingGround`
|
||||
})
|
||||
message: `${IAM}::onCheckTypingGround`,
|
||||
});
|
||||
},
|
||||
onCheckTypingAir: async (req: any, res: any, next: any) => {
|
||||
onCheckTypingAir: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onCheckTypingAir req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onCheckTypingAir`
|
||||
})
|
||||
message: `${IAM}::onCheckTypingAir`,
|
||||
});
|
||||
},
|
||||
onOnlineAir: async (req: any, res: any, next: any) => {
|
||||
onOnlineAir: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onOnlineAir req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onOnlineAir`
|
||||
})
|
||||
message: `${IAM}::onOnlineAir`,
|
||||
});
|
||||
},
|
||||
onOnlineGround: async (req: any, res: any, next: any) => {
|
||||
onOnlineGround: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onOnlineGround req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onOnlineGround`
|
||||
})
|
||||
message: `${IAM}::onOnlineGround`,
|
||||
});
|
||||
},
|
||||
onCheckOnlineGround: async (req: any, res: any, next: any) => {
|
||||
onCheckOnlineGround: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onCheckOnlineGround req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onCheckOnlineGround`
|
||||
})
|
||||
message: `${IAM}::onCheckOnlineGround`,
|
||||
});
|
||||
},
|
||||
onCheckOnlineAir: async (req: any, res: any, next: any) => {
|
||||
onCheckOnlineAir: async (req: any, res: express.Response) => {
|
||||
console.log(`${IAM}::onCheckOnlineAir req.body`, req.body);
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onCheckOnlineAir`
|
||||
})
|
||||
}
|
||||
}
|
||||
message: `${IAM}::onCheckOnlineAir`,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -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`,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -1,9 +1,11 @@
|
||||
const MyID = 'TestController';
|
||||
import express from 'express';
|
||||
|
||||
const IAM = 'TestController';
|
||||
export default {
|
||||
onGet: async (req: any, res: any, next: any) => {
|
||||
onGet: async (req: any, res: express.Response) => {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: `${MyID}::onGet`
|
||||
})
|
||||
}
|
||||
}
|
||||
message: `${IAM}::onGet`,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -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`,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -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`,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
@ -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`,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
13
src/db/connectPG.ts
Normal file
13
src/db/connectPG.ts
Normal file
@ -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);
|
55
src/db/incidentV2PG.ts
Normal file
55
src/db/incidentV2PG.ts
Normal file
@ -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<null> => {
|
||||
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;
|
||||
};
|
17
src/db/loginmanagerPG.ts
Normal file
17
src/db/loginmanagerPG.ts
Normal file
@ -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<User | any> => {
|
||||
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;
|
||||
};
|
@ -1,2 +1,2 @@
|
||||
import * as server from "./server";
|
||||
new server.App
|
||||
import * as server from './server';
|
||||
new server.App();
|
||||
|
@ -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.',
|
||||
|
@ -1,15 +1,15 @@
|
||||
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 {
|
||||
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
|
||||
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(', ')}`);
|
||||
next(`Validation error: ${error.details.map((x) => x.message).join(', ')}`);
|
||||
} else {
|
||||
req.body = value;
|
||||
next();
|
||||
|
@ -1,33 +1,27 @@
|
||||
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,) {
|
||||
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);
|
||||
|
||||
console.log("token", token);
|
||||
console.log('token', token);
|
||||
|
||||
jwt.verify(
|
||||
token as string,
|
||||
process.env.TOKEN_SECRET as string,
|
||||
(err: any, user: any) => {
|
||||
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) {
|
||||
export function generateAccessToken(username: string) {
|
||||
// expires after half and hour (1800 seconds = 30 minutes)
|
||||
const payload = {
|
||||
username
|
||||
username,
|
||||
};
|
||||
const tokenSecret: string = process.env.TOKEN_SECRET!;
|
||||
return jwt.sign(payload, tokenSecret, { expiresIn: '3h' });
|
||||
|
@ -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"
|
||||
ERRA1: 'Incident or item does not exist',
|
||||
ERRA2: 'Invalid timestamp',
|
||||
ERRA3: 'Item already acknowledged',
|
||||
ERRTG1: 'No incident supplied',
|
||||
};
|
||||
|
||||
export const STATUS_CODES = statusCodes;
|
||||
|
@ -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<any> => {
|
||||
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
|
||||
userId: user._id,
|
||||
},
|
||||
process.env.TOKEN_SECRET!
|
||||
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 });
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
export interface Casualty {
|
||||
id: number;
|
||||
// id: number;
|
||||
incidentid: string;
|
||||
gender: string;
|
||||
dob: string;
|
||||
@ -14,9 +14,11 @@ export interface Casualty {
|
||||
arrivalairport: string;
|
||||
lastmeal: string;
|
||||
detailsadded: number;
|
||||
detailssent: number;
|
||||
detailsack: number;
|
||||
deleted: number;
|
||||
complain: string;
|
||||
// detailssent: number;
|
||||
// detailsack: number;
|
||||
complaint: string;
|
||||
history: string;
|
||||
deleted: number;
|
||||
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -6,5 +6,4 @@ export interface ChatStatus {
|
||||
lasttypingair: number;
|
||||
lasttypingground: number;
|
||||
deleted: number;
|
||||
|
||||
}
|
||||
|
@ -21,3 +21,5 @@ export interface IncidentItem {
|
||||
onlineair: number;
|
||||
onlineground: number;
|
||||
}
|
||||
|
||||
|
||||
|
21
src/models/StartIncident.ts
Normal file
21
src/models/StartIncident.ts
Normal file
@ -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;
|
||||
}
|
@ -2,6 +2,6 @@ export interface User {
|
||||
id: number;
|
||||
username: string;
|
||||
password: string;
|
||||
email:string;
|
||||
email: string;
|
||||
_id: string;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
},
|
||||
);
|
||||
}*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user