Get a report

This commit is contained in:
Zalmoxisus 2016-08-17 18:33:07 +03:00
parent ff4245d965
commit 0a8576ab86
2 changed files with 18 additions and 0 deletions

View File

@ -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
};
}

View File

@ -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);