diff --git a/backend/src/middleware/permissionsMiddleware.js b/backend/src/middleware/permissionsMiddleware.js index 9e8f5dacb..dc685e20c 100644 --- a/backend/src/middleware/permissionsMiddleware.js +++ b/backend/src/middleware/permissionsMiddleware.js @@ -166,6 +166,7 @@ const permissions = shield( isLoggedIn: allow, Badge: allow, postsEmotionsCountByEmotion: allow, + postsEmotionsCountByCurrentUser: allow, }, Mutation: { '*': deny, diff --git a/backend/src/schema/resolvers/posts.js b/backend/src/schema/resolvers/posts.js index 54351ffbb..cca2ba463 100644 --- a/backend/src/schema/resolvers/posts.js +++ b/backend/src/schema/resolvers/posts.js @@ -110,12 +110,12 @@ export default { Query: { postsEmotionsCountByEmotion: async (object, params, context, resolveInfo) => { const session = context.driver.session() - const { id, data } = params + const { postId, data } = params const transactionRes = await session.run( - `MATCH (post:Post {id: $id})<-[emoted:EMOTED {emotion: $data.emotion}]-() + `MATCH (post:Post {id: $postId})<-[emoted:EMOTED {emotion: $data.emotion}]-() RETURN COUNT(DISTINCT emoted) as emotionsCount `, - { id, data }, + { postId, data }, ) session.close() @@ -124,5 +124,22 @@ export default { }) return emotionsCount }, + postsEmotionsCountByCurrentUser: async (object, params, context, resolveInfo) => { + const session = context.driver.session() + const { postId } = params + const transactionRes = await session.run( + `MATCH (user:User {id: $userId})-[emoted:EMOTED]->(post:Post {id: $postId}) + RETURN emoted.emotion as emotion`, + { userId: context.user.id, postId }, + ) + + session.close() + let emotionsArray = [] + transactionRes.records.map(record => { + emotionsArray.push(record.get('emotion')) + }) + + return emotionsArray + }, }, } diff --git a/backend/src/schema/types/type/Post.gql b/backend/src/schema/types/type/Post.gql index 8aa2aee92..ba2b6ceef 100644 --- a/backend/src/schema/types/type/Post.gql +++ b/backend/src/schema/types/type/Post.gql @@ -95,5 +95,6 @@ type Mutation { } type Query { - postsEmotionsCountByEmotion(id: ID!, data: _EMOTEDInput!): Int! + postsEmotionsCountByEmotion(postId: ID!, data: _EMOTEDInput!): Int! + postsEmotionsCountByCurrentUser(postId: ID!): [String] } diff --git a/webapp/components/EmotionsButtons/EmotionsButtons.vue b/webapp/components/EmotionsButtons/EmotionsButtons.vue index 0bc217f64..b115e4bf3 100644 --- a/webapp/components/EmotionsButtons/EmotionsButtons.vue +++ b/webapp/components/EmotionsButtons/EmotionsButtons.vue @@ -1,7 +1,7 @@