Skip to content

Commit

Permalink
Merge pull request #209 from ChetanSaini12/main
Browse files Browse the repository at this point in the history
Experience Page
  • Loading branch information
ChetanSaini12 authored Jul 1, 2024
2 parents 29ecd44 + aa4eeff commit 36a38b1
Show file tree
Hide file tree
Showing 23 changed files with 823 additions and 418 deletions.
64 changes: 32 additions & 32 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"@apollo/server": "^4.10.0",
"@graphql-tools/merge": "^9.0.4",
"@prisma/client": "^5.9.1",
"@prisma/client": "^5.16.1",
"all": "^0.0.0",
"bcryptjs": "^2.4.3",
"cloudinary": "^2.2.0",
Expand All @@ -36,6 +36,6 @@
"devDependencies": {
"nodemon": "^3.0.3",
"prettier": "^3.2.4",
"prisma": "^5.8.1"
"prisma": "^5.16.1"
}
}
7 changes: 6 additions & 1 deletion backend/src/controllers/Experience/Comment/addCommentExp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { prisma } from '../../../../prisma/index.js'
import { GraphQLError } from 'graphql'
import { addUserName } from './addUserName.js'
import { addLikeStatus } from '../../../utils/addLikeStatus.js'
export const addCommentExp = async (_, payload, context) => {
try {
/*
Expand All @@ -17,8 +18,12 @@ export const addCommentExp = async (_, payload, context) => {
experienceId: payload.Comment.experienceId,
commentorId: context.userId,
},
include : {
reply : true
}
})
expComment = addUserName(expComment)
expComment = await addLikeStatus(expComment, context.userId, 'EXP_COMMENT')
expComment = await addUserName(expComment)
return expComment
} else {
throw new GraphQLError('User is not authorised', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GraphQLError } from 'graphql'
import { prisma } from '../../../../prisma/index.js'
import { addUserName } from './addUserName.js'
import { addLikeStatus } from '../../../utils/addLikeStatus.js'

export const addReplyToExpComment = async (_, payload, context) => {
try {
Expand Down Expand Up @@ -32,7 +33,8 @@ export const addReplyToExpComment = async (_, payload, context) => {
replierId: context.userId,
},
})
expReply = addUserName(expReply)
expReply = await addLikeStatus(expReply, context.userId, 'EXP_REPLY')
expReply = await addUserName(expReply)
return expReply
} else {
throw new GraphQLError('User is not authorised', {
Expand Down
42 changes: 37 additions & 5 deletions backend/src/controllers/Experience/Comment/likeExpComment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GraphQLError } from 'graphql'
import { prisma } from '../../../../prisma/index.js'
import { addUserName } from './addUserName.js'
import { addLikeStatus } from '../../../utils/addLikeStatus.js'

export const likeExpComment = async (_, payload, context) => {
try {
Expand All @@ -25,14 +26,14 @@ export const likeExpComment = async (_, payload, context) => {
const voteEntry = await prisma.userVotes.findFirst({
where: {
userId: context.userId,
area: 'COMMENT',
area: 'EXP_COMMENT',
areaId: payload.commentId,
},
})
if (voteEntry) {
await prisma.userVotes.delete({
where: {
id: voteEntry.id
id: voteEntry.id,
},
})
let likedComment = await prisma.expComment.update({
Expand All @@ -44,14 +45,29 @@ export const likeExpComment = async (_, payload, context) => {
decrement: 1,
},
},
include: {
reply: true,
},
})
likedComment = addUserName(likedComment)
likedComment = await addLikeStatus(
likedComment,
context.userId,
'EXP_COMMENT'
)
likedComment = await addUserName(likedComment)
for (let i = 0; i < likedComment.reply.length; i++) {
likedComment.reply[i] = await addLikeStatus(
likedComment.reply[i],
context.userId,
'EXP_REPLY'
)
}
return likedComment
}
await prisma.userVotes.create({
data: {
userId: context.userId,
area: 'COMMENT',
area: 'EXP_COMMENT',
areaId: payload.commentId,
type: 'LIKE',
},
Expand All @@ -65,8 +81,23 @@ export const likeExpComment = async (_, payload, context) => {
increment: 1,
},
},
include: {
reply: true,
},
})
likedComment = addUserName(likedComment)
likedComment = await addLikeStatus(
likedComment,
context.userId,
'EXP_COMMENT'
)
likedComment = await addUserName(likedComment)
for (let i = 0; i < likedComment.reply.length; i++) {
likedComment.reply[i] = await addLikeStatus(
likedComment.reply[i],
context.userId,
'EXP_REPLY'
)
}
return likedComment
} else {
throw new GraphQLError('You are not authorised user!!', {
Expand All @@ -84,6 +115,7 @@ export const likeExpComment = async (_, payload, context) => {
) {
throw error
}
console.log('Error while liking comment : ', error)
throw new GraphQLError('Something went wrong!!')
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GraphQLError } from 'graphql'
import { prisma } from '../../../../prisma/index.js'
import { addUserName } from './addUserName.js'
import { addLikeStatus } from '../../../utils/addLikeStatus.js'

export const likeExpCommentReply = async (_, payload, context) => {
try {
Expand All @@ -26,7 +27,7 @@ export const likeExpCommentReply = async (_, payload, context) => {
const voteEntry = await prisma.userVotes.findFirst({
where: {
userId: context.userId,
area: 'REPLY',
area: 'EXP_REPLY',
areaId: replyId,
},
})
Expand All @@ -42,14 +43,15 @@ export const likeExpCommentReply = async (_, payload, context) => {
},
},
})
likedReply = addUserName(likedReply)
likedReply = await addLikeStatus(likedReply, context.userId, 'EXP_REPLY')
likedReply = await addUserName(likedReply)
return likedReply
}

await prisma.userVotes.create({
data: {
userId: context.userId,
area: 'REPLY',
area: 'EXP_REPLY',
areaId: replyId,
type: 'LIKE',
},
Expand All @@ -65,7 +67,8 @@ export const likeExpCommentReply = async (_, payload, context) => {
},
},
})
likedReply = addUserName(likedReply)
likedReply = await addLikeStatus(likedReply, context.userId, 'EXP_REPLY')
likedReply = await addUserName(likedReply)
return likedReply
} else {
throw new GraphQLError('You are not authorised user!!', {
Expand Down
27 changes: 21 additions & 6 deletions backend/src/controllers/Experience/downvoteExperience.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { GraphQLError } from 'graphql'
import { prisma } from '../../../prisma/index.js'
import { addNameExp } from './addnameExp.js'
import { addLikeStatus } from '../../utils/addLikeStatus.js'
import { addUserName } from './Comment/addUserName.js'
import { formatExp } from './formatExp.js'

export const downvoteExperience = async (_, payload, context) => {
try {
Expand All @@ -26,10 +29,14 @@ export const downvoteExperience = async (_, payload, context) => {
},
},
include: {
comments: true,
comments: {
include: {
reply: true,
},
},
},
})
experience = addNameExp(experience)
experience = await formatExp(experience, context)
return experience
} else {
await prisma.userVotes.update({
Expand All @@ -53,10 +60,14 @@ export const downvoteExperience = async (_, payload, context) => {
},
},
include: {
comments: true,
comments: {
include: {
reply: true,
},
},
},
})
experience = addNameExp(experience)
experience = await formatExp(experience, context)
return experience
}
} else {
Expand All @@ -78,10 +89,14 @@ export const downvoteExperience = async (_, payload, context) => {
},
},
include: {
comments: true,
comments: {
include: {
reply: true,
},
},
},
})
experience = addNameExp(experience)
experience = await formatExp(experience, context)
return experience
}
} else {
Expand Down
Loading

0 comments on commit 36a38b1

Please sign in to comment.