feat: GraphQL mutations for folder, group, tag, user
This commit is contained in:
29
server/schemas/resolvers-folder.js
Normal file
29
server/schemas/resolvers-folder.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
folders(obj, args, context, info) {
|
||||
return wiki.db.Folder.findAll({ where: args })
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
createFolder(obj, args) {
|
||||
return wiki.db.Folder.create(args)
|
||||
},
|
||||
deleteGroup(obj, args) {
|
||||
return wiki.db.Folder.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
},
|
||||
limit: 1
|
||||
})
|
||||
}
|
||||
},
|
||||
Folder: {
|
||||
files(grp) {
|
||||
return grp.getFiles()
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,8 @@
|
||||
|
||||
/* global wiki */
|
||||
|
||||
const gql = require('graphql')
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
groups(obj, args, context, info) {
|
||||
@@ -9,8 +11,42 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
assignUserToGroup(obj, args) {
|
||||
return wiki.db.Group.findById(args.groupId).then(grp => {
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
return wiki.db.User.findById(args.userId).then(usr => {
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
return grp.addUser(usr)
|
||||
})
|
||||
})
|
||||
},
|
||||
createGroup(obj, args) {
|
||||
return wiki.db.Group.create(args)
|
||||
},
|
||||
deleteGroup(obj, args) {
|
||||
return wiki.db.Group.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
},
|
||||
limit: 1
|
||||
})
|
||||
},
|
||||
removeUserFromGroup(obj, args) {
|
||||
return wiki.db.Group.findById(args.groupId).then(grp => {
|
||||
if (!grp) {
|
||||
throw new gql.GraphQLError('Invalid Group ID')
|
||||
}
|
||||
return wiki.db.User.findById(args.userId).then(usr => {
|
||||
if (!usr) {
|
||||
throw new gql.GraphQLError('Invalid User ID')
|
||||
}
|
||||
return grp.removeUser(usr)
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
Group: {
|
||||
|
57
server/schemas/resolvers-tag.js
Normal file
57
server/schemas/resolvers-tag.js
Normal file
@@ -0,0 +1,57 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
const gql = require('graphql')
|
||||
|
||||
module.exports = {
|
||||
Query: {
|
||||
tags(obj, args, context, info) {
|
||||
return wiki.db.Tag.findAll({ where: args })
|
||||
}
|
||||
},
|
||||
Mutation: {
|
||||
assignTagToDocument(obj, args) {
|
||||
return wiki.db.Tag.findById(args.tagId).then(tag => {
|
||||
if (!tag) {
|
||||
throw new gql.GraphQLError('Invalid Tag ID')
|
||||
}
|
||||
return wiki.db.Document.findById(args.documentId).then(doc => {
|
||||
if (!doc) {
|
||||
throw new gql.GraphQLError('Invalid Document ID')
|
||||
}
|
||||
return tag.addDocument(doc)
|
||||
})
|
||||
})
|
||||
},
|
||||
createTag(obj, args) {
|
||||
return wiki.db.Tag.create(args)
|
||||
},
|
||||
deleteTag(obj, args) {
|
||||
return wiki.db.Tag.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
},
|
||||
limit: 1
|
||||
})
|
||||
},
|
||||
removeTagFromDocument(obj, args) {
|
||||
return wiki.db.Tag.findById(args.tagId).then(tag => {
|
||||
if (!tag) {
|
||||
throw new gql.GraphQLError('Invalid Tag ID')
|
||||
}
|
||||
return wiki.db.Document.findById(args.documentId).then(doc => {
|
||||
if (!doc) {
|
||||
throw new gql.GraphQLError('Invalid Document ID')
|
||||
}
|
||||
return tag.removeDocument(doc)
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
Tag: {
|
||||
documents(tag) {
|
||||
return tag.getDocuments()
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,6 +11,14 @@ module.exports = {
|
||||
Mutation: {
|
||||
createUser(obj, args) {
|
||||
return wiki.db.User.create(args)
|
||||
},
|
||||
deleteUser(obj, args) {
|
||||
return wiki.db.User.destroy({
|
||||
where: {
|
||||
id: args.id
|
||||
},
|
||||
limit: 1
|
||||
})
|
||||
}
|
||||
},
|
||||
User: {
|
||||
|
@@ -73,6 +73,7 @@ type Folder implements Base {
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
name: String!
|
||||
files: [File]
|
||||
}
|
||||
|
||||
type Group implements Base {
|
||||
@@ -107,7 +108,8 @@ type Tag implements Base {
|
||||
id: Int!
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
key: String!
|
||||
key: String!,
|
||||
documents: [Document]
|
||||
}
|
||||
|
||||
# A User
|
||||
@@ -138,13 +140,23 @@ type Query {
|
||||
|
||||
# Mutations (Create, Update, Delete)
|
||||
type Mutation {
|
||||
assignTagToDocument(
|
||||
tagId: Int!
|
||||
documentId: Int!
|
||||
): Boolean
|
||||
assignUserToGroup(
|
||||
userId: Int!
|
||||
groupId: Int!
|
||||
): Boolean
|
||||
createFolder(
|
||||
name: String!
|
||||
): Folder
|
||||
createGroup(
|
||||
name: String!
|
||||
): Group
|
||||
createTag(
|
||||
name: String!
|
||||
): Tag
|
||||
createUser(
|
||||
email: String!
|
||||
name: String
|
||||
@@ -152,12 +164,22 @@ type Mutation {
|
||||
providerId: String
|
||||
role: UserRole!
|
||||
): User
|
||||
deleteFolder(
|
||||
id: Int!
|
||||
): Boolean
|
||||
deleteGroup(
|
||||
id: Int!
|
||||
): Boolean
|
||||
deleteTag(
|
||||
id: Int!
|
||||
): Boolean
|
||||
deleteUser(
|
||||
id: Int!
|
||||
): Boolean
|
||||
removeTagFromDocument(
|
||||
tagId: Int!
|
||||
documentId: Int!
|
||||
): Boolean
|
||||
removeUserFromGroup(
|
||||
userId: Int!
|
||||
groupId: Int!
|
||||
|
Reference in New Issue
Block a user