Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

feat: add resolvers to accommodate for admin panel #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions server/resolvers/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
9 changes: 9 additions & 0 deletions server/resolvers/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
6 changes: 4 additions & 2 deletions server/resolvers/index.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -8,7 +8,9 @@ const {getComment, getAllComments, addComment, editComment, deleteComment} = req

module.exports.Query = {
account,
accountByUser,
author,
authorByAccount,
findAccountById,
findUserById,
getAllComments,
Expand Down
2 changes: 1 addition & 1 deletion server/resolvers/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion server/schemas/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!]
Expand Down
1 change: 1 addition & 0 deletions server/schemas/types/account.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type Account {
_id: ID!
user: User!
isEnabled: Boolean!
userID: Int!
Expand Down
3 changes: 2 additions & 1 deletion server/schemas/types/author.graphql
Original file line number Diff line number Diff line change
@@ -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!]
Expand Down
1 change: 1 addition & 0 deletions server/schemas/types/comment.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type Comment {
_id: ID!
id: Int
body: String!
user: ID!
Expand Down
1 change: 1 addition & 0 deletions server/schemas/types/group.graphql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type Group {
_id: ID!
id: Int!
name: String!
members: [ID!]!
Expand Down
2 changes: 2 additions & 0 deletions server/schemas/types/post.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import Comment from "./comment.graphql";

type Post {
_id: ID!
title: String!
id: Int!
body: String!
Expand All @@ -16,6 +17,7 @@ type Post {
input PostInput {
title: String!
body: String!
summary: String
author: ID!
picture: [String]
tags: [Int!]
Expand Down