Use knex instead of js-data
This commit is contained in:
@ -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() {
|
||||
|
Reference in New Issue
Block a user