Skip to content

Commit

Permalink
update noti
Browse files Browse the repository at this point in the history
  • Loading branch information
HUNG-rushb committed Dec 2, 2023
1 parent 4051401 commit 3614f5f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Type_Definitions/User_User.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const userDefs = gql`
extend type Query {
allUsers: [User]!
userInfo(data: UserInfoInput!): User!
userFollow(data: UserInfoInput!): UserFollow!
verifyUser(data: VerifyUserInput!): User!
suggestUserToFollow(
data: SuggestUserToFollowInput!
Expand All @@ -19,6 +20,11 @@ const userDefs = gql`
getUserFollowingLeaderBoard(data: UserFollowingLeaderInput!): [User]!
}
type UserFollow {
follower: Follower!
following: Following!
}
type UserPagination {
edges: [UserEdge!]!
pageInfo: PageInfo!
Expand All @@ -43,6 +49,10 @@ const userDefs = gql`
userId: ID!
}
input UserInfoInput {
userId: ID!
}
input UserFollowingLeaderInput {
userId: ID!
}
Expand Down
20 changes: 20 additions & 0 deletions src/resolvers/Mutation/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,26 @@ const postMutation = {
},
},
});

const a = await prisma.notification.create({
data: {
type: 'POST_LIKED',
postId: post.id,
userTriggerId: args.data.likedUserId,
userIds: [post.userId],
},
});
console.log({ a });

sendNotificationToClient(
[
'eUW71E0j4VAwZdHuyjdnQd:APA91bFKKXAsu_RxExCsDDK7V0AaqvHF9tW51bUBBDUkbvtxHEe9DpnFMhUfvgwVSAoud89y1rHxpeeEesWZZ9hkqAkkEMoP-7ys6QjYekcLln-bnXvvWfdG2ISZGwLtIm0iVH526VLr',
],
{
title: 'Notify user like post',
body: JSON.stringify({ post, likedUserId: args.data.likedUserId }),
},
);
} else {
const { userLikedPost } = await prisma.post.findUnique({
where: {
Expand Down
16 changes: 16 additions & 0 deletions src/resolvers/Query/USER.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ const userQuery = {
},
});
},

userFollow: async (parent, args, info) => {
const follower = await prisma.follower.findUnique({
where: {
userId: args.data.userId,
},
});

const following = await prisma.following.findUnique({
where: {
userId: args.data.userId,
},
});

return { follower, following };
},
verifyUser: async (parent, args, info) => {
return await prisma.user.findFirst({
where: {
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/Type/Notification___.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Notification = {
userTriggerId: async (parent, args, info) => {
return await prisma.user.findUnique({
where: {
id: parent.userId,
id: parent.userTriggerId,
},
});
},
Expand Down

0 comments on commit 3614f5f

Please sign in to comment.