mirror of https://github.com/requarks/wiki
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.
53 lines
1.6 KiB
53 lines
1.6 KiB
2 years ago
|
import _ from 'lodash-es'
|
||
|
import { generateError, generateSuccess } from '../../helpers/graph.mjs'
|
||
6 years ago
|
|
||
2 years ago
|
export default {
|
||
6 years ago
|
Query: {
|
||
|
async renderers(obj, args, context, info) {
|
||
2 years ago
|
let renderers = await WIKI.db.renderers.getRenderers()
|
||
6 years ago
|
renderers = renderers.map(rdr => {
|
||
|
const rendererInfo = _.find(WIKI.data.renderers, ['key', rdr.key]) || {}
|
||
|
return {
|
||
|
...rendererInfo,
|
||
|
...rdr,
|
||
|
config: _.sortBy(_.transform(rdr.config, (res, value, key) => {
|
||
5 years ago
|
const configData = _.get(rendererInfo.props, key, false)
|
||
|
if (configData) {
|
||
|
res.push({
|
||
|
key,
|
||
|
value: JSON.stringify({
|
||
|
...configData,
|
||
|
value
|
||
|
})
|
||
6 years ago
|
})
|
||
5 years ago
|
}
|
||
6 years ago
|
}, []), 'key')
|
||
|
}
|
||
|
})
|
||
5 years ago
|
// if (args.filter) { renderers = graphHelper.filter(renderers, args.filter) }
|
||
|
if (args.orderBy) { renderers = _.sortBy(renderers, [args.orderBy]) }
|
||
6 years ago
|
return renderers
|
||
|
}
|
||
|
},
|
||
3 years ago
|
Mutation: {
|
||
6 years ago
|
async updateRenderers(obj, args, context) {
|
||
|
try {
|
||
|
for (let rdr of args.renderers) {
|
||
2 years ago
|
await WIKI.db.renderers.query().patch({
|
||
6 years ago
|
isEnabled: rdr.isEnabled,
|
||
|
config: _.reduce(rdr.config, (result, value, key) => {
|
||
5 years ago
|
_.set(result, `${value.key}`, _.get(JSON.parse(value.value), 'v', null))
|
||
6 years ago
|
return result
|
||
|
}, {})
|
||
|
}).where('key', rdr.key)
|
||
|
}
|
||
|
return {
|
||
2 years ago
|
responseResult: generateSuccess('Renderers updated successfully')
|
||
6 years ago
|
}
|
||
|
} catch (err) {
|
||
2 years ago
|
return generateError(err)
|
||
6 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|