wikijs-fork/server/graph/resolvers/page.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-05-20 22:50:51 +00:00
const graphHelper = require('../../helpers/graph')
/* global WIKI */
module.exports = {
Query: {
async pages() { return {} }
},
Mutation: {
async pages() { return {} }
},
PageQuery: {
async list(obj, args, context, info) {
return WIKI.models.pages.query().select(
2018-07-22 04:29:39 +00:00
'pages.*',
WIKI.models.pages.relatedQuery('users').count().as('userCount')
2018-05-20 22:50:51 +00:00
)
},
async single(obj, args, context, info) {
return WIKI.models.pages.query().findById(args.id)
2018-05-20 22:50:51 +00:00
}
},
PageMutation: {
2018-07-22 04:29:39 +00:00
async create(obj, args, context) {
const page = await WIKI.models.pages.createPage({
...args,
2018-07-22 04:29:39 +00:00
authorId: context.req.user.id
2018-05-20 22:50:51 +00:00
})
return {
2018-07-22 04:29:39 +00:00
responseResult: graphHelper.generateSuccess('Page created successfully.'),
page
2018-05-20 22:50:51 +00:00
}
},
async delete(obj, args) {
await WIKI.models.groups.query().deleteById(args.id)
2018-05-20 22:50:51 +00:00
return {
2018-07-22 04:29:39 +00:00
responseResult: graphHelper.generateSuccess('Page has been deleted.')
2018-05-20 22:50:51 +00:00
}
},
async update(obj, args, context) {
const page = await WIKI.models.pages.updatePage({
...args,
authorId: context.req.user.id
})
2018-05-20 22:50:51 +00:00
return {
responseResult: graphHelper.generateSuccess('Page has been updated.'),
page
2018-05-20 22:50:51 +00:00
}
}
},
Page: {
// comments(pg) {
// return pg.$relatedQuery('comments')
// }
}
}