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.
wiki/server/graph/resolvers/page.js

64 lines
1.6 KiB

const graphHelper = require('../../helpers/graph')
/* global WIKI */
module.exports = {
Query: {
async pages() { return {} }
},
Mutation: {
async pages() { return {} }
},
PageQuery: {
async history(obj, args, context, info) {
return WIKI.models.pageHistory.getHistory({
pageId: args.id,
offsetPage: args.offsetPage || 0,
offsetSize: args.offsetSize || 100
})
},
async list(obj, args, context, info) {
return WIKI.models.pages.query().select(
7 years ago
'pages.*',
WIKI.models.pages.relatedQuery('users').count().as('userCount')
)
},
async single(obj, args, context, info) {
return WIKI.models.pages.query().findById(args.id)
}
},
PageMutation: {
7 years ago
async create(obj, args, context) {
const page = await WIKI.models.pages.createPage({
...args,
7 years ago
authorId: context.req.user.id
})
return {
7 years ago
responseResult: graphHelper.generateSuccess('Page created successfully.'),
page
}
},
async delete(obj, args) {
await WIKI.models.groups.query().deleteById(args.id)
return {
7 years ago
responseResult: graphHelper.generateSuccess('Page has been deleted.')
}
},
async update(obj, args, context) {
const page = await WIKI.models.pages.updatePage({
...args,
authorId: context.req.user.id
})
return {
responseResult: graphHelper.generateSuccess('Page has been updated.'),
page
}
}
},
Page: {
// comments(pg) {
// return pg.$relatedQuery('comments')
// }
}
}