From 53ed92fd52d54a75dc52f90d329279459ffe2346 Mon Sep 17 00:00:00 2001 From: Pavlos Karakalidis Date: Sat, 8 May 2021 21:23:25 +0300 Subject: [PATCH] feat: add resolvers to accommodate for admin panel --- server/resolvers/account.js | 9 +++++++++ server/resolvers/author.js | 9 +++++++++ server/resolvers/index.js | 6 ++++-- server/resolvers/tag.js | 2 +- server/schemas/queries.graphql | 4 +++- server/schemas/types/account.graphql | 1 + server/schemas/types/author.graphql | 3 ++- server/schemas/types/comment.graphql | 1 + server/schemas/types/group.graphql | 1 + server/schemas/types/post.graphql | 2 ++ 10 files changed, 33 insertions(+), 5 deletions(-) diff --git a/server/resolvers/account.js b/server/resolvers/account.js index 3221f17..cd8d414 100644 --- a/server/resolvers/account.js +++ b/server/resolvers/account.js @@ -143,3 +143,12 @@ module.exports.findAccountById = async(_, args, req)=> { throw e; } }; + +module.exports.accountByUser = async(_, args, req)=> { + try { + return await AccountModel.findOne({user: args.id}); + } catch (e) { + console.log(e); + throw e; + } +}; diff --git a/server/resolvers/author.js b/server/resolvers/author.js index 912f341..2c71681 100644 --- a/server/resolvers/author.js +++ b/server/resolvers/author.js @@ -78,3 +78,12 @@ module.exports.deleteAuthor = async (_, args, req) => { throw new ForbiddenError('403-Forbidden'); } }; + +module.exports.authorByAccount = async(_, args, req)=> { + try { + return await AuthorModel.findOne({account: args.id}); + } catch (e) { + console.log(e); + throw e; + } +}; diff --git a/server/resolvers/index.js b/server/resolvers/index.js index 82f28be..b5e5dbb 100644 --- a/server/resolvers/index.js +++ b/server/resolvers/index.js @@ -1,5 +1,5 @@ -const {account, registerAccount, editAccount, deleteAccount, findAccountById} = require('./account'); -const {author, addAuthor, editAuthor, deleteAuthor} = require('./author'); +const {account, registerAccount, editAccount, deleteAccount, findAccountById, accountByUser} = require('./account'); +const {author, addAuthor, editAuthor, deleteAuthor, authorByAccount} = require('./author'); const {group, addGroup, editGroup, deleteGroup } = require('./group'); const {post, posts, addPost, editPost, deletePost, postsByTag} = require('./post'); const {tag, tags, addTag, editTag, deleteTag} = require('./tag'); @@ -8,7 +8,9 @@ const {getComment, getAllComments, addComment, editComment, deleteComment} = req module.exports.Query = { account, + accountByUser, author, + authorByAccount, findAccountById, findUserById, getAllComments, diff --git a/server/resolvers/tag.js b/server/resolvers/tag.js index 68ab158..a78259c 100644 --- a/server/resolvers/tag.js +++ b/server/resolvers/tag.js @@ -12,7 +12,7 @@ module.exports.tag = async(_, args, req) => { module.exports.tags = async (_, args, req) => { try { - return await TagModel.find({}); + return await TagModel.find({_id: {$exists: true}}); } catch (err) { console.log(err); } diff --git a/server/schemas/queries.graphql b/server/schemas/queries.graphql index 5618246..e582d76 100644 --- a/server/schemas/queries.graphql +++ b/server/schemas/queries.graphql @@ -12,10 +12,12 @@ type Query { posts: [Post!]! post(id: Int): Post! account(userID: Int): Account! + accountByUser(id: ID!): Account author(_id: String): Author! + authorByAccount(id: ID!): Author group(name: String!): Group! tag(name: String!): Tag! - tags: Tag! + tags: [Tag!] findAccountById(_id: String): Account findUserById(_id: String!): User postsByTag(tag: Int!): [Post!] diff --git a/server/schemas/types/account.graphql b/server/schemas/types/account.graphql index 471127a..6222e75 100644 --- a/server/schemas/types/account.graphql +++ b/server/schemas/types/account.graphql @@ -1,4 +1,5 @@ type Account { + _id: ID! user: User! isEnabled: Boolean! userID: Int! diff --git a/server/schemas/types/author.graphql b/server/schemas/types/author.graphql index 3e64242..f84eeb6 100644 --- a/server/schemas/types/author.graphql +++ b/server/schemas/types/author.graphql @@ -1,11 +1,12 @@ type Author { + _id: ID! account: Account! description: String! posts: [ID!]! } input AuthorInput { - _id: ID! + _id: ID account: ID! description: String! posts: [ID!] diff --git a/server/schemas/types/comment.graphql b/server/schemas/types/comment.graphql index edb4078..6ed0836 100644 --- a/server/schemas/types/comment.graphql +++ b/server/schemas/types/comment.graphql @@ -1,4 +1,5 @@ type Comment { + _id: ID! id: Int body: String! user: ID! diff --git a/server/schemas/types/group.graphql b/server/schemas/types/group.graphql index 995801e..f689270 100644 --- a/server/schemas/types/group.graphql +++ b/server/schemas/types/group.graphql @@ -1,4 +1,5 @@ type Group { + _id: ID! id: Int! name: String! members: [ID!]! diff --git a/server/schemas/types/post.graphql b/server/schemas/types/post.graphql index 604c945..77a7518 100644 --- a/server/schemas/types/post.graphql +++ b/server/schemas/types/post.graphql @@ -1,6 +1,7 @@ #import Comment from "./comment.graphql"; type Post { + _id: ID! title: String! id: Int! body: String! @@ -16,6 +17,7 @@ type Post { input PostInput { title: String! body: String! + summary: String author: ID! picture: [String] tags: [Int!]