feat: GraphQL setting, right, folder resolvers

This commit is contained in:
NGPixel 2017-08-19 22:51:25 -04:00
parent 02183f82ec
commit 574e4b97f4
12 changed files with 232 additions and 1 deletions

View File

@ -7,7 +7,9 @@ module.exports = db => {
db.User.belongsToMany(db.Group, { through: 'userGroups' })
db.Group.belongsToMany(db.User, { through: 'userGroups' })
db.Group.hasMany(db.Right)
db.Right.belongsTo(db.Group)
db.Document.belongsToMany(db.Tag, { through: 'documentTags' })
db.Document.hasMany(db.Comment)
db.Tag.belongsToMany(db.Document, { through: 'documentTags' })
db.File.belongsTo(db.Folder)
db.Folder.hasMany(db.File)

View File

@ -41,6 +41,11 @@ module.exports = (sequelize, DataTypes) => {
allowNull: false,
defaultValue: false
},
isDraft: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
searchContent: {
type: DataTypes.TEXT,
allowNull: true,

View File

@ -10,16 +10,20 @@ const _ = require('lodash')
const typeDefs = fs.readFileSync(path.join(wiki.SERVERPATH, 'schemas/types.graphql'), 'utf8')
const DateScalar = require('../schemas/scalar-date')
const CommentResolvers = require('../schemas/resolvers-comment')
const DocumentResolvers = require('../schemas/resolvers-document')
const FolderResolvers = require('../schemas/resolvers-folder')
const GroupResolvers = require('../schemas/resolvers-group')
const SettingResolvers = require('../schemas/resolvers-setting')
const TagResolvers = require('../schemas/resolvers-tag')
const UserResolvers = require('../schemas/resolvers-user')
const resolvers = _.merge(
CommentResolvers,
DocumentResolvers,
FolderResolvers,
GroupResolvers,
SettingResolvers,
TagResolvers,
UserResolvers,
DateScalar

View File

@ -0,0 +1,43 @@
'use strict'
/* global wiki */
module.exports = {
Query: {
comments(obj, args, context, info) {
return wiki.db.Comment.findAll({ where: args })
}
},
Mutation: {
createComment(obj, args) {
return wiki.db.Comment.create({
content: args.content,
author: args.userId,
document: args.documentId
})
},
deleteComment(obj, args) {
return wiki.db.Comment.destroy({
where: {
id: args.id
},
limit: 1
})
},
modifyComment(obj, args) {
return wiki.db.Comment.update({
content: args.content
}, {
where: { id: args.id }
})
}
},
Comment: {
author(cm) {
return cm.getAuthor()
},
document(cm) {
return cm.getDocument()
}
}
}

View File

@ -19,9 +19,27 @@ module.exports = {
},
limit: 1
})
},
modifyDocument(obj, args) {
return wiki.db.Document.update({
title: args.title,
subtitle: args.subtitle
}, {
where: { id: args.id }
})
},
moveDocument(obj, args) {
return wiki.db.Document.update({
path: args.path
}, {
where: { id: args.id }
})
}
},
Document: {
comments(doc) {
return doc.getComments()
},
tags(doc) {
return doc.getTags()
}

View File

@ -19,6 +19,13 @@ module.exports = {
},
limit: 1
})
},
renameFolder(obj, args) {
return wiki.db.Folder.update({
name: args.name
}, {
where: { id: args.id }
})
}
},
Folder: {

View File

@ -47,6 +47,13 @@ module.exports = {
return grp.removeUser(usr)
})
})
},
renameGroup(obj, args) {
return wiki.db.Group.update({
name: args.name
}, {
where: { id: args.id }
})
}
},
Group: {

View File

@ -0,0 +1,54 @@
'use strict'
/* global wiki */
const gql = require('graphql')
module.exports = {
Query: {
rights(obj, args, context, info) {
return wiki.db.Right.findAll({ where: args })
}
},
Mutation: {
addRightToGroup(obj, args) {
return wiki.db.Group.findById(args.groupId).then(grp => {
if (!grp) {
throw new gql.GraphQLError('Invalid Group ID')
}
return wiki.db.Right.create({
path: args.path,
role: args.role,
exact: args.exact,
allow: args.allow,
group: grp
})
})
},
removeRightFromGroup(obj, args) {
return wiki.db.Right.destroy({
where: {
id: args.rightId
},
limit: 1
})
},
modifyRight(obj, args) {
return wiki.db.Right.update({
path: args.path,
role: args.role,
exact: args.exact,
allow: args.allow
}, {
where: {
id: args.id
}
})
}
},
Right: {
group(rt) {
return rt.getGroup()
}
}
}

View File

@ -0,0 +1,25 @@
'use strict'
/* global wiki */
const _ = require('lodash')
module.exports = {
Query: {
settings(obj, args, context, info) {
return wiki.db.Setting.findAll({ where: args, raw: true }).then(entries => {
return _.map(entries, entry => {
entry.config = JSON.stringify(entry.config)
return entry
})
})
}
},
Mutation: {
setConfigEntry(obj, args) {
return wiki.db.Setting.update({
value: args.value
}, { where: { key: args.key } })
}
}
}

View File

@ -47,6 +47,13 @@ module.exports = {
return tag.removeDocument(doc)
})
})
},
renameTag(obj, args) {
return wiki.db.Group.update({
key: args.key
}, {
where: { id: args.id }
})
}
},
Tag: {

View File

@ -19,6 +19,23 @@ module.exports = {
},
limit: 1
})
},
modifyUser(obj, args) {
return wiki.db.User.update({
email: args.email,
name: args.name,
provider: args.provider,
providerId: args.providerId,
role: args.role
}, {
where: { id: args.id }
})
},
resetUserPassword(obj, args) {
return false
},
setUserPassword(obj, args) {
return false
}
},
User: {

View File

@ -52,6 +52,7 @@ type Document implements Base {
isDirectory: Boolean!
isEntry: Boolean!
searchContent: String
comments: [Comment]
tags: [Tag]
}
@ -93,6 +94,7 @@ type Right implements Base {
role: RightRole!
exact: Boolean!
allow: Boolean!
group: Group!
}
type Setting implements Base {
@ -145,6 +147,14 @@ type Query {
# Mutations (Create, Update, Delete)
type Mutation {
addRightToGroup(
groupId: Int!
path: String!
role: RightRole!
exact: Boolean!
allow: Boolean!
): Right
assignTagToDocument(
tagId: Int!
documentId: Int!
@ -155,6 +165,12 @@ type Mutation {
groupId: Int!
): OperationResult
createComment(
userId: Int!
documentId: Int!
content: String!
): Comment
createDocument(
path: String!
title: String!
@ -182,6 +198,10 @@ type Mutation {
role: UserRole!
): User
deleteComment(
id: Int!
): OperationResult
deleteDocument(
id: Int!
): OperationResult
@ -202,6 +222,11 @@ type Mutation {
id: Int!
): OperationResult
modifyComment(
id: Int!
content: String!
): Document
modifyDocument(
id: Int!
title: String
@ -217,6 +242,14 @@ type Mutation {
role: UserRole
): User
modifyRight(
id: Int!
path: String
role: RightRole
exact: Boolean
allow: Boolean
): Right
moveDocument(
id: Int!
path: String!
@ -234,7 +267,7 @@ type Mutation {
renameTag(
id: Int!
name: String!
key: String!
): OperationResult
removeTagFromDocument(
@ -242,6 +275,10 @@ type Mutation {
documentId: Int!
): OperationResult
removeRightFromGroup(
rightId: Int!
): OperationResult
removeUserFromGroup(
userId: Int!
groupId: Int!
@ -251,6 +288,11 @@ type Mutation {
id: Int!
): OperationResult
setConfigEntry(
key: String!
value: String!
): OperationResult
setUserPassword(
id: Int!
passwordRaw: String!