Get a report
This commit is contained in:
parent
ff4245d965
commit
0a8576ab86
13
lib/store.js
13
lib/store.js
@ -11,6 +11,18 @@ function error(msg) {
|
||||
});
|
||||
}
|
||||
|
||||
function get(id) {
|
||||
if (!id) return error('No id specified.');
|
||||
|
||||
if (!adapter) {
|
||||
return new Promise(function(resolve) {
|
||||
var report = Report.get(id);
|
||||
return resolve(report);
|
||||
});
|
||||
}
|
||||
return Report.find(id);
|
||||
}
|
||||
|
||||
function add(data) {
|
||||
if (!data.type || !data.payload) {
|
||||
return error('Required parameters aren\'t specified.');
|
||||
@ -36,6 +48,7 @@ function createStore(options) {
|
||||
Report = store.defineResource('report');
|
||||
|
||||
return {
|
||||
get: get,
|
||||
add: add
|
||||
};
|
||||
}
|
||||
|
@ -25,6 +25,11 @@ module.exports.run = function(worker) {
|
||||
if (!store) store = createStore(worker.options);
|
||||
|
||||
switch(req.body.op) {
|
||||
case 'get':
|
||||
store.get(req.body.id).then(function(r) {
|
||||
res.send(r || {});
|
||||
});
|
||||
break;
|
||||
default:
|
||||
store.add(req.body).then(function(r) {
|
||||
scServer.exchange.publish('log', req.body);
|
||||
|
Loading…
x
Reference in New Issue
Block a user