Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/chandan1971/Mind_Set into c…
Browse files Browse the repository at this point in the history
…handan
  • Loading branch information
chandan1971 committed Mar 13, 2024
2 parents 7e1fc96 + 6ff04da commit 3892d57
Show file tree
Hide file tree
Showing 37 changed files with 1,122 additions and 491 deletions.
178 changes: 136 additions & 42 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,39 @@ datasource db {
}

model User {
id Int @id @default(autoincrement())
email String @unique
username String? @unique
id Int @id @default(autoincrement())
userInformation UserInformation
authentication Authentication
userContribution UserContribution
userTraining UserTraining
}

model Authentication {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int @unique
otpForEmail String?
otpEmailExpiry DateTime?
otpForExtra String?
otpExtraExpiry DateTime?
isVerified Boolean @default(false)
isBoarded Boolean @default(false)
}

model UserInformation {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int @unique
email String @unique
username String? @unique
name String?
password String
mobileNum String?
role Roles @default(USER)
role Roles @default(USER)
profilePic String?
gender Gender?
college_id String?
graduation_year Int?
collegeId String?
graduationYear Int?
cgpa Float?
college String?
department Department?
Expand All @@ -31,21 +53,115 @@ model User {
leetcodeProfile String?
codeforcesProfile String?
linkedinProfile String?
githubProfile String?
questions Question[]
authentication Authentication?
githubProfile String?
}

model Authentication {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int @unique
otpForEmail String?
otpEmailExpiry DateTime?
otpForPasswordChange String?
otpPasswordChangeExpiry DateTime?
isVerified Boolean @default(false)
isBoarded Boolean @default(false)
model UserContribution {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int @unique
interview Interview
questions Question
quizes Quiz
articles Article
contributionPoints Int @default(0)
}

model UserTraining {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int @unique
interview Interview
quizes Quiz
trainingPoints Int @default(0)
}

model Question {
id Int @id @default(autoincrement())
description String
answer String?
creator UserContribution @relation(fields: [createdBy], references: [id])
createdBy Int
tags String[]?
links QueAddOnLink[]?
isApproved Boolean @default(false)
isVisibile Boolean @default(false)
upvotes Int @default(0)
downvotes Int @default(0)
}

model QueAddOnLink {
id Int @id @default(autoincrement())
question Question @relation(fields: [questionId], references: [id])
questionId Int
title String
url String
}

model Quiz {
id Int @id @default(autoincrement())
creator User @relation(fields: [createdBy], references: [id])
createdBy Int
title String
description String?
questions QuizQuestion[]
startTime DateTime
endTime DateTime
isVisibile Boolean @default(false)
attendees QuizAttendance[]
}

model QuizAttendance {
id Int @id @default(autoincrement())
quiz Quiz @relation(fields: [quizId], references: [id])
quizId Int
attendee User @relation(fields: [userId], references: [id])
userId Int
score Int
}

model QuizQuestion {
id Int @id @default(autoincrement())
quiz Quiz @relation(fields: [quizId], references: [id])
quizId Int
description String
options String[4]
correctOption Int
}

model Article {
id Int @id @default(autoincrement())
creator User @relation(fields: [createdBy], references: [id])
createdBy Int
title String
description String
isApproved Boolean @default(false)
isVisibile Boolean @default(false)
}

model Interview {
id Int @id @default(autoincrement())
interviewer UserContribution @relation(fields: [interviewerId], references: [id])
interviewee UserInformation @relation(fields: [intervieweeId], references: [id])
interviewerId Int
intervieweeId Int
startTime DateTime
duration Int
topics String[]
isCompleted Boolean @default(false)
feedback Feedback
}

model Feedback {
id Int @id @default(autoincrement())
interview Interview @relation(fields: [interviewId], references: [id])
interviewId Int @unique
communication Int @default(0)
development Int @default(0)
dsa Int @default(0)
csfundamentals Int @default(0)
notes String[]?
points Int @default(0)
}

enum Roles {
Expand Down Expand Up @@ -79,26 +195,4 @@ enum Course {
PhD
MCA
MTech
}

model Question {
id Int @id @default(autoincrement())
title String
description String
answer String?
user User @relation(fields: [postedBy], references: [id])
postedBy Int
tags String[]
links QueAddOnLink[]
isApproved Boolean @default(false)
upvotes Int @default(0)
downvotes Int @default(0)
}

model QueAddOnLink {
id Int @id @default(autoincrement())
title String
url String
question Question @relation(fields: [questionId], references: [id])
questionId Int
}
}
25 changes: 18 additions & 7 deletions backend/src/controllers/Auth/checkOTPForEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const checkOtpForEmail = async (_, payload) => {
authentication: true,
},
})

const token = generateJwtToken(user.id)
return {
token,
Expand Down Expand Up @@ -78,11 +78,22 @@ export const checkOtpForEmail = async (_, payload) => {
})
}
} catch (error) {
console.log('Error while checking otp for email : ', error);
throw new GraphQLError('Error while checking otp for email', {
extensions: {
code: 'OTP_VERIFICATION_FAILED',
},
})
console.log('Error while checking otp for email : ', error)
if (
error.extensions &&
(error.extensions.code === 'USER_NOT_FOUND' ||
error.extensions.code === 'ALREADY_VERIFIED' ||
error.extensions.code === 'OTP_NOT_SENT' ||
error.extensions.code === 'OTP_EXPIRED' ||
error.extensions.code === 'INVALID_OTP')
) {
throw error
} else {
throw new GraphQLError('Error while checking otp for email', {
extensions: {
code: 'OTP_VERIFICATION_FAILED',
},
})
}
}
}
10 changes: 5 additions & 5 deletions backend/src/controllers/Auth/generateJWT.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import JWT from 'jsonwebtoken'
export const generateJwtToken = (id) => {
const token = JWT.sign({ id }, process.env.JWT_SECRET, {
expiresIn: process.env.JWT_EXPIRATION,
})
return token
}
const token = JWT.sign({ id }, process.env.JWT_SECRET, {
expiresIn: process.env.JWT_EXPIRATION,
})
return token
}
41 changes: 26 additions & 15 deletions backend/src/controllers/Auth/onboardUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ export const onboardUser = async (_, payload, context) => {
console.log('UserInput for Onboarding: ' + JSON.stringify(payload.user))

const usernameExist = await prisma.user.findFirst({
where : { username: payload.user.username}
where: { username: payload.user.username },
})

if(usernameExist) {
throw new GraphQLError('Username already exist', {
extensions: {
code: 'USERNAME_ALREADY_EXISTS',
},
})
if (usernameExist) {
throw new GraphQLError(
'Username already exist, Please Select a different.',
{
extensions: {
code: 'USERNAME_ALREADY_EXISTS',
},
}
)
}

const user = await prisma.user.update({
Expand All @@ -29,21 +32,29 @@ export const onboardUser = async (_, payload, context) => {
...payload.user,
},
})

return user
}

throw new GraphQLError('User is not registered yet!!', {
extensions: {
code: 'NOT_REGISTERED',
},
})
} catch (error) {
console.log('Error while onboarding user : ', error);
throw new GraphQLError('Error while onboarding user', {
extensions: {
code: 'ONBOARD_FAILED',
},
})
console.log('Error while onboarding user : ', error)
if (
error.extensions &&
(error.extensions.code === 'USERNAME_ALREADY_EXISTS' ||
error.extensions.code === 'NOT_REGISTERED')
) {
throw error
} else {
throw new GraphQLError('Error while onboarding user', {
extensions: {
code: 'ONBOARD_FAILED',
},
})
}
}
}
Loading

0 comments on commit 3892d57

Please sign in to comment.