diff --git a/src/Type_Definitions/Comment_Comment.js b/src/Type_Definitions/Comment_Comment.js index dc744e4..c16f8ba 100644 --- a/src/Type_Definitions/Comment_Comment.js +++ b/src/Type_Definitions/Comment_Comment.js @@ -46,6 +46,7 @@ const commentDefs = gql` input VoteCommentInput { commentId: ID! action: voteCommentAction! + userId: ID! } input CreateCommentInput { @@ -77,7 +78,7 @@ const commentDefs = gql` votes: Int! children: [Comment] - userVotePost: [String]! + userVoteComment: [String]! } `; diff --git a/src/prisma/ERD.svg b/src/prisma/ERD.svg index 008d66f..e09bb50 100644 --- a/src/prisma/ERD.svg +++ b/src/prisma/ERD.svg @@ -1 +1 @@ -ViewStatusPUBLICPUBLICONLY_FOLLOWERSONLY_FOLLOWERSPRIVATEPRIVATEUserStringz_idPKStringemailStringphoneNumberStringhashPasswordStringnameStringprofileImageURLStringbackgroundImageURLIntageStringbirthdayIntisAdminDateTimecreatedAtDateTimeupdatedAtStringchatIDsStringcourseIDsReportStringz_idPKBooleanisFinishedStringreasonStringpostIdStringuserIdStringuserReportedFollowerStringz_idPKStringuserFollowerStringuserIdFollowingStringz_idPKStringuserFollowingStringuserIdLevelStringz_idPKIntcurrentXPIntcurrentLevelStringuserIdImageStringz_idPKStringurlStringhashDateTimecreatedAtDateTimeupdatedAtStringpostIdImageInfoStringz_idPKStringcameraStringlensStringapertureStringfocalLengthStringshutterSpeedStringISOStringtakenWhenStringcopyRightStringimageIdCategoryStringz_idPKStringnameDateTimecreatedAtDateTimeupdatedAtStringpostsAlbumStringz_idPKStringnameDateTimecreatedAtDateTimeupdatedAtStringuserIdStringpostsTagStringz_idPKStringnameDateTimecreatedAtDateTimeupdatedAtPostStringz_idPKStringtitleStringcaptionDateTimecreatedAtDateTimeupdatedAtViewStatuspostViewStatusIntpointsStringuserIdStringcategoryIdStringalbumIdStringtagStringuserLikedPostStoryStringz_idPKStringtitleViewStatusstoryViewStatusDateTimecreatedAtDateTimeupdatedAtIntpointsStringcontentStringimagesStringuserIdStringuserLikedStoryCommentStringz_idPKStringcontentnullableDateTimecreatedAtStringuserIdStringpostIdnullableStringstoryIdnullableStringparentIdnullableIntvotesContestStringz_idPKStringnameDateTimecreatedAtDateTimeupdatedAtCourseStringz_idPKStringuserIDsLessonStringz_idPKStringcontentStringcourseIdMessageStringz_idPKStringcontentnullableDateTimecreatedAtBooleanisImageStringuserIdStringchatIdChatStringz_idPKDateTimecreatedAtStringuserIDsuser_to_chatuser_to_coursefollower_to_userfollowing_to_userlevel_to_userimage_to_postimageInfo_to_imagecategory_to_postalbum_to_useralbum_to_postenum:postViewStatuspost_to_userpost_to_categorypost_to_albumenum:storyViewStatusstory_to_usercmt_to_usercmt_to_postcmt_to_storyparentcourse_to_userlesson_to_coursemessage_to_usermessage_to_chatchat_to_user \ No newline at end of file +ViewStatusPUBLICPUBLICONLY_FOLLOWERSONLY_FOLLOWERSPRIVATEPRIVATEUserStringz_idPKStringemailStringphoneNumberStringhashPasswordStringnameStringprofileImageURLStringbackgroundImageURLIntageStringbirthdayIntisAdminDateTimecreatedAtDateTimeupdatedAtStringchatIDsStringcourseIDsReportStringz_idPKBooleanisFinishedStringreasonStringpostIdStringuserIdStringuserReportedFollowerStringz_idPKStringuserFollowerStringuserIdFollowingStringz_idPKStringuserFollowingStringuserIdLevelStringz_idPKIntcurrentXPIntcurrentLevelStringuserIdImageStringz_idPKStringurlStringhashDateTimecreatedAtDateTimeupdatedAtStringpostIdImageInfoStringz_idPKStringcameraStringlensStringapertureStringfocalLengthStringshutterSpeedStringISOStringtakenWhenStringcopyRightStringimageIdCategoryStringz_idPKStringnameDateTimecreatedAtDateTimeupdatedAtStringpostsAlbumStringz_idPKStringnameDateTimecreatedAtDateTimeupdatedAtStringuserIdStringpostsTagStringz_idPKStringnameDateTimecreatedAtDateTimeupdatedAtPostStringz_idPKStringtitleStringcaptionDateTimecreatedAtDateTimeupdatedAtViewStatuspostViewStatusIntpointsStringuserIdStringcategoryIdStringalbumIdStringtagStringuserLikedPostStoryStringz_idPKStringtitleViewStatusstoryViewStatusDateTimecreatedAtDateTimeupdatedAtIntpointsStringcontentStringimagesStringuserIdStringuserLikedStoryCommentStringz_idPKStringcontentnullableDateTimecreatedAtStringuserIdStringpostIdnullableStringstoryIdnullableStringparentIdnullableIntvotesStringuserVoteCommentContestStringz_idPKStringnameDateTimecreatedAtDateTimeupdatedAtCourseStringz_idPKStringuserIDsLessonStringz_idPKStringcontentStringcourseIdMessageStringz_idPKStringcontentnullableDateTimecreatedAtBooleanisImageStringuserIdStringchatIdChatStringz_idPKDateTimecreatedAtStringuserIDsuser_to_chatuser_to_coursefollower_to_userfollowing_to_userlevel_to_userimage_to_postimageInfo_to_imagecategory_to_postalbum_to_useralbum_to_postenum:postViewStatuspost_to_userpost_to_categorypost_to_albumenum:storyViewStatusstory_to_usercmt_to_usercmt_to_postcmt_to_storyparentcourse_to_userlesson_to_coursemessage_to_usermessage_to_chatchat_to_user \ No newline at end of file diff --git a/src/prisma/schema.prisma b/src/prisma/schema.prisma index 53e2a5b..242b707 100644 --- a/src/prisma/schema.prisma +++ b/src/prisma/schema.prisma @@ -229,6 +229,7 @@ model Comment { children Comment[] @relation(name: "Comment_Children") votes Int @default(0) + userVoteComment String[] } model Contest { diff --git a/src/resolvers/Mutation/comment.js b/src/resolvers/Mutation/comment.js index ba0b7cc..9a0815f 100644 --- a/src/resolvers/Mutation/comment.js +++ b/src/resolvers/Mutation/comment.js @@ -87,12 +87,12 @@ const commentMutation = { /** * * @param {*} parent - * @param {{data: {commentId: string, action: UPVOTE | DOWNVOTE}}} args + * @param {{data: {commentId: string, userId: string, action: UPVOTE | DOWNVOTE}}} args * @param {*} info * @returns */ voteComment: async (parent, args, info) => { - const { action, commentId } = args.data; + const { action, commentId, userId } = args.data; const existedComment = await prisma.comment.findUnique({ where: { @@ -104,6 +104,10 @@ const commentMutation = { throw Error('Comment Not Exsited'); } + if (existedComment.userVoteComment.length > 0 && existedComment.userVoteComment.includes(userId)) { + throw Error('User has voted this comment already'); + } + switch (action) { case VOTE_COMMENT_ACTION.DOWNVOTE: return await prisma.comment.update({ @@ -112,6 +116,9 @@ const commentMutation = { }, data: { votes: existedComment.votes - 1, + userVoteComment: { + push: userId + } }, }); @@ -122,6 +129,9 @@ const commentMutation = { }, data: { votes: existedComment.votes + 1, + userVoteComment: { + push: userId + } }, }); default: