2020-04-07 02:21:42 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
const graphHelper = require('../../helpers/graph')
|
|
|
|
|
|
|
|
/* global WIKI */
|
|
|
|
|
2017-08-20 02:51:25 +00:00
|
|
|
module.exports = {
|
2020-04-07 02:21:42 +00:00
|
|
|
Query: {
|
|
|
|
async comments() { return {} }
|
|
|
|
},
|
|
|
|
Mutation: {
|
|
|
|
async comments() { return {} }
|
|
|
|
},
|
|
|
|
CommentQuery: {
|
|
|
|
async providers(obj, args, context, info) {
|
|
|
|
const providers = await WIKI.models.commentProviders.getProviders()
|
|
|
|
return providers.map(provider => {
|
|
|
|
const providerInfo = _.find(WIKI.data.commentProviders, ['key', provider.key]) || {}
|
|
|
|
return {
|
|
|
|
...providerInfo,
|
|
|
|
...provider,
|
|
|
|
config: _.sortBy(_.transform(provider.config, (res, value, key) => {
|
|
|
|
const configData = _.get(providerInfo.props, key, false)
|
|
|
|
if (configData) {
|
|
|
|
res.push({
|
|
|
|
key,
|
|
|
|
value: JSON.stringify({
|
|
|
|
...configData,
|
|
|
|
value
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}, []), 'key')
|
|
|
|
}
|
|
|
|
})
|
2020-05-23 22:49:10 +00:00
|
|
|
},
|
|
|
|
async list (obj, args, context) {
|
|
|
|
return []
|
2020-04-07 02:21:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
CommentMutation: {
|
|
|
|
async updateProviders(obj, args, context) {
|
|
|
|
try {
|
|
|
|
for (let provider of args.providers) {
|
2020-05-17 02:46:05 +00:00
|
|
|
await WIKI.models.commentProviders.query().patch({
|
2020-04-07 02:21:42 +00:00
|
|
|
isEnabled: provider.isEnabled,
|
|
|
|
config: _.reduce(provider.config, (result, value, key) => {
|
|
|
|
_.set(result, `${value.key}`, _.get(JSON.parse(value.value), 'v', null))
|
|
|
|
return result
|
|
|
|
}, {})
|
|
|
|
}).where('key', provider.key)
|
|
|
|
}
|
2020-05-17 02:46:05 +00:00
|
|
|
await WIKI.models.commentProviders.initProvider()
|
2020-04-07 02:21:42 +00:00
|
|
|
return {
|
|
|
|
responseResult: graphHelper.generateSuccess('Comment Providers updated successfully')
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
return graphHelper.generateError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-20 02:51:25 +00:00
|
|
|
}
|