feat: add new server log page

This commit is contained in:
Luis Félix 2019-11-12 11:15:00 +00:00
parent fc1951c4b2
commit 703c5d7c91
38 changed files with 2844 additions and 29 deletions

View file

@ -0,0 +1,26 @@
const _ = require('lodash/fp')
const uuid = require('uuid')
const db = require('../db')
const NUM_RESULTS = 500
function getServerLogs (until = new Date().toISOString()) {
const sql = `select id, log_level, timestamp, message from server_logs
order by timestamp desc
limit $1`
return Promise.all([db.any(sql, [ NUM_RESULTS ])])
.then(([logs]) => ({
logs: _.map(_.mapKeys(_.camelCase), logs)
}))
}
function insert () {
const sql = `insert into server_support_logs
(id) values ($1) returning *`
return db.one(sql, [uuid.v4()])
.then(_.mapKeys(_.camelCase))
}
module.exports = { getServerLogs, insert }