2023-05-07 21:22:07 +01:00
|
|
|
/* global process */
|
2023-02-09 20:34:53 +00:00
|
|
|
const log = require('../utils/log.utils'); // Log Helper
|
2023-05-06 21:54:49 +01:00
|
|
|
const db = require('../services/dbAccess.services');
|
|
|
|
const os = require('os');
|
|
|
|
const vers = require('../configs/version.configs');
|
2023-02-09 20:34:53 +00:00
|
|
|
|
2023-05-07 21:22:07 +01:00
|
|
|
async function buildJson() {
|
|
|
|
let json = {};
|
|
|
|
json.count = {};
|
|
|
|
// Async call all db queries
|
|
|
|
const counters = db.query('meta', {target: 'counters'});
|
|
|
|
const versions = db.query('meta', {target: 'versions'});
|
|
|
|
const userCount = db.colCount('users');
|
|
|
|
const regCount = db.colCount('registrations');
|
|
|
|
const pisCount = db.colCount('pis');
|
|
|
|
const corpusCount = db.colCount('corpus');
|
|
|
|
const stationsCount = db.colCount('stations');
|
|
|
|
|
|
|
|
// Insert data
|
|
|
|
json.mode = process.env.NODE_ENV;
|
|
|
|
json.verBkend = vers.app;
|
|
|
|
json.verApi = vers.api;
|
2023-05-07 21:30:03 +01:00
|
|
|
json.host = os.hostname();
|
2023-05-07 21:22:07 +01:00
|
|
|
// Await and insert async calls
|
|
|
|
json.dat = await counters;
|
|
|
|
json.ver = await versions;
|
|
|
|
json.count.users = await userCount;
|
|
|
|
json.count.reg = await regCount;
|
|
|
|
json.count.pis = await pisCount;
|
|
|
|
json.count.corpus = await corpusCount;
|
|
|
|
json.count.stations = await stationsCount;
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
2023-02-09 20:34:53 +00:00
|
|
|
async function hits(){
|
2023-05-06 21:54:49 +01:00
|
|
|
log.out('statsServices.hits: Statistics Requested', 'info');
|
2023-05-07 21:22:07 +01:00
|
|
|
const out = await buildJson();
|
2023-05-06 21:54:49 +01:00
|
|
|
log.out(`statsServices.hits: Sending Data: ${JSON.stringify(out)}`, 'info');
|
|
|
|
return out;
|
2023-02-09 20:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2023-05-06 21:54:49 +01:00
|
|
|
hits
|
|
|
|
};
|