Skip to content

Commit

Permalink
some changes to allow posts
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomein committed Sep 1, 2019
1 parent 7bfb86f commit 30f642b
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion graphql/resolvers/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
const post = await Post.findById(postId);

if (post) {
const commentIndex = post.comments.findIndex(c => c.id === commentId);
const commentIndex = post.comments.findIndex((c) => c.id === commentId);

if (post.comments[commentIndex].username === username) {
post.comments.splice(commentIndex, 1);
Expand Down
4 changes: 2 additions & 2 deletions graphql/resolvers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const commentsResolvers = require('./comments');

module.exports = {
Post: {
likeCount: parent => parent.likes.length,
commentCount: parent => parent.comments.length
likeCount: (parent) => parent.likes.length,
commentCount: (parent) => parent.comments.length
},
Query: {
...postsResolvers.Query
Expand Down
8 changes: 4 additions & 4 deletions graphql/resolvers/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ module.exports = {
Mutation: {
async createPost(_, { body }, context) {
const user = checkAuth(context);

if (args.body.trim() === '') {
throw new Error('Post body must not be empty');
}
// console.log(args);
// if (args.body.trim() === '') {
// throw new Error('Post body must not be empty');
// }

const newPost = new Post({
body,
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ mongoose
console.log('MongoDB Connected');
return server.listen({ port: 5000 });
})
.then(res => {
.then((res) => {
console.log(`Server running at ${res.url}`);
});
2 changes: 1 addition & 1 deletion util/check-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { AuthenticationError } = require('apollo-server');
const jwt = require('jsonwebtoken');
const { SECRET_KEY } = require('../config');

module.exports = context => {
module.exports = (context) => {
// context = { ... headers }
const authHeader = context.req.headers.authorization;
if (authHeader) {
Expand Down

0 comments on commit 30f642b

Please sign in to comment.