mirror of https://github.com/Requarks/wiki.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
const _ = require('lodash')
|
|
const graphHelper = require('../../helpers/graph')
|
|
|
|
/* global WIKI */
|
|
|
|
module.exports = {
|
|
Query: {
|
|
async logging() { return {} }
|
|
},
|
|
Mutation: {
|
|
async logging() { return {} }
|
|
},
|
|
LoggingQuery: {
|
|
async loggers(obj, args, context, info) {
|
|
let loggers = await WIKI.models.loggers.getLoggers()
|
|
loggers = loggers.map(logger => {
|
|
const loggerInfo = _.find(WIKI.data.loggers, ['key', logger.key]) || {}
|
|
return {
|
|
...loggerInfo,
|
|
...logger,
|
|
config: _.sortBy(_.transform(logger.config, (res, value, key) => {
|
|
const configData = _.get(loggerInfo.props, key, {})
|
|
res.push({
|
|
key,
|
|
value: JSON.stringify({
|
|
...configData,
|
|
value
|
|
})
|
|
})
|
|
}, []), 'key')
|
|
}
|
|
})
|
|
if (args.filter) { loggers = graphHelper.filter(loggers, args.filter) }
|
|
if (args.orderBy) { loggers = graphHelper.orderBy(loggers, args.orderBy) }
|
|
return loggers
|
|
}
|
|
},
|
|
LoggingMutation: {
|
|
async updateLoggers(obj, args, context) {
|
|
try {
|
|
for (let logger of args.loggers) {
|
|
await WIKI.models.loggers.query().patch({
|
|
isEnabled: logger.isEnabled,
|
|
level: logger.level,
|
|
config: _.reduce(logger.config, (result, value, key) => {
|
|
_.set(result, `${value.key}`, value.value)
|
|
return result
|
|
}, {})
|
|
}).where('key', logger.key)
|
|
}
|
|
return {
|
|
responseResult: graphHelper.generateSuccess('Loggers updated successfully')
|
|
}
|
|
} catch (err) {
|
|
return graphHelper.generateError(err)
|
|
}
|
|
}
|
|
}
|
|
}
|