split per app

This commit is contained in:
2020-08-16 11:48:06 +02:00
parent d3a19c953a
commit c5be16963d
12 changed files with 126 additions and 14 deletions
+10
View File
@@ -0,0 +1,10 @@
'use strict';
const db = require ('../db');
const { http } = require ('@sapphirecode/consts');
module.exports = async (req, res) => {
const apps = await db.app.get_all ();
res.status (http.status_ok)
.json (apps);
};
+11 -2
View File
@@ -4,6 +4,15 @@ const db = require ('../db');
const { http } = require ('@sapphirecode/consts');
module.exports = async (req, res) => {
res.status (http.status_ok)
.json (await db.get_all ());
if (
typeof req.headers.app_id === 'undefined'
|| isNaN (parseInt (req.headers.app_id))
) {
res.status (http.status_bad_request)
.end ();
}
else {
res.status (http.status_ok)
.json (await db.log.get_all (parseInt (req.headers.app_id)));
}
};
+1
View File
@@ -4,5 +4,6 @@ const router = require ('express')
.Router ();
router.get ('/log', require ('./get-log'));
router.get ('/app', require ('./get-app'));
module.exports = router;
+9
View File
@@ -0,0 +1,9 @@
'use strict';
module.exports = (get_db) => ({
get_all () {
const knex = get_db ();
return knex ('app')
.select ();
}
});
+6 -4
View File
@@ -18,9 +18,11 @@ async function init (use_fake_seed) {
await db.seed.run ({ specific: 'fake.js' });
}
function get_all () {
return db ('log')
.select ();
function get_db () {
return db;
}
module.exports = { init, get_all };
const log = require ('./log') (get_db);
const app = require ('./app') (get_db);
module.exports = { init, log, app };
+15
View File
@@ -0,0 +1,15 @@
'use strict';
module.exports = (get_db) => ({
get_all (app_id) {
const knex = get_db ();
return knex.select (
'id',
'message',
'data',
'timestamp'
)
.from ('log')
.where ({ app_id });
}
});