From de11d38ad75ccba84ea21c9fcf7c3e5158679f21 Mon Sep 17 00:00:00 2001 From: yeon Date: Thu, 12 Dec 2019 16:16:18 +0900 Subject: [PATCH] =?UTF-8?q?[Add]=20feed=201=EA=B0=9C=20=EA=B0=80=EC=A7=80?= =?UTF-8?q?=EA=B3=A0=20=EC=98=A4=EB=8A=94=20api=20#86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 피드 1개 가지고오는 api 상세페이지 피드정보를 보여주기위해서 --- server/src/api/feed/feed.graphql | 1 + server/src/api/feed/feed.resolvers.ts | 17 +++++++++++++++-- server/src/schema/feed/query.ts | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/server/src/api/feed/feed.graphql b/server/src/api/feed/feed.graphql index b52fa7cf..72c2310d 100644 --- a/server/src/api/feed/feed.graphql +++ b/server/src/api/feed/feed.graphql @@ -77,6 +77,7 @@ type Query { feeds(first: Int, cursor: String): IFeeds alarms: [Alarm] alarmCount: Int! + feed(feedId: Int!): IFeed } type Mutation { diff --git a/server/src/api/feed/feed.resolvers.ts b/server/src/api/feed/feed.resolvers.ts index 42c4c6d0..3fa0df45 100644 --- a/server/src/api/feed/feed.resolvers.ts +++ b/server/src/api/feed/feed.resolvers.ts @@ -34,7 +34,8 @@ import { QueryResolvers, QueryFeedsArgs, MutationWriteCommentArgs, - Alarm + Alarm, + QueryFeedArgs } from '../../types'; const DEFAUT_MAX_DATE = '9999-12-31T09:29:26.050Z'; @@ -71,7 +72,7 @@ const createImages = async (pubsub, email, feedId, files) => { const publishingFeed = async (pubsub, feedId, email) => { const registerdFeed = await requestDB(GET_NEW_FEED, { feedId, - useremail: email + userEmail: email }); const parsedRegisterdFeed = parseResultRecords(registerdFeed); @@ -279,6 +280,18 @@ const queryResolvers: QueryResolvers = { const [parsedAlarmCount] = parseResultRecords(result); return Number(parsedAlarmCount.alarmCount); + }, + feed: async (_, { feedId }: QueryFeedArgs, { req }): Promise => { + isAuthenticated(req); + const userEmail = req.email; + + const feed = await requestDB(GET_NEW_FEED, { + feedId, + userEmail + }); + const [parsedFeed] = parseResultRecords(feed); + + return parsedFeed; } }; diff --git a/server/src/schema/feed/query.ts b/server/src/schema/feed/query.ts index 88101ab8..424c8272 100644 --- a/server/src/schema/feed/query.ts +++ b/server/src/schema/feed/query.ts @@ -30,7 +30,7 @@ OPTIONAL MATCH (feed)<-[:HAS]-(img:Image) WITH searchUser, feed, COLLECT(DISTINCT likeUser) AS cp , COLLECT(com) as comments, COLLECT(DISTINCT img) as imgs where ID(feed) = {feedId} RETURN searchUser , feed, ID(feed) as feedId , length(cp) AS totallikes, imgs as imglist, -length(filter(x IN cp WHERE x.email= {useremail} )) AS hasLiked, comments +length(filter(x IN cp WHERE x.email= {userEmail} )) AS hasLiked, comments order by feed.createdAt desc `;