Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 3 additions & 51 deletions app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,12 @@ const { databaseManager } = require('./lib/database/DatabaseManager.js');
const { databaseService } = require('./lib/database/DatabaseService.js');

// Server
const { webUiServer } = require('./lib/server');
const { webUiServer } = require('./lib/server/WebUiServer.js');

// Extract important
const EP = config.public.endpoints;
Log.configure(config);

// IO
const readline = require('readline');
const Utils = require('./lib/utils');
const { Console } = require('node:console');

/**
* RunConditionTable application
*/
Expand All @@ -46,12 +41,10 @@ class RunConditionTableApplication {
this.webUiServer = webUiServer;
this.databaseService = databaseService;
this.databaseManager = databaseManager;
this.databaseService.healthcheckInsertData();
this.syncManager = alimonitorServices.syncManager;
this.defineEndpoints();

buildPublicConfig(config);
this.buildCli();
}

defineEndpoints() {
Expand All @@ -75,6 +68,7 @@ class RunConditionTableApplication {
try {
await this.databaseManager.migrate();
await this.httpServer.listen();
await this.databaseService.healthcheckInsertData();
} catch (error) {
this.logger.error(`Error while starting RCT app: ${error}`);
await this.stop();
Expand All @@ -88,13 +82,10 @@ class RunConditionTableApplication {
this.logger.info('Stopping RCT app...');
try {
await this.httpServer.close();
await this.syncManager.clearSyncAllTask();
} catch (error) {
this.logger.error(`Error while stopping RCT app: ${error}`);
}
await this.syncManager.clearSyncAllTask();
this.rl.close();

this.logger.info('RCT app stopped');
} else {
this.logger.info('Stopping already...');
}
Expand All @@ -115,45 +106,6 @@ class RunConditionTableApplication {
get httpServer() {
return this.webUiServer.httpServer;
}

buildCli() {
this.rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: true,
prompt: '==> ',
});
this.rl.on('line', (line) => this.devCli(line));
this.con = new Console({ stdout: process.stdout, stderr: process.stderr });
}

devCli(line) {
try {
const cmdAndArgs = line.trim().split(/ +/).map((s) => s.trim());
Utils.switchCase(cmdAndArgs[0], {
'': () => {},
users: () => {
this.con.log(this.databaseService.loggedUsers);
},
sync: () => this.syncManager.syncAll(),
app: (args) => this.applicationCli(args),
}, this.incorrectCommand())(cmdAndArgs.slice(1));
this.rl.prompt();
} catch (error) {
this.con.error(error.message);
}
}

applicationCli(args) {
Utils.switchCase(args[0], {
stop: () => this.stop(),
run: () => this.run(),
}, this.incorrectCommand())();
}

incorrectCommand() {
return () => this.con.log('incorrect command');
}
}

module.exports = new RunConditionTableApplication();
13 changes: 0 additions & 13 deletions app/lib/database/DatabaseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ class DatabaseService {
config.database.max = 20

this.pool = new Pool(config.database)
this.pool.on('remove', () => {
// this.logger.info(`removing client, clients in pool: ${this.pool._clients.length}`);
})
this.pool.on('acquire', () => {
// this.logger.info(`acquiring client, clients in pool: ${this.pool._clients.length}`);
})
this.pool.on('error', (e) => {
this.logger.error(`database pg pool fatal error: ${e.stack}`);
})
Expand Down Expand Up @@ -120,7 +114,6 @@ class DatabaseService {
return;
}


const params = {...req.query, ...req.params}

const connectErrorHandler = (connectErr) => {
Expand Down Expand Up @@ -186,10 +179,6 @@ class DatabaseService {
}
}

async getDate(req, res) {
await this.pgExecFetchData(req, res, 'SELECT NOW();');
}

responseWithStatus(res, status, message) {
res.status(status).json({ message: message });
}
Expand All @@ -203,8 +192,6 @@ class DatabaseService {
}
}
}


}

module.exports = {
Expand Down
4 changes: 3 additions & 1 deletion app/lib/server/WebUiServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ class WebUiServer {
}
}

exports.WebUiServer = WebUiServer;
module.exports = {
webUiServer: new WebUiServer(),
};
16 changes: 0 additions & 16 deletions app/lib/server/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ const assert = require('assert');

module.exports = () => {
describe('DatabaseSuite', () => {
describe('Check Initialization of DatabaseService', () => {
it('should connect to the database successfully', () => {
assert.doesNotThrow(async () => {
await databaseService.getDate();
describe('Check methods of DatabaseService', () => {
it('should succesfully performe healthcheckInsertData', async () => {
await assert.doesNotReject(async () => {
await databaseService.healthcheckInsertData();
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/database/utilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/

const PGQueryBuilderSuite = require('./PGQueryBuilder.test');
const DatabaseServiceSuite = require('./DataBaseService.test');
const DatabaseServiceSuite = require('./DatabaseService.test');

module.exports = () => {
describe('PGQueryBuilder', PGQueryBuilderSuite);
Expand Down
26 changes: 0 additions & 26 deletions test/lib/server/WebUiServer.test.js

This file was deleted.

2 changes: 0 additions & 2 deletions test/lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
* or submit itself to any jurisdiction.
*/

const WebUiServerSuite = require('./WebUiServer.test');
const RoutesSuite = require('./routes.test');

module.exports = () => {
describe('Routes', RoutesSuite);
describe('WebUiServer', WebUiServerSuite);
};