feat: fetch page tree resolver

pull/1098/head
NGPixel 5 years ago
parent 38c33c58bb
commit 2a4b89859c

@ -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: {

@ -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
}

@ -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
} }

Loading…
Cancel
Save