feat: fetch page tree resolver

This commit is contained in:
NGPixel 2019-10-07 23:38:06 -04:00
parent 38c33c58bb
commit 2a4b89859c
3 changed files with 56 additions and 0 deletions

View File

@ -115,6 +115,34 @@ module.exports = {
}, },
async tags (obj, args, context, info) { async tags (obj, args, context, info) {
return WIKI.models.tags.query().orderBy('tag', 'asc') return WIKI.models.tags.query().orderBy('tag', 'asc')
},
async tree (obj, args, context, info) {
let results = []
let conds = {
localeCode: args.locale,
parent: (args.parent < 1) ? null : args.parent
}
switch (args.mode) {
case 'FOLDERS':
conds.isFolder = true
results = await WIKI.models.knex('pageTree').where(conds)
break
case 'PAGES':
await WIKI.models.knex('pageTree').where(conds).andWhereNotNull('pageId')
break
default:
results = await WIKI.models.knex('pageTree').where(conds)
break
}
return results.filter(r => {
return WIKI.auth.checkAccess(context.req.user, ['read:pages'], {
path: r.path,
locale: r.localeCode
})
}).map(r => ({
...r,
locale: r.localeCode
}))
} }
}, },
PageMutation: { PageMutation: {

View File

@ -40,6 +40,12 @@ type PageQuery {
): Page @auth(requires: ["manage:pages", "delete:pages", "manage:system"]) ): Page @auth(requires: ["manage:pages", "delete:pages", "manage:system"])
tags: [PageTag]! @auth(requires: ["manage:system", "read:pages"]) tags: [PageTag]! @auth(requires: ["manage:system", "read:pages"])
tree(
parent: Int!
mode: PageTreeMode!
locale: String!
): [PageTreeItem] @auth(requires: ["manage:system", "read:pages"])
} }
# ----------------------------------------------- # -----------------------------------------------
@ -182,6 +188,19 @@ type PageListItem {
tags: [String] tags: [String]
} }
type PageTreeItem {
id: Int!
path: String!
depth: Int!
title: String!
isPrivate: Boolean!
isFolder: Boolean!
privateNS: String
parent: Int
pageId: Int
locale: String!
}
enum PageOrderBy { enum PageOrderBy {
CREATED CREATED
ID ID
@ -194,3 +213,9 @@ enum PageOrderByDirection {
ASC ASC
DESC DESC
} }
enum PageTreeMode {
FOLDERS
PAGES
ALL
}

View File

@ -43,6 +43,9 @@ module.exports = async (pageId) => {
pageId: isFolder ? null : page.id pageId: isFolder ? null : page.id
}) })
parentId = pik parentId = pik
} else if (isFolder && !found.isFolder) {
found.isFolder = true
parentId = found.id
} else { } else {
parentId = found.id parentId = found.id
} }