Extend store API
This commit is contained in:
parent
6794f63629
commit
1ba4d1e40b
@ -17,7 +17,7 @@ module.exports = function connector(options) {
|
|||||||
return knex.seed.run();
|
return knex.seed.run();
|
||||||
})
|
})
|
||||||
.then(function() {
|
.then(function() {
|
||||||
console.log('Migrations are finished.');
|
console.log(' \x1b[0;32m[Done]\x1b[0m Migrations are finished\n');
|
||||||
})
|
})
|
||||||
.catch(function(error) {
|
.catch(function(error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -13,6 +13,7 @@ exports.up = function(knex, Promise) {
|
|||||||
table.string('version');
|
table.string('version');
|
||||||
table.string('user');
|
table.string('user');
|
||||||
table.string('userId');
|
table.string('userId');
|
||||||
|
table.string('instanceId');
|
||||||
table.string('meta');
|
table.string('meta');
|
||||||
table.string('exception');
|
table.string('exception');
|
||||||
table.timestamp('added').defaultTo(knex.fn.now());
|
table.timestamp('added').defaultTo(knex.fn.now());
|
||||||
|
15
lib/store.js
15
lib/store.js
@ -20,10 +20,16 @@ function list(query, fields) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function listAll(query) {
|
||||||
|
var r = knex.select().from(reports);
|
||||||
|
if (query) return r.where(query);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
function get(id) {
|
function get(id) {
|
||||||
if (!id) return error('No id specified.');
|
if (!id) return error('No id specified.');
|
||||||
|
|
||||||
return knex(reports).where('id', id);
|
return knex(reports).where('id', id).first();
|
||||||
}
|
}
|
||||||
|
|
||||||
function add(data) {
|
function add(data) {
|
||||||
@ -45,13 +51,15 @@ function add(data) {
|
|||||||
preloadedState: data.preloadedState,
|
preloadedState: data.preloadedState,
|
||||||
screenshot: data.screenshot,
|
screenshot: data.screenshot,
|
||||||
version: data.version,
|
version: data.version,
|
||||||
appId: data.appId,
|
|
||||||
userAgent: data.userAgent,
|
userAgent: data.userAgent,
|
||||||
user: data.user,
|
user: data.user,
|
||||||
userId: typeof data.user === 'object' ? data.user.id : data.user,
|
userId: typeof data.user === 'object' ? data.user.id : data.user,
|
||||||
|
instanceId: data.instanceId,
|
||||||
meta: data.meta,
|
meta: data.meta,
|
||||||
exception: data.exception
|
exception: data.exception,
|
||||||
|
added: Date.now()
|
||||||
};
|
};
|
||||||
|
if (data.appId) report.appId = data.appId; // TODO check if the id exists and we have access to link it
|
||||||
/*
|
/*
|
||||||
var payload = {
|
var payload = {
|
||||||
id: uuid.v4(),
|
id: uuid.v4(),
|
||||||
@ -73,6 +81,7 @@ function createStore(options) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
list: list,
|
list: list,
|
||||||
|
listAll: listAll,
|
||||||
get: get,
|
get: get,
|
||||||
add: add
|
add: add
|
||||||
};
|
};
|
||||||
|
@ -17,15 +17,15 @@ module.exports.run = function(worker) {
|
|||||||
app.set('view engine', 'ejs');
|
app.set('view engine', 'ejs');
|
||||||
app.set('views', path.resolve(__dirname, '..', 'views'));
|
app.set('views', path.resolve(__dirname, '..', 'views'));
|
||||||
|
|
||||||
app.get('*', function(req, res) {
|
|
||||||
res.render('index', { port: worker.options.port });
|
|
||||||
});
|
|
||||||
|
|
||||||
if (logHTTPRequests) {
|
if (logHTTPRequests) {
|
||||||
if (typeof logHTTPRequests === 'object') app.use(morgan('combined', logHTTPRequests));
|
if (typeof logHTTPRequests === 'object') app.use(morgan('combined', logHTTPRequests));
|
||||||
else app.use(morgan('combined'));
|
else app.use(morgan('combined'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.get('*', function(req, res) {
|
||||||
|
res.render('index', { port: worker.options.port });
|
||||||
|
});
|
||||||
|
|
||||||
app.use(cors({ methods: 'POST' }));
|
app.use(cors({ methods: 'POST' }));
|
||||||
app.use(bodyParser.json({ limit: limit }));
|
app.use(bodyParser.json({ limit: limit }));
|
||||||
app.use(bodyParser.urlencoded({ limit: limit, extended: false }));
|
app.use(bodyParser.urlencoded({ limit: limit, extended: false }));
|
||||||
@ -34,7 +34,7 @@ module.exports.run = function(worker) {
|
|||||||
switch(req.body.op) {
|
switch(req.body.op) {
|
||||||
case 'get':
|
case 'get':
|
||||||
store.get(req.body.id).then(function(r) {
|
store.get(req.body.id).then(function(r) {
|
||||||
res.send(r[0] || {});
|
res.send(r || {});
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
res.sendStatus(500)
|
res.sendStatus(500)
|
||||||
@ -98,7 +98,7 @@ module.exports.run = function(worker) {
|
|||||||
});
|
});
|
||||||
socket.on('getReport', function (id, respond) {
|
socket.on('getReport', function (id, respond) {
|
||||||
store.get(id).then(function(data) {
|
store.get(id).then(function(data) {
|
||||||
respond(null, data[0]);
|
respond(null, data);
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user