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,
|
2018-11-25 23:25:52 +00:00
|
|
|
offsetPage: args.offsetPage || 0,
|
|
|
|
offsetSize: args.offsetSize || 100
|
2018-11-25 06:28:20 +00:00
|
|
|
})
|
2019-03-09 05:51:02 +00:00
|
|
|
},
|
|
|
|
async search (obj, args, context) {
|
|
|
|
if (WIKI.data.searchEngine) {
|
|
|
|
return WIKI.data.searchEngine.query(args.query, args)
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
results: [],
|
|
|
|
suggestions: [],
|
|
|
|
totalHits: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2019-04-07 22:10:44 +00:00
|
|
|
async list (obj, args, context, info) {
|
|
|
|
return WIKI.models.pages.query().column([
|
|
|
|
'id',
|
|
|
|
'path',
|
|
|
|
{ locale: 'localeCode' },
|
|
|
|
'title',
|
|
|
|
'description',
|
|
|
|
'isPublished',
|
|
|
|
'isPrivate',
|
|
|
|
'privateNS',
|
|
|
|
'contentType',
|
|
|
|
'createdAt',
|
|
|
|
'updatedAt'
|
|
|
|
])
|
|
|
|
}
|
2018-05-20 22:50:51 +00:00
|
|
|
},
|
|
|
|
PageMutation: {
|
2018-07-22 04:29:39 +00:00
|
|
|
async create(obj, args, context) {
|
2018-07-30 02:23:33 +00:00
|
|
|
const page = await WIKI.models.pages.createPage({
|
2018-07-22 20:25:39 +00:00
|
|
|
...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
|
|
|
}
|
|
|
|
},
|
2018-07-23 01:13:01 +00:00
|
|
|
async update(obj, args, context) {
|
2018-07-30 02:23:33 +00:00
|
|
|
const page = await WIKI.models.pages.updatePage({
|
2018-07-23 01:13:01 +00:00
|
|
|
...args,
|
|
|
|
authorId: context.req.user.id
|
|
|
|
})
|
2018-05-20 22:50:51 +00:00
|
|
|
return {
|
2018-07-23 01:13:01 +00:00
|
|
|
responseResult: graphHelper.generateSuccess('Page has been updated.'),
|
|
|
|
page
|
2018-05-20 22:50:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Page: {
|
|
|
|
// comments(pg) {
|
|
|
|
// return pg.$relatedQuery('comments')
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|