refactor: move up dateFormat method
This commit is contained in:
parent
a0c77b4939
commit
b5e35b82c2
3 changed files with 20 additions and 23 deletions
17
lib/logs.js
17
lib/logs.js
|
|
@ -1,4 +1,5 @@
|
|||
const _ = require('lodash/fp')
|
||||
const moment = require('moment')
|
||||
|
||||
const db = require('./db')
|
||||
const pgp = require('pg-promise')()
|
||||
|
|
@ -109,4 +110,18 @@ function simpleGetMachineLogs (deviceId, from = new Date(0).toISOString(), until
|
|||
.then(_.map(_.mapKeys(_.camelCase)))
|
||||
}
|
||||
|
||||
module.exports = { getUnlimitedMachineLogs, getMachineLogs, simpleGetMachineLogs, update, getLastSeen, clearOldLogs }
|
||||
function logDateFormat (timezone, logs, fields) {
|
||||
const offset = timezone.split(':')[1]
|
||||
|
||||
return _.map(log => {
|
||||
const values = _.map(field => moment.utc(log[field]).utcOffset(parseInt(offset)).format('YYYY-MM-DDTHH:mm:ss.SSS'), fields)
|
||||
const fieldsToOverride = _.zipObject(fields, values)
|
||||
|
||||
return {
|
||||
...log,
|
||||
...fieldsToOverride
|
||||
}
|
||||
}, logs)
|
||||
}
|
||||
|
||||
module.exports = { getUnlimitedMachineLogs, getMachineLogs, simpleGetMachineLogs, update, getLastSeen, clearOldLogs, logDateFormat }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue