Provide machine name on logs snapshots batch
This commit is contained in:
parent
62d606cc80
commit
4f9cc88a5e
4 changed files with 819 additions and 273 deletions
|
|
@ -3,6 +3,22 @@ const uuid = require('uuid')
|
|||
|
||||
const db = require('./db')
|
||||
|
||||
/**
|
||||
* Get single support_log by id
|
||||
*
|
||||
* @name get
|
||||
* @function
|
||||
*
|
||||
* @param {string} phone Customer's phone number
|
||||
*
|
||||
* @returns {object} Customer
|
||||
*/
|
||||
function get (id) {
|
||||
if (!id || _.isEmpty(id)) return Promise.resolve()
|
||||
const sql = 'select * from support_logs where id=$1'
|
||||
return db.oneOrNone(sql, [id])
|
||||
.then(_.mapKeys(_.camelCase))
|
||||
}
|
||||
/**
|
||||
* Insert a single support_logs row in db
|
||||
*
|
||||
|
|
@ -22,23 +38,21 @@ function insert (deviceId) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the latest 48-hour logs
|
||||
* Get the latest 48-hour logs snapshots
|
||||
*
|
||||
* @name batch
|
||||
* @function
|
||||
* @async
|
||||
*
|
||||
* @param {string} deviceId Machine's id
|
||||
* @param {date} timestamp Fetch the last 48-hour logs before this timestamp
|
||||
*
|
||||
* @returns {array} List of all support_logs rows
|
||||
*/
|
||||
function batch (timestamp) {
|
||||
const sql = `select * from support_logs
|
||||
where timestamp > $1 - interval '2 days'
|
||||
order by timestamp desc`
|
||||
return db.oneOrNone(sql, [timestamp])
|
||||
function batch () {
|
||||
const sql = `select s.id, s.device_id, s.timestamp, devices.name from support_logs as s
|
||||
inner join devices on s.device_id = devices.device_id
|
||||
where timestamp > (now() - interval '2 days')
|
||||
order by s.timestamp desc`
|
||||
return db.any(sql)
|
||||
.then(_.map(_.mapKeys(_.camelCase)))
|
||||
}
|
||||
|
||||
module.exports = { insert, batch }
|
||||
module.exports = { get, insert, batch }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue