feat: add grammar check functionality and enhance quiz schema
- Introduced a new 'testCheckGrammar' field in DocumentSchema to facilitate grammar checking for documents, leveraging the document service for processing. - Updated DocumentService to implement grammar checking logic, including caching results and publishing suggestions. - Enhanced QuizSchema by adding filter arguments for quiz attempts, allowing for more flexible data retrieval based on user and quiz IDs. - Cleaned up whitespace and improved error handling in quiz attempt creation to ensure better user feedback. These changes improve the document editing experience and enhance the quiz feature's data handling capabilities.
This commit is contained in:
@@ -269,10 +269,18 @@ export class QuizSchema extends PothosSchema {
|
||||
quizAttempts: t.prismaField({
|
||||
type: [this.quizAttempt()],
|
||||
args: {
|
||||
filter: t.arg({
|
||||
type: this.builder.generator.getWhere('QuizAttempt'),
|
||||
required: false,
|
||||
}),
|
||||
quizId: t.arg({
|
||||
type: 'String',
|
||||
required: false,
|
||||
}),
|
||||
userId: t.arg({
|
||||
type: 'String',
|
||||
required: false,
|
||||
}),
|
||||
},
|
||||
resolve: async (query, _root, args, ctx, _info) => {
|
||||
if (ctx.isSubscription) {
|
||||
@@ -292,10 +300,15 @@ export class QuizSchema extends PothosSchema {
|
||||
return await this.prisma.quizAttempt.findMany({
|
||||
...query,
|
||||
where: {
|
||||
...args.filter,
|
||||
quiz: {
|
||||
centerMentorId: centerMentor.mentorId,
|
||||
},
|
||||
...(args.quizId ? [{ quizId: args.quizId }] : []),
|
||||
...(args.userId ? [{ quizId: args.userId }] : []),
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -307,6 +320,9 @@ export class QuizSchema extends PothosSchema {
|
||||
userId: ctx.http.me.id,
|
||||
...(args.quizId ? [{ quizId: args.quizId }] : []),
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
@@ -407,14 +423,18 @@ export class QuizSchema extends PothosSchema {
|
||||
if (!quiz) {
|
||||
throw new Error('Quiz not found')
|
||||
}
|
||||
return await this.prisma.quizAttempt.create({
|
||||
...query,
|
||||
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 } },
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
} catch (_error) {
|
||||
throw new Error('Quiz attempt already exists')
|
||||
}
|
||||
},
|
||||
}),
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user