fix: added timestamp parameters for a date range on the gql queries for
machineLogs, serverLogs and transactions feat: added optional limit and offset variables for the logs queries, for filtering and pagination feat: adapted the LogsDownloaderPopper to download the logs by whats set on the filters fix: improved code readability fix: avoid errors when the range option is selected and no range is actually selected
This commit is contained in:
parent
37ea3a04c3
commit
f641e605a4
7 changed files with 109 additions and 68 deletions
|
|
@ -195,12 +195,12 @@ const typeDefs = gql`
|
|||
machines: [Machine]
|
||||
customers: [Customer]
|
||||
customer(customerId: ID!): Customer
|
||||
machineLogs(deviceId: ID!): [MachineLog]
|
||||
machineLogs(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): [MachineLog]
|
||||
funding: [CoinFunds]
|
||||
serverVersion: String!
|
||||
uptime: [ProcessStatus]
|
||||
serverLogs: [ServerLog]
|
||||
transactions: [Transaction]
|
||||
serverLogs(from: Date, until: Date, limit: Int, offset: Int): [ServerLog]
|
||||
transactions(from: Date, until: Date, limit: Int, offset: Int): [Transaction]
|
||||
accounts: JSONObject
|
||||
config: JSONObject
|
||||
}
|
||||
|
|
@ -250,11 +250,14 @@ const resolvers = {
|
|||
customers: () => customers.getCustomersList(),
|
||||
customer: (...[, { customerId }]) => customers.getCustomerById(customerId),
|
||||
funding: () => funding.getFunding(),
|
||||
machineLogs: (...[, { deviceId }]) => logs.simpleGetMachineLogs(deviceId),
|
||||
machineLogs: (...[, { deviceId, from, until, limit, offset }]) =>
|
||||
logs.simpleGetMachineLogs(deviceId, from, until, limit, offset),
|
||||
serverVersion: () => serverVersion,
|
||||
uptime: () => supervisor.getAllProcessInfo(),
|
||||
serverLogs: () => serverLogs.getServerLogs(),
|
||||
transactions: () => transactions.batch(),
|
||||
serverLogs: (...[, { from, until, limit, offset }]) =>
|
||||
serverLogs.getServerLogs(from, until, limit, offset),
|
||||
transactions: (...[, { from, until, limit, offset }]) =>
|
||||
transactions.batch(from, until, limit, offset),
|
||||
config: () => settingsLoader.getConfig(),
|
||||
accounts: () => settingsLoader.getAccounts()
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ const db = require('../db')
|
|||
|
||||
const NUM_RESULTS = 500
|
||||
|
||||
function getServerLogs (until = new Date().toISOString()) {
|
||||
function getServerLogs (from = new Date(0).toISOString(), until = new Date().toISOString(), limit = null, offset = 0) {
|
||||
const sql = `select id, log_level, timestamp, message from server_logs
|
||||
where timestamp >= $1 and timestamp <= $2
|
||||
order by timestamp desc
|
||||
limit $1`
|
||||
limit $3
|
||||
offset $4`
|
||||
|
||||
return db.any(sql, [ NUM_RESULTS ])
|
||||
return db.any(sql, [ from, until, limit, offset ])
|
||||
.then(_.map(_.mapKeys(_.camelCase)))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ function addNames (txs) {
|
|||
|
||||
const camelize = _.mapKeys(_.camelCase)
|
||||
|
||||
function batch () {
|
||||
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']),
|
||||
_.take(NUM_RESULTS), _.map(camelize), addNames)
|
||||
function batch (from = new Date(0).toISOString(), until = new Date().toISOString(), limit = null, offset = 0) {
|
||||
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
|
||||
|
||||
const cashInSql = `select 'cashIn' as tx_class, txs.*,
|
||||
c.phone as customer_phone,
|
||||
|
|
@ -38,7 +37,8 @@ function batch () {
|
|||
((not txs.send_confirmed) and (txs.created <= now() - interval $1)) as expired
|
||||
from cash_in_txs as txs
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
order by created desc limit $2`
|
||||
where txs.created >= $2 and txs.created <= $3
|
||||
order by created desc limit $4 offset $5`
|
||||
|
||||
const cashOutSql = `select 'cashOut' as tx_class,
|
||||
txs.*,
|
||||
|
|
@ -50,14 +50,18 @@ function batch () {
|
|||
c.name as customer_name,
|
||||
c.front_camera_path as customer_front_camera_path,
|
||||
c.id_card_photo_path as customer_id_card_photo_path,
|
||||
(extract(epoch from (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $2 as expired
|
||||
(extract(epoch from (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $1 as expired
|
||||
from cash_out_txs txs
|
||||
inner join cash_out_actions actions on txs.id = actions.tx_id
|
||||
and actions.action = 'provisionAddress'
|
||||
left outer join customers c on txs.customer_id = c.id
|
||||
order by created desc limit $1`
|
||||
where txs.created >= $2 and txs.created <= $3
|
||||
order by created desc limit $4 offset $5`
|
||||
|
||||
return Promise.all([db.any(cashInSql, [cashInTx.PENDING_INTERVAL, NUM_RESULTS]), db.any(cashOutSql, [NUM_RESULTS, REDEEMABLE_AGE])])
|
||||
return Promise.all([
|
||||
db.any(cashInSql, [cashInTx.PENDING_INTERVAL, from, until, limit, offset]),
|
||||
db.any(cashOutSql, [REDEEMABLE_AGE, from, until, limit, offset])
|
||||
])
|
||||
.then(packager)
|
||||
}
|
||||
|
||||
|
|
@ -65,8 +69,7 @@ function getCustomerTransactions (customerId) {
|
|||
const packager = _.flow(it => {
|
||||
console.log()
|
||||
return it
|
||||
}, _.flatten, _.orderBy(_.property('created'), ['desc']),
|
||||
_.take(NUM_RESULTS), _.map(camelize), addNames)
|
||||
}, _.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
|
||||
|
||||
const cashInSql = `select 'cashIn' as tx_class, txs.*,
|
||||
c.phone as customer_phone,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue