feat: implement AI suggestion
This commit is contained in:
@@ -190,6 +190,9 @@ export class QuizSchema extends PothosSchema {
|
||||
if (!schedule) {
|
||||
throw new Error('Schedule not found')
|
||||
}
|
||||
if (schedule.customerId !== ctx.http.me.id) {
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
// get centerMentorId from schedule
|
||||
const centerMentorId = schedule.managedService.mentorId
|
||||
if (!centerMentorId) {
|
||||
@@ -202,6 +205,16 @@ export class QuizSchema extends PothosSchema {
|
||||
centerMentorId: centerMentorId,
|
||||
},
|
||||
})
|
||||
// check if user has already taken the quiz
|
||||
const quizAttempt = await this.prisma.quizAttempt.findFirst({
|
||||
where: {
|
||||
userId: ctx.http.me.id,
|
||||
quizId: quizzes[0]?.id,
|
||||
},
|
||||
})
|
||||
if (quizAttempt) {
|
||||
throw new Error('User has already taken the quiz')
|
||||
}
|
||||
// get amount of questions using nrOfQuestions and random index based on random
|
||||
const randomIndex = quizzes.length > 0 ? Math.floor(random * quizzes.length) : 0
|
||||
const nrOfQuestions = quizzes[0]?.nrOfQuestions ?? 1
|
||||
@@ -426,10 +439,10 @@ export class QuizSchema extends PothosSchema {
|
||||
try {
|
||||
return await this.prisma.quizAttempt.create({
|
||||
...query,
|
||||
data: {
|
||||
...args.data,
|
||||
quiz: { connect: { id: args.data.quiz.connect.id } },
|
||||
user: { connect: { id: ctx.http.me.id } },
|
||||
data: {
|
||||
...args.data,
|
||||
quiz: { connect: { id: args.data.quiz.connect.id } },
|
||||
user: { connect: { id: ctx.http.me.id } },
|
||||
},
|
||||
})
|
||||
} catch (_error) {
|
||||
|
||||
Reference in New Issue
Block a user