Data selector by base fields
This commit is contained in:
@@ -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)
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user