Refacor and increase number of stats
Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
parent
7da713526f
commit
99c7842c2a
@ -73,11 +73,21 @@ async function delRegReq(uuid) {
|
||||
col.deleteOne({uuid: uuid});
|
||||
}
|
||||
|
||||
async function colCount(collection) {
|
||||
log.out(`dbAccess.colCount: Counting entries in collection: ${collection}`);
|
||||
await client.connect();
|
||||
let col = db.collection(collection);
|
||||
let count = col.countDocuments();
|
||||
log.out(`dbAccess.colCount: Collection: ${collection} contains ${count} documents`);
|
||||
return await count;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
query,
|
||||
increment, // Probqbly doesn't need exporting? - It does, ldbServices needs to increment when the API is hit!
|
||||
addUser,
|
||||
userAtime,
|
||||
addRegReq,
|
||||
delRegReq
|
||||
delRegReq,
|
||||
colCount
|
||||
};
|
@ -3,19 +3,37 @@ const db = require('../services/dbAccess.services');
|
||||
const os = require('os');
|
||||
const vers = require('../configs/version.configs');
|
||||
|
||||
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;
|
||||
json.hostname = os.hostname();
|
||||
// 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;
|
||||
}
|
||||
|
||||
async function hits(){
|
||||
log.out('statsServices.hits: Statistics Requested', 'info');
|
||||
var dat = db.query('meta', {target: 'counters'});
|
||||
var ver = db.query('meta', {target: 'versions'});
|
||||
log.out('statsServices.hits: fetched server meta', 'info');
|
||||
let out = {};
|
||||
out.host = os.hostname();
|
||||
// eslint-disable-next-line no-undef
|
||||
out.mode = process.env.NODE_ENV;
|
||||
out.verBkend = vers.app;
|
||||
out.verApi = vers.api;
|
||||
out.dat = await dat;
|
||||
out.ver = await ver;
|
||||
const out = await buildJson();
|
||||
log.out(`statsServices.hits: Sending Data: ${JSON.stringify(out)}`, 'info');
|
||||
return out;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user