Use knex instead of js-data

This commit is contained in:
Zalmoxisus
2016-11-08 22:48:32 +02:00
parent 7c106cd843
commit fd9f7f2c0d
9 changed files with 130 additions and 64 deletions

View File

@ -26,20 +26,29 @@ module.exports.run = function(worker) {
switch(req.body.op) {
case 'get':
store.get(req.body.id).then(function(r) {
res.send(r || {});
res.send(r[0] || {});
}).catch(function(error) {
console.error(error);
res.sendStatus(500)
});
break;
case 'list':
store.list(req.body.query, req.body.fields).then(function(r) {
res.send(r);
}).catch(function(error) {
console.error(error);
res.sendStatus(500)
});
break;
default:
store.add(req.body).then(function(r) {
res.send({ id: r.id, error: r.error });
scServer.exchange.publish('report', {
type: 'add', data: store.selectors.byBaseFields(r)
type: 'add', data: r
});
}).catch(function(error) {
console.error(error);
res.status(500).send({})
});
}
});
@ -60,6 +69,8 @@ module.exports.run = function(worker) {
if (req.channel === 'report') {
store.list().then(function(data) {
req.socket.emit(req.channel, { type: 'list', data: data });
}).catch(function(error) {
console.error(error);
});
}
});
@ -79,7 +90,9 @@ module.exports.run = function(worker) {
});
socket.on('getReport', function (id, respond) {
store.get(id).then(function(data) {
respond(null, data);
respond(null, data[0]);
}).catch(function(error) {
console.error(error);
});
});
socket.on('disconnect', function() {