split per app
This commit is contained in:
10
lib/api/get-app.js
Normal file
10
lib/api/get-app.js
Normal 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);
|
||||
};
|
@ -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)));
|
||||
}
|
||||
};
|
||||
|
@ -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
lib/db/app.js
Normal file
9
lib/db/app.js
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (get_db) => ({
|
||||
get_all () {
|
||||
const knex = get_db ();
|
||||
return knex ('app')
|
||||
.select ();
|
||||
}
|
||||
});
|
@ -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
lib/db/log.js
Normal file
15
lib/db/log.js
Normal 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 });
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user