feat: return logs in csv format

This commit is contained in:
Taranto 2020-10-30 19:31:05 +00:00 committed by Josh Harvey
parent 542ba9f1b7
commit a108df0c4c
7 changed files with 65 additions and 13 deletions

View file

@ -1,4 +1,5 @@
const { gql } = require('apollo-server-express')
const converter = require('json-2-csv')
const { GraphQLDateTime } = require('graphql-iso-date')
const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json')
const got = require('got')
@ -206,11 +207,14 @@ const typeDefs = gql`
customers: [Customer]
customer(customerId: ID!): Customer
machineLogs(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): [MachineLog]
machineLogsCsv(deviceId: ID!, from: Date, until: Date, limit: Int, offset: Int): String
funding: [CoinFunds]
serverVersion: String!
uptime: [ProcessStatus]
serverLogs(from: Date, until: Date, limit: Int, offset: Int): [ServerLog]
serverLogsCsv(from: Date, until: Date, limit: Int, offset: Int): String
transactions(from: Date, until: Date, limit: Int, offset: Int): [Transaction]
transactionsCsv(from: Date, until: Date, limit: Int, offset: Int): String
accounts: JSONObject
config: JSONObject
}
@ -256,12 +260,18 @@ const resolvers = {
funding: () => funding.getFunding(),
machineLogs: (...[, { deviceId, from, until, limit, offset }]) =>
logs.simpleGetMachineLogs(deviceId, from, until, limit, offset),
machineLogsCsv: (...[, { deviceId, from, until, limit, offset }]) =>
logs.simpleGetMachineLogs(deviceId, from, until, limit, offset).then(converter.json2csvAsync),
serverVersion: () => serverVersion,
uptime: () => supervisor.getAllProcessInfo(),
serverLogs: (...[, { from, until, limit, offset }]) =>
serverLogs.getServerLogs(from, until, limit, offset),
serverLogsCsv: (...[, { from, until, limit, offset }]) =>
serverLogs.getServerLogs(from, until, limit, offset).then(converter.json2csvAsync),
transactions: (...[, { from, until, limit, offset }]) =>
transactions.batch(from, until, limit, offset),
transactionsCsv: (...[, { from, until, limit, offset }]) =>
transactions.batch(from, until, limit, offset).then(converter.json2csvAsync),
config: () => settingsLoader.loadLatestConfigOrNone(),
accounts: () => settingsLoader.loadAccounts()
},