Skip to content

Commit

Permalink
[Add] feed 1개 가지고 오는 api #86
Browse files Browse the repository at this point in the history
피드 1개 가지고오는 api
상세페이지 피드정보를 보여주기위해서
  • Loading branch information
WooYeonSeo committed Dec 12, 2019
1 parent 58eb256 commit de11d38
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions server/src/api/feed/feed.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type Query {
feeds(first: Int, cursor: String): IFeeds
alarms: [Alarm]
alarmCount: Int!
feed(feedId: Int!): IFeed
}

type Mutation {
Expand Down
17 changes: 15 additions & 2 deletions server/src/api/feed/feed.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
QueryResolvers,
QueryFeedsArgs,
MutationWriteCommentArgs,
Alarm
Alarm,
QueryFeedArgs
} from '../../types';

const DEFAUT_MAX_DATE = '9999-12-31T09:29:26.050Z';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -279,6 +280,18 @@ const queryResolvers: QueryResolvers = {
const [parsedAlarmCount] = parseResultRecords(result);

return Number(parsedAlarmCount.alarmCount);
},
feed: async (_, { feedId }: QueryFeedArgs, { req }): Promise<any> => {
isAuthenticated(req);
const userEmail = req.email;

const feed = await requestDB(GET_NEW_FEED, {
feedId,
userEmail
});
const [parsedFeed] = parseResultRecords(feed);

return parsedFeed;
}
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/schema/feed/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
`;

Expand Down

0 comments on commit de11d38

Please sign in to comment.