From fb9a632d558d9e6eb8a4d1b3f499ce91a093645e Mon Sep 17 00:00:00 2001 From: Matt Rider Date: Thu, 1 Aug 2019 15:11:41 +0200 Subject: [PATCH] Query a currentUsers emotions for a post, translations --- .../src/middleware/permissionsMiddleware.js | 1 + backend/src/schema/resolvers/posts.js | 23 ++++- backend/src/schema/types/type/Post.gql | 3 +- .../EmotionsButtons/EmotionsButtons.vue | 83 ++++++++++++------- webapp/locales/de.json | 8 ++ webapp/locales/en.json | 8 ++ 6 files changed, 93 insertions(+), 33 deletions(-) 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 @@