Data selector by base fields

This commit is contained in:
Zalmoxisus
2016-09-11 17:07:02 +03:00
parent 7986004ea2
commit 9040cae21b
2 changed files with 17 additions and 9 deletions

View File

@@ -7,7 +7,7 @@ var createStore = require('./store');
module.exports.run = function(worker) {
var httpServer = worker.httpServer;
var scServer = worker.scServer;
var store;
var store = createStore(worker.options);
httpServer.on('request', app);
@@ -23,8 +23,6 @@ module.exports.run = function(worker) {
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/', function(req, res) {
if (!req.body) return res.status(404).end();
if (!store) store = createStore(worker.options);
switch(req.body.op) {
case 'get':
store.get(req.body.id).then(function(r) {
@@ -38,8 +36,10 @@ module.exports.run = function(worker) {
break;
default:
store.add(req.body).then(function(r) {
scServer.exchange.publish('log', req.body);
res.send({ id: r.id, error: r.error });
scServer.exchange.publish('report', {
type: 'add', data: store.selectors.byBaseFields(r)
});
});
}
});