Making some progress

This commit is contained in:
Martin Donnelly 2021-03-18 10:13:52 +00:00
parent 73221af968
commit e250908de3
40 changed files with 774 additions and 97 deletions

0
.eslintignore Normal file
View File

63
.eslintrc Executable file → Normal file
View File

@ -1,55 +1,12 @@
{
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": false
}
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"rules": {
"arrow-spacing": "error",
"block-scoped-var": "error",
"block-spacing": "error",
"brace-style": ["error", "stroustrup", {}],
"camelcase": "error",
"comma-dangle": ["error", "never"],
"comma-spacing": ["error", { "before": false, "after": true }],
"comma-style": [1, "last"],
"consistent-this": [1, "_this"],
"curly": [1, "multi"],
"eol-last": 1,
"eqeqeq": 1,
"func-names": 1,
"indent": ["error", 2, { "SwitchCase": 1 }],
"lines-around-comment": ["error", { "beforeBlockComment": true, "allowArrayStart": true }],
"max-len": [1, 180, 2, { "ignoreTemplateLiterals": true, "ignoreStrings": true, "ignoreUrls": true, "ignoreTrailingComments": true, "ignoreComments": true }], // 2 spaces per tab, max 80 chars per line
"new-cap": 1,
"newline-before-return": "error",
"no-array-constructor": 1,
"no-inner-declarations": [1, "both"],
"no-mixed-spaces-and-tabs": 1,
"no-multi-spaces": 2,
"no-new-object": 1,
"no-shadow-restricted-names": 1,
"object-curly-spacing": ["error", "always"],
"padded-blocks": ["error", { "blocks": "never", "switches": "always" }],
"prefer-const": "error",
"prefer-template": "error",
"one-var": 0,
"quote-props": ["error", "always"],
"quotes": [1, "single"],
"radix": 1,
"semi": [1, "always"],
"space-before-blocks": [1, "always"],
"space-infix-ops": 1,
"vars-on-top": 1,
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }],
"spaced-comment": ["error", "always", { "markers": ["/"] }]
}
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
]
}

55
.eslintrc-orig Executable file
View File

@ -0,0 +1,55 @@
{
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"jsx": false
}
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"rules": {
"arrow-spacing": "error",
"block-scoped-var": "error",
"block-spacing": "error",
"brace-style": ["error", "stroustrup", {}],
"camelcase": "error",
"comma-dangle": ["error", "never"],
"comma-spacing": ["error", { "before": false, "after": true }],
"comma-style": [1, "last"],
"consistent-this": [1, "_this"],
"curly": [1, "multi"],
"eol-last": 1,
"eqeqeq": 1,
"func-names": 1,
"indent": ["error", 2, { "SwitchCase": 1 }],
"lines-around-comment": ["error", { "beforeBlockComment": true, "allowArrayStart": true }],
"max-len": [1, 180, 2, { "ignoreTemplateLiterals": true, "ignoreStrings": true, "ignoreUrls": true, "ignoreTrailingComments": true, "ignoreComments": true }], // 2 spaces per tab, max 80 chars per line
"new-cap": 1,
"newline-before-return": "error",
"no-array-constructor": 1,
"no-inner-declarations": [1, "both"],
"no-mixed-spaces-and-tabs": 1,
"no-multi-spaces": 2,
"no-new-object": 1,
"no-shadow-restricted-names": 1,
"object-curly-spacing": ["error", "always"],
"padded-blocks": ["error", { "blocks": "never", "switches": "always" }],
"prefer-const": "error",
"prefer-template": "error",
"one-var": 0,
"quote-props": ["error", "always"],
"quotes": [1, "single"],
"radix": 1,
"semi": [1, "always"],
"space-before-blocks": [1, "always"],
"space-infix-ops": 1,
"vars-on-top": 1,
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }],
"spaced-comment": ["error", "always", { "markers": ["/"] }]
}
}

2
.gitignore vendored
View File

@ -164,3 +164,5 @@ artefacts/*.json
!/artefacts/
menu.db
menu.db.backup
/server

View File

@ -3,19 +3,30 @@
"version": "1.0.0",
"description": "",
"main": "./server/index.js",
"watch": {
"run_server": {
"patterns": [
"src"
],
"extensions": "ts,html,scss",
"quiet": false
}
},
"scripts": {
"run:ts": "ts-node ./src/development.ts",
"clean": "rm -rf dist",
"prebuild": "rimraf ./server",
"test:js": "mocha test/**/*.js",
"test:ts": "mocha -r ts-node/register test/**/*.ts",
"lint": "eslint . --ext .ts",
"lint": "eslint ./src --ext .ts",
"coverage": "nyc npm run test:js",
"build:js": "rollup -c rollup.config.js",
"compile:es": "tsc --declaration true --declarationMap true --module esnext --outDir './server/es'",
"compile:commonjs": "tsc --declaration true --declarationMap true --module commonjs --outDir './server/commonjs'",
"compile:ts": "tsc --outDir './server'",
"compile": "npm run prebuild && npm run compile:es && npm run compile:commonjs"
"compile": "npm run prebuild && npm run compile:es && npm run compile:commonjs",
"run_server": "npm run run:ts",
"watch_server": "npm-watch run_server"
},
"keywords": [],
"author": "",
@ -44,10 +55,13 @@
"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/jsonwebtoken": "^8.5.0",
"@types/morgan": "^1.9.2",
"eslint": "^7.21.0",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"eslint": "7.22.0",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"rollup": "^2.33.1",

View File

@ -1 +1,2 @@
export declare const db: any;
import sqlite3 from 'sqlite3';
export declare const db: sqlite3.Database;

View File

@ -1,7 +1,10 @@
"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 = require('sqlite3').verbose();
const sqlite3_1 = __importDefault(require("sqlite3"));
console.log(`${__dirname}/../../db/users.db`);
exports.db = new sqlite3.Database(`${__dirname}/../../db/users.db`);
exports.db = new sqlite3_1.default.Database(`${__dirname}/../../db/users.db`);
//# sourceMappingURL=connect.js.map

View File

@ -1 +1 @@
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/db/connect.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;AAC7C,OAAO,CAAC,GAAG,CAAC,GAAG,SAAS,oBAAoB,CAAC,CAAC;AACjC,QAAA,EAAE,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,SAAS,oBAAoB,CAAC,CAAC"}
{"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"}

View File

@ -1 +1,2 @@
export declare const getOne: (username: string, password: string) => Promise<unknown>;
import { User } from '../models/User';
export declare const getOne: (username: string, password: string) => User | any;

View File

@ -1 +1 @@
{"version":3,"file":"loginmanager.js","sourceRoot":"","sources":["../../src/db/loginmanager.ts"],"names":[],"mappings":";;;AAAA,uCAA6B;AAEtB,MAAM,MAAM,GAAG,CAAC,QAAe,EAAE,QAAe,EAAE,EAAE;IACvD,MAAM,GAAG,GAAG,6DAA6D,CAAC;IAE1E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,YAAE,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAQ,EAAE,GAAY,EAAE,EAAE;YACzD,IAAI,GAAG;gBACH,MAAM,CAAC,GAAG,CAAC,CAAC;YAEhB,IAAI,CAAC,GAAG;gBAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAXW,QAAA,MAAM,UAWjB"}
{"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"}

View File

@ -1,3 +1,3 @@
import express from 'express';
export declare const ProcessLogin: (req: express.Request, res: express.Response) => express.Response<any, Record<string, any>> | Promise<express.Response<any, Record<string, any>> | undefined>;
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;

View File

@ -1 +1 @@
{"version":3,"file":"LoginHandler.js","sourceRoot":"","sources":["../../src/handlers/LoginHandler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,iEAAmD;AAEnD,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,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Q,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"}

4
server/server.d.ts vendored
View File

@ -1,5 +1,5 @@
import express from 'express';
import { Application } from 'express';
export declare class App {
protected app: express.Application;
protected app: Application;
constructor(NODE_ENV?: string, PORT?: number);
}

View File

@ -28,28 +28,35 @@ 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 authenticator_1 = require("./lib/authenticator");
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(cors_1.default());
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);
this.app.post('/test', authenticator_1.authenticateToken, (req, res) => {
res.sendStatus(200);
});
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);
});

View File

@ -1 +1 @@
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,sDAA8B;AAC9B,oDAA4B;AAC5B,gDAAwB;AACxB,oDAA4B;AAI5B,uDAAwD;AACxD,2CAA6B;AAE7B,0CAAqC;AAErC,MAAM,CAAC,MAAM,EAAE,CAAC;AAEhB,MAAa,GAAG;IAGd,YAAY,WAAmB,aAAa,EAAE,OAAe,IAAI;QAC/D,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC;QAC5C,MAAM,QAAQ,GAAG,QAAQ,CAAC;QAE1B,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;QAE7B,IAAI,CAAC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,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"}

View File

@ -0,0 +1,12 @@
import express from "express";
export default {
onLogin: async (req: any, res: express.Response): Promise<express.Response> => {
return res.status(200).json({
success: true,
token: req.authToken,
userId: req.userId,
})
}
}

View File

@ -0,0 +1,9 @@
const MyID = 'ECGController';
export default {
onGetECG: async (req: any, res: any, next: any) => {
return res.status(200).json({
success: true,
message: `${MyID}::onGetECG`
})
}
}

View File

@ -0,0 +1,15 @@
const MyID = '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`
})
}
}

View File

@ -0,0 +1,153 @@
const MyID = '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`
})
}
}

View File

@ -0,0 +1,34 @@
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`
})
}
}

View File

@ -0,0 +1,9 @@
const MyID = 'TestController';
export default {
onGet: async (req: any, res: any, next: any) => {
return res.status(200).json({
success: true,
message: `${MyID}::onGet`
})
}
}

View File

@ -0,0 +1,34 @@
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`
})
}
}

View File

@ -0,0 +1,34 @@
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`
})
}
}

View File

@ -0,0 +1,34 @@
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`
})
}
}

View File

@ -1,3 +1,4 @@
const sqlite3 = require('sqlite3').verbose();
// const sqlite3 = require('sqlite3').verbose();
import sqlite3 from 'sqlite3';
console.log(`${__dirname}/../../db/users.db`);
export const db = new sqlite3.Database(`${__dirname}/../../db/users.db`);

View File

@ -1,14 +1,14 @@
import {db} from './connect';
import { db } from './connect';
import { User } from '../models/User';
export const getOne = (username:string, password:string) => {
const sql = 'SELECT * FROM accounts WHERE username = ? and password = ?';
export const getOne = (username: string, password: string): User | any => {
const sql = 'SELECT * FROM accounts WHERE username = ? and password = ?';
return new Promise((resolve, reject) => {
db.get(sql, [username, password], (err: any, row: unknown) => {
if (err)
reject(err);
return new Promise((resolve, reject) => {
db.get(sql, [username, password], (err: any, row: User) => {
if (err) reject(err);
if (!err) resolve(row);
});
if (!err) resolve(row);
});
});
};

View File

@ -1,6 +1,7 @@
import express from 'express';
import * as loginManager from '../db/loginmanager';
import {User} from '../models/User';
import { generateAccessToken } from '../lib/authenticator';
@ -17,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) => {
.then((data:User) => {
if (!data) {
// response.redirect('/');
console.warn('No data!');
@ -31,7 +32,7 @@ export const ProcessLogin = (req: express.Request, res: express.Response) => {
response.redirect('/menu');*/
}
})
.catch((err) => {
.catch((err:any) => {
console.error(err);
return res.status(500).send({
message: err.message || 'Some error occurred while querying the database.',

10
src/lib/constants.ts Normal file
View File

@ -0,0 +1,10 @@
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"
};

26
src/middleware/Checks.ts Normal file
View File

@ -0,0 +1,26 @@
import { ERROR_MESSAGES } from '../lib/constants';
const IAM = 'Checks';
export default {
incidentExists: async (req: any, res: any, next: any) => {
console.log(`${IAM}::incidentExists`);
next();
},
alreadyAcknowledged: async (req: any, res: any, next: any) => {
console.log(`${IAM}::alreadyAcknowledged`);
next();
},
validTimestamp: async (req: any, res: any, next: any) => {
console.log(`${IAM}::validTimestamp`);
next();
},
incidentNotNull: async (req: any, res: any, next: any) => {
console.log(`${IAM}::incidentNotNull`);
next();
},
};

60
src/middleware/jwt.ts Normal file
View File

@ -0,0 +1,60 @@
import jwt from 'jsonwebtoken';
import { ERROR_MESSAGES } from '../lib/constants';
import { getOne } from '../db/loginmanager';
import {User} from '../models/User';
import express from "express";
const IAM = 'jwt';
export const encode = async (req: any, res: express.Response, next: express.NextFunction) => {
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);
if (user) {
console.log(`>> ${IAM}::encode - user`, user);
const authToken = jwt.sign(
{
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 });
}
};
export const decode = (req: any, res: any, next: any) => {
if (!req.headers['authorization']) {
return res.status(401).json({ success: false, message: ERROR_MESSAGES.NO_TOKEN });
}
try {
const accessToken = req.headers.authorization.split(' ')[1];
const decoded: any = jwt.verify(accessToken, process.env.TOKEN_SECRET!);
req.userId = decoded.userId;
return next();
} catch (error) {
console.log(error);
return res.status(401).json({ success: false, message: error.message });
}
};

22
src/models/Casualty.ts Normal file
View File

@ -0,0 +1,22 @@
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;
}

10
src/models/Chat.ts Normal file
View File

@ -0,0 +1,10 @@
export interface Chat {
id: number;
incidentid: string;
aibermsg:string;
controlmsg: string;
msgtime:number;
msgrecd:number;
msgread:number;
deleted:number;
}

10
src/models/ChatStatus.ts Normal file
View File

@ -0,0 +1,10 @@
export interface ChatStatus {
id: number;
incidentid: string;
typingair: number;
typingground: number;
lasttypingair: number;
lasttypingground: number;
deleted: number;
}

View File

@ -0,0 +1,9 @@
export interface IncidentItem {
id: number;
incidentdate: Date;
description: string;
username: string;
reportdate: Date;
reportlog: string;
ecgtrace: string;
}

View File

@ -0,0 +1,23 @@
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;
}

22
src/models/PanelLatest.ts Normal file
View File

@ -0,0 +1,22 @@
export interface PanelLatest {
panelinfoid: number;
incidentid: string;
avpu: string;
avputime: number;
ecg: number;
ecgtime: number;
hr: number;
hrtime: number;
br: number;
brtime: number;
sats: number;
satstime: number;
bpsys: number;
bpdia: number;
bptime: number;
temp: number;
temptime: number;
messages: number;
messagestime: number;
deleted: number;
}

32
src/models/PanelLayout.ts Normal file
View File

@ -0,0 +1,32 @@
export interface PanelLatest {
panelinfoid: number;
incidentid: string;
avpu: string;
avputime: number;
airway: string;
airwaytime: number;
breathing: string;
breathingtime: number;
circulation: string;
circulationtime: number;
unconsciousness: string;
unconsciousnesstime: number;
ecg: number;
ecgtime: number;
hr: number;
hrtime: number;
br: number;
brtime: number;
sats: number;
satstime: number;
bpsys: number;
bpdia: number;
bptime: number;
temp: number;
temptime: number;
messages: number;
messagestime: number;
deleted: number;
}

7
src/models/User.ts Normal file
View File

@ -0,0 +1,7 @@
export interface User {
id: number;
username: string;
password: string;
email:string;
_id: string;
}

62
src/routes/index.ts Normal file
View File

@ -0,0 +1,62 @@
import express, { Router } from 'express';
import { decode, encode } from '../middleware/jwt';
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 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({
success: true,
message: 'You are good to go',
});
});
// Routes
router.get('/Ecg/GetECG', decode, ecgController.onGetECG);
//
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);
export default router;

View File

@ -1,40 +1,39 @@
import * as dotenv from 'dotenv';
import express from 'express';
import express, { Application } from 'express';
import helmet from 'helmet';
import cors from 'cors';
import cors, { CorsOptions } from 'cors';
import logger from 'morgan';
import * as jwt from 'jsonwebtoken';
import { authenticateToken } from './lib/authenticator';
import * as path from 'path';
import {Login} from "./routes/login";
import { Login } from './routes/login';
import indexRouter from './routes/index';
import { ERROR_MESSAGES } from './lib/constants';
dotenv.config();
export class App {
protected app: express.Application;
protected app: Application;
constructor(NODE_ENV: string = 'development', PORT: number = 8080) {
constructor(NODE_ENV = 'development', PORT = 8080) {
const serverPort = process.env.PORT || PORT;
const sitePath = 'public';
const corsOptions: CorsOptions = { credentials: false };
this.app = express();
this.app.use(logger('dev'));
this.app.use(express.json());
this.app.use(express.urlencoded({ extended: false }));
this.app.use(cors());
this.app.use(cors(corsOptions));
this.app.use(helmet());
this.app.set('trust proxy', 1);
this.app.post('/test', authenticateToken, (req: express.Request, res: express.Response) => {
res.sendStatus(200);
});
// ///
const login = Login(this.app);
@ -43,6 +42,15 @@ export class App {
res.sendFile('index.html', { root: path.join(process.cwd(), sitePath) });
});
this.app.use(`${process.env.URL_PREFIX}`, indexRouter);
this.app.use('*', (req, res) => {
return res.status(404).json({
success: false,
message: ERROR_MESSAGES.ENDPOINT_NOT_FOUND,
});
});
this.app.listen(serverPort, function () {
console.log('The server is running in port localhost: ', serverPort);
});