From a324c6fc63c23adeb5344b419c12a27fba72b55a Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 26 Jun 2023 22:26:47 +0100 Subject: [PATCH] Add /misc/server/versions Signed-off-by: Fred Boniface --- src/controllers/issue.controllers.js | 2 ++ src/controllers/stats.controllers.js | 13 ++++++++++++- src/routes/misc.routes.js | 3 ++- src/services/issue.services.js | 10 +++++++++- src/services/stats.services.js | 17 ++++++++++++++++- 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/controllers/issue.controllers.js b/src/controllers/issue.controllers.js index dc1fc83..5986db2 100644 --- a/src/controllers/issue.controllers.js +++ b/src/controllers/issue.controllers.js @@ -1,7 +1,9 @@ const issue = require('../services/issue.services'); +const log = require('../utils/log.utils'); async function post(req, res, next){ try { + log.out(`issueControllers.post: Request Body: ${JSON.stringify(req.body)}`); res.json(await issue.processor(req.body)); } catch (err) { console.error('Controller Error', err.message); diff --git a/src/controllers/stats.controllers.js b/src/controllers/stats.controllers.js index 4675478..d39b7e5 100644 --- a/src/controllers/stats.controllers.js +++ b/src/controllers/stats.controllers.js @@ -10,6 +10,17 @@ async function get(req, res, next) { } } +async function versions(req, res, next) { + try { + res.json(await stat.versions()); + } catch (err) { + console.error('Controller Error', err); + err.status = 500; + next(err); + } +} + module.exports = { - get + get, + versions }; \ No newline at end of file diff --git a/src/routes/misc.routes.js b/src/routes/misc.routes.js index e943e93..0dce9af 100644 --- a/src/routes/misc.routes.js +++ b/src/routes/misc.routes.js @@ -3,12 +3,13 @@ const router = express.Router(); // Controller Imports const issueCtr = require('../controllers/issue.controllers'); +const statCtr = require('../controllers/stats.controllers'); // Routes router.get('/server/stats'); -router.get('/server/versions'); +router.get('/server/versions', statCtr.versions); router.post('/issue', issueCtr.post); diff --git a/src/services/issue.services.js b/src/services/issue.services.js index 194516c..e4843f5 100644 --- a/src/services/issue.services.js +++ b/src/services/issue.services.js @@ -2,11 +2,19 @@ const axios = require('axios'); const log = require('../utils/log.utils'); +const issueLabels = { + bug: 120, + enhancement: 122, + question: 125, + 'user-support': 152, + 'web-user': 153 +}; + async function processor(data) { log.out('issueService.processor: Issue received', 'info'); console.log(data); // TEMPORARY MEASURE let out = {}; - out.labels = data?.labels || []; + out.labels = [(issueLabels[data?.label] || 0), issueLabels['web-user']]; out.title = data?.subject.replace(/<[^>]+>|[\*\$]/g, ''); out.body = data?.msg.replace(/<[^>]+>|[\*\$]/g, ''); return await sendToGitea(out); diff --git a/src/services/stats.services.js b/src/services/stats.services.js index cc387f6..71c6646 100644 --- a/src/services/stats.services.js +++ b/src/services/stats.services.js @@ -41,6 +41,21 @@ async function hits(){ return out; } +async function versions() { + log.out('statsServices.versions: Fetching versions', 'info'); + const versions = db.query('meta', {target: 'versions'}); + let data = { + backend: '', + 'db-manager': '', + 'mq-subscriber': '', + }; + await versions; + data.backend = vers.app; + data['db-manager'] = versions[0]['dbmanager']; + return data; +} + module.exports = { - hits + hits, + versions }; \ No newline at end of file