Commit 574e4b97 authored by NGPixel's avatar NGPixel

feat: GraphQL setting, right, folder resolvers

parent 02183f82
...@@ -7,7 +7,9 @@ module.exports = db => { ...@@ -7,7 +7,9 @@ module.exports = db => {
db.User.belongsToMany(db.Group, { through: 'userGroups' }) db.User.belongsToMany(db.Group, { through: 'userGroups' })
db.Group.belongsToMany(db.User, { through: 'userGroups' }) db.Group.belongsToMany(db.User, { through: 'userGroups' })
db.Group.hasMany(db.Right) db.Group.hasMany(db.Right)
db.Right.belongsTo(db.Group)
db.Document.belongsToMany(db.Tag, { through: 'documentTags' }) db.Document.belongsToMany(db.Tag, { through: 'documentTags' })
db.Document.hasMany(db.Comment)
db.Tag.belongsToMany(db.Document, { through: 'documentTags' }) db.Tag.belongsToMany(db.Document, { through: 'documentTags' })
db.File.belongsTo(db.Folder) db.File.belongsTo(db.Folder)
db.Folder.hasMany(db.File) db.Folder.hasMany(db.File)
......
...@@ -41,6 +41,11 @@ module.exports = (sequelize, DataTypes) => { ...@@ -41,6 +41,11 @@ module.exports = (sequelize, DataTypes) => {
allowNull: false, allowNull: false,
defaultValue: false defaultValue: false
}, },
isDraft: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
},
searchContent: { searchContent: {
type: DataTypes.TEXT, type: DataTypes.TEXT,
allowNull: true, allowNull: true,
......
...@@ -10,16 +10,20 @@ const _ = require('lodash') ...@@ -10,16 +10,20 @@ const _ = require('lodash')
const typeDefs = fs.readFileSync(path.join(wiki.SERVERPATH, 'schemas/types.graphql'), 'utf8') const typeDefs = fs.readFileSync(path.join(wiki.SERVERPATH, 'schemas/types.graphql'), 'utf8')
const DateScalar = require('../schemas/scalar-date') const DateScalar = require('../schemas/scalar-date')
const CommentResolvers = require('../schemas/resolvers-comment')
const DocumentResolvers = require('../schemas/resolvers-document') const DocumentResolvers = require('../schemas/resolvers-document')
const FolderResolvers = require('../schemas/resolvers-folder') const FolderResolvers = require('../schemas/resolvers-folder')
const GroupResolvers = require('../schemas/resolvers-group') const GroupResolvers = require('../schemas/resolvers-group')
const SettingResolvers = require('../schemas/resolvers-setting')
const TagResolvers = require('../schemas/resolvers-tag') const TagResolvers = require('../schemas/resolvers-tag')
const UserResolvers = require('../schemas/resolvers-user') const UserResolvers = require('../schemas/resolvers-user')
const resolvers = _.merge( const resolvers = _.merge(
CommentResolvers,
DocumentResolvers, DocumentResolvers,
FolderResolvers, FolderResolvers,
GroupResolvers, GroupResolvers,
SettingResolvers,
TagResolvers, TagResolvers,
UserResolvers, UserResolvers,
DateScalar DateScalar
......
'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()
}
}
}
...@@ -19,9 +19,27 @@ module.exports = { ...@@ -19,9 +19,27 @@ module.exports = {
}, },
limit: 1 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: { Document: {
comments(doc) {
return doc.getComments()
},
tags(doc) { tags(doc) {
return doc.getTags() return doc.getTags()
} }
......
...@@ -19,6 +19,13 @@ module.exports = { ...@@ -19,6 +19,13 @@ module.exports = {
}, },
limit: 1 limit: 1
}) })
},
renameFolder(obj, args) {
return wiki.db.Folder.update({
name: args.name
}, {
where: { id: args.id }
})
} }
}, },
Folder: { Folder: {
......
...@@ -47,6 +47,13 @@ module.exports = { ...@@ -47,6 +47,13 @@ module.exports = {
return grp.removeUser(usr) return grp.removeUser(usr)
}) })
}) })
},
renameGroup(obj, args) {
return wiki.db.Group.update({
name: args.name
}, {
where: { id: args.id }
})
} }
}, },
Group: { Group: {
......
'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()
}
}
}
'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 } })
}
}
}
...@@ -47,6 +47,13 @@ module.exports = { ...@@ -47,6 +47,13 @@ module.exports = {
return tag.removeDocument(doc) return tag.removeDocument(doc)
}) })
}) })
},
renameTag(obj, args) {
return wiki.db.Group.update({
key: args.key
}, {
where: { id: args.id }
})
} }
}, },
Tag: { Tag: {
......
...@@ -19,6 +19,23 @@ module.exports = { ...@@ -19,6 +19,23 @@ module.exports = {
}, },
limit: 1 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: { User: {
......
...@@ -52,6 +52,7 @@ type Document implements Base { ...@@ -52,6 +52,7 @@ type Document implements Base {
isDirectory: Boolean! isDirectory: Boolean!
isEntry: Boolean! isEntry: Boolean!
searchContent: String searchContent: String
comments: [Comment]
tags: [Tag] tags: [Tag]
} }
...@@ -93,6 +94,7 @@ type Right implements Base { ...@@ -93,6 +94,7 @@ type Right implements Base {
role: RightRole! role: RightRole!
exact: Boolean! exact: Boolean!
allow: Boolean! allow: Boolean!
group: Group!
} }
type Setting implements Base { type Setting implements Base {
...@@ -145,6 +147,14 @@ type Query { ...@@ -145,6 +147,14 @@ type Query {
# Mutations (Create, Update, Delete) # Mutations (Create, Update, Delete)
type Mutation { type Mutation {
addRightToGroup(
groupId: Int!
path: String!
role: RightRole!
exact: Boolean!
allow: Boolean!
): Right
assignTagToDocument( assignTagToDocument(
tagId: Int! tagId: Int!
documentId: Int! documentId: Int!
...@@ -155,6 +165,12 @@ type Mutation { ...@@ -155,6 +165,12 @@ type Mutation {
groupId: Int! groupId: Int!
): OperationResult ): OperationResult
createComment(
userId: Int!
documentId: Int!
content: String!
): Comment
createDocument( createDocument(
path: String! path: String!
title: String! title: String!
...@@ -182,6 +198,10 @@ type Mutation { ...@@ -182,6 +198,10 @@ type Mutation {
role: UserRole! role: UserRole!
): User ): User
deleteComment(
id: Int!
): OperationResult
deleteDocument( deleteDocument(
id: Int! id: Int!
): OperationResult ): OperationResult
...@@ -202,6 +222,11 @@ type Mutation { ...@@ -202,6 +222,11 @@ type Mutation {
id: Int! id: Int!
): OperationResult ): OperationResult
modifyComment(
id: Int!
content: String!
): Document
modifyDocument( modifyDocument(
id: Int! id: Int!
title: String title: String
...@@ -217,6 +242,14 @@ type Mutation { ...@@ -217,6 +242,14 @@ type Mutation {
role: UserRole role: UserRole
): User ): User
modifyRight(
id: Int!
path: String
role: RightRole
exact: Boolean
allow: Boolean
): Right
moveDocument( moveDocument(
id: Int! id: Int!
path: String! path: String!
...@@ -234,7 +267,7 @@ type Mutation { ...@@ -234,7 +267,7 @@ type Mutation {
renameTag( renameTag(
id: Int! id: Int!
name: String! key: String!
): OperationResult ): OperationResult
removeTagFromDocument( removeTagFromDocument(
...@@ -242,6 +275,10 @@ type Mutation { ...@@ -242,6 +275,10 @@ type Mutation {
documentId: Int! documentId: Int!
): OperationResult ): OperationResult
removeRightFromGroup(
rightId: Int!
): OperationResult
removeUserFromGroup( removeUserFromGroup(
userId: Int! userId: Int!
groupId: Int! groupId: Int!
...@@ -251,6 +288,11 @@ type Mutation { ...@@ -251,6 +288,11 @@ type Mutation {
id: Int! id: Int!
): OperationResult ): OperationResult
setConfigEntry(
key: String!
value: String!
): OperationResult
setUserPassword( setUserPassword(
id: Int! id: Int!
passwordRaw: String! passwordRaw: String!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment