feat: analytics modules backend + admin panel
This commit is contained in:
56
server/graph/resolvers/analytics.js
Normal file
56
server/graph/resolvers/analytics.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const _ = require('lodash')
|
||||
const graphHelper = require('../../helpers/graph')
|
||||
|
||||
/* global WIKI */
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
async analytics() { return {} }
|
||||
},
|
||||
Mutation: {
|
||||
async analytics() { return {} }
|
||||
},
|
||||
AnalyticsQuery: {
|
||||
async providers(obj, args, context, info) {
|
||||
let providers = await WIKI.models.analytics.getProviders(args.isEnabled)
|
||||
providers = providers.map(stg => {
|
||||
const providerInfo = _.find(WIKI.data.analytics, ['key', stg.key]) || {}
|
||||
return {
|
||||
...providerInfo,
|
||||
...stg,
|
||||
config: _.sortBy(_.transform(stg.config, (res, value, key) => {
|
||||
const configData = _.get(providerInfo.props, key, {})
|
||||
res.push({
|
||||
key,
|
||||
value: JSON.stringify({
|
||||
...configData,
|
||||
value
|
||||
})
|
||||
})
|
||||
}, []), 'key')
|
||||
}
|
||||
})
|
||||
return providers
|
||||
}
|
||||
},
|
||||
AnalyticsMutation: {
|
||||
async updateProviders(obj, args, context) {
|
||||
try {
|
||||
for (let str of args.providers) {
|
||||
await WIKI.models.analytics.query().patch({
|
||||
isEnabled: str.isEnabled,
|
||||
config: _.reduce(str.config, (result, value, key) => {
|
||||
_.set(result, `${value.key}`, _.get(JSON.parse(value.value), 'v', null))
|
||||
return result
|
||||
}, {})
|
||||
}).where('key', str.key)
|
||||
}
|
||||
return {
|
||||
responseResult: graphHelper.generateSuccess('Providers updated successfully')
|
||||
}
|
||||
} catch (err) {
|
||||
return graphHelper.generateError(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
server/graph/schemas/analytics.graphql
Normal file
53
server/graph/schemas/analytics.graphql
Normal file
@@ -0,0 +1,53 @@
|
||||
# ===============================================
|
||||
# ANALYTICS
|
||||
# ===============================================
|
||||
|
||||
extend type Query {
|
||||
analytics: AnalyticsQuery
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
analytics: AnalyticsMutation
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# QUERIES
|
||||
# -----------------------------------------------
|
||||
|
||||
type AnalyticsQuery {
|
||||
providers(
|
||||
isEnabled: Boolean
|
||||
): [AnalyticsProvider]
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# MUTATIONS
|
||||
# -----------------------------------------------
|
||||
|
||||
type AnalyticsMutation {
|
||||
updateProviders(
|
||||
providers: [AnalyticsProviderInput]!
|
||||
): DefaultResponse @auth(requires: ["manage:system"])
|
||||
}
|
||||
|
||||
# -----------------------------------------------
|
||||
# TYPES
|
||||
# -----------------------------------------------
|
||||
|
||||
type AnalyticsProvider {
|
||||
isEnabled: Boolean!
|
||||
key: String!
|
||||
props: [String]
|
||||
title: String!
|
||||
description: String
|
||||
isAvailable: Boolean
|
||||
logo: String
|
||||
website: String
|
||||
icon: String
|
||||
config: [KeyValuePair] @auth(requires: ["manage:system"])
|
||||
}
|
||||
input AnalyticsProviderInput {
|
||||
isEnabled: Boolean!
|
||||
key: String!
|
||||
config: [KeyValuePairInput]
|
||||
}
|
Reference in New Issue
Block a user