Skip to content

Commit

Permalink
[Merge] feed alarm api merge #53
Browse files Browse the repository at this point in the history
client์ชฝ graphql ๋ฐ์ดํ„ฐ ์š”์ฒญ์„ ์œ„ํ•ด์„œ ์•Œ๋ฆผ์ •๋ณด ๋ฐ›์•„์˜ค๋Š” api(#24) cherry pick
  • Loading branch information
WooYeonSeo committed Dec 8, 2019
1 parent 6e77d25 commit 59380c1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
19 changes: 19 additions & 0 deletions client/src/composition/Header/Alarm/feedAlarm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { useSubscribeFeedSubscription } from 'react-components.d';

const FeedAlarm = () => {
const { data, loading } = useSubscribeFeedSubscription({
variables: {
userEmail: ''
}
});

console.log(data);
return (
<>
<div>feed alarms : </div>
</>
);
};

export default FeedAlarm;
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Footer = styled(CommonFooter)`
`;

function AlarmTabPresenter() {
// const alarms
return (
<Container>
<Header>
Expand Down
12 changes: 11 additions & 1 deletion server/src/api/feed/feed.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
DELETE_LIKE,
GET_NEW_FEED,
GET_FRIENDS,
WRITE_COMMENT
WRITE_COMMENT,
ALARM_NEW_FEED
} from '../../schema/feed/query';
import { parseResultRecords } from '../../utils/parseData';

Expand All @@ -27,6 +28,7 @@ import {
QueryFeedsArgs,
MutationWriteCommentArgs
} from '../../types';
import console = require('console');

const DEFAUT_MAX_DATE = '9999-12-31T09:29:26.050Z';

Expand Down Expand Up @@ -103,6 +105,12 @@ const mutationResolvers: MutationResolvers = {
} else {
publishingFeed(pubsub, feedId, email);
}

await requestDB(ALARM_NEW_FEED, {
feedId,
userEmail: email
});

return true;
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -140,6 +148,7 @@ const mutationResolvers: MutationResolvers = {
feedId,
content
});

return true;
} catch (error) {
const DBError = createDBError(error);
Expand Down Expand Up @@ -186,6 +195,7 @@ export default {
feeds: {
subscribe: withFilter(
(_, __, { pubsub }) => {
console.log('subscribed');
return pubsub.asyncIterator(NEW_FEED);
},
async (payload, _, context) => {
Expand Down
25 changes: 12 additions & 13 deletions server/src/schema/feed/query.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
/* export const MATCH_FEEDS = `MATCH (searchUser:User)-[:AUTHOR]->(feed:Feed)
OPTIONAL MATCH (likeUser:User)-[like:LIKE]->(feed)
OPTIONAL MATCH (feed)-[:HAS]->(com:Comment)
OPTIONAL MATCH (feed)<-[:HAS]-(img:Image)
WITH searchUser, feed, COLLECT(DISTINCT likeUser) AS cp , com, COLLECT(DISTINCT img) as imgs
ORDER BY com.createdAt
where feed.createdAt < datetime({cursor})
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, COLLECT(com) as comments
order by feed.createdAt desc
LIMIT {first}
`; */

export const MATCH_FEEDS = `MATCH (searchUser:User)-[:AUTHOR]->(feed:Feed)
OPTIONAL MATCH (likeUser:User)-[like:LIKE]->(feed)
OPTIONAL MATCH (feed)-[:HAS]->(com:Comment)<-[:AUTHOR]-(w:User)
Expand Down Expand Up @@ -66,3 +53,15 @@ WHERE ID(f) = {feedId}
CREATE (c:Comment {content: {content} ,createdAt: datetime()})
CREATE (f)-[r:HAS]->(c)
CREATE (u)-[wr:AUTHOR]->(c)`;

export const ALARM_NEW_FEED = `
MATCH (searchUser:User)-[:FRIEND]-(friend:User), (f:Feed)
WHERE searchUser.email = {userEmail} and ID(f)={feedId}
MERGE (f)-[al:ALARM{isRead:false}]->(friend)
return searchUser,al,friend
`;

export const DELETE_ALARM = `
MATCH (f:Feed{ID:{feedId}})-[al:ALARM{isRead:true}]->(fr:User{email:{userEmail}})
delete al
return f, al,fr`;

0 comments on commit 59380c1

Please sign in to comment.