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

58 lines
1.3 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: {
2018-11-25 06:28:20 +00:00
async history(obj, args, context, info) {
return WIKI.models.pageHistory.getHistory({
pageId: args.id,
offsetPage: args.offsetPage || 0,
offsetSize: args.offsetSize || 100
2018-11-25 06:28:20 +00:00
})
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
}
},
2019-01-26 23:35:56 +00:00
async delete(obj, args, context) {
await WIKI.models.pages.deletePage({
...args,
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 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')
// }
}
}