chore: update subproject commit reference and enhance Quiz schema

- Updated the subproject commit reference in epess-database to the latest version.
- Enhanced QuizSchema by adding quizAttempt relation and submitQuiz mutation for improved quiz attempt handling.
- Updated Prisma types to include QuizAttempt, ensuring consistency across the application.
This commit is contained in:
2024-12-07 19:39:16 +07:00
parent 636be21a4c
commit 14a91a1885
4 changed files with 129 additions and 27 deletions

View File

@@ -51,39 +51,39 @@
"@nestjs/schedule": "^4.1.1",
"@nestjs/swagger": "^7.4.2",
"@payos/node": "^1.0.10",
"@pothos/core": "^4.3.0",
"@pothos/plugin-add-graphql": "^4.1.0",
"@pothos/plugin-authz": "^3.5.10",
"@pothos/plugin-errors": "^4.2.0",
"@pothos/plugin-prisma": "^4.3.0",
"@pothos/plugin-prisma-utils": "^1.2.0",
"@pothos/plugin-relay": "^4.3.0",
"@pothos/plugin-scope-auth": "^4.1.0",
"@pothos/plugin-simple-objects": "^4.1.0",
"@pothos/plugin-smart-subscriptions": "^4.1.0",
"@pothos/plugin-zod": "^4.1.0",
"@pothos/core": "4.3.0",
"@pothos/plugin-add-graphql": "4.2.1",
"@pothos/plugin-authz": "3.5.10",
"@pothos/plugin-errors": "4.2.0",
"@pothos/plugin-prisma": "4.4.0",
"@pothos/plugin-prisma-utils": "1.2.0",
"@pothos/plugin-relay": "4.3.0",
"@pothos/plugin-scope-auth": "4.1.1",
"@pothos/plugin-simple-objects": "4.1.0",
"@pothos/plugin-smart-subscriptions": "4.1.1",
"@pothos/plugin-zod": "4.1.0",
"@prisma/client": "^6.0.1",
"@smatch-corp/nestjs-pothos": "^0.3.0",
"@smatch-corp/nestjs-pothos-apollo-driver": "^0.1.0",
"@smatch-corp/nestjs-pothos": "0.3.0",
"@smatch-corp/nestjs-pothos-apollo-driver": "0.1.0",
"apollo-server-express": "^3.13.0",
"axios": "^1.7.7",
"axios": "1.7.9",
"bcryptjs": "^2.4.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"epess-web-backend": "file:",
"graphql": "^16.9.0",
"graphql": "16.9.0",
"graphql-redis-subscriptions": "^2.6.1",
"graphql-scalars": "^1.23.0",
"graphql-subscriptions": "^2.0.0",
"graphql-tools": "^9.0.1",
"graphql-upload": "15.0.2",
"graphql-tools": "9.0.6",
"graphql-upload": "17.0.0",
"graphql-ws": "^5.16.0",
"ioredis": "^5.4.1",
"jsonwebtoken": "^9.0.2",
"livekit-server-sdk": "2.9.2",
"luxon": "^3.5.0",
"minio": "^8.0.1",
"nestjs-minio": "^2.6.2",
"minio": "8.0.2",
"nestjs-minio": "2.6.2",
"nodemailer": "^6.9.15",
"openai": "^4.73.1",
"passport-jwt": "^4.0.1",

View File

@@ -71,6 +71,28 @@ export class QuizSchema extends PothosSchema {
})
}
@PothosRef()
quizAttempt() {
return this.builder.prismaObject('QuizAttempt', {
fields: (t) => ({
id: t.exposeID('id'),
quizId: t.exposeID('quizId'),
quiz: t.relation('quiz'),
userId: t.exposeID('userId'),
user: t.relation('user'),
score: t.exposeInt('score'),
questions: t.relation('questions'),
answers: t.exposeStringList('answers'),
createdAt: t.expose('createdAt', {
type: 'DateTime',
}),
updatedAt: t.expose('updatedAt', {
type: 'DateTime',
}),
}),
})
}
@PothosRef()
stringType() {
return this.builder.objectRef('StringType')
@@ -180,6 +202,41 @@ export class QuizSchema extends PothosSchema {
})
},
}),
submitQuiz: t.prismaField({
type: this.quizAttempt(),
args: {
data: t.arg({
type: this.builder.generator.getCreateInput('QuizAttempt', [
'id',
'createdAt',
'updatedAt',
'quiz',
'user',
'userId',
]),
}),
},
resolve: async (query, _root, args, ctx, _info) => {
if (ctx.isSubscription) throw new Error('Subscription is not allowed')
if (!ctx.http.me) throw new Error('User is not authenticated')
if (!args.data) throw new Error('Data is required')
if (!args.data.quiz?.connect?.id) throw new Error('Quiz ID is required')
// query the quiz to get the questions
const quiz = await this.prisma.quiz.findUnique({
where: { id: args.data.quiz.connect.id },
})
if (!quiz) throw new Error('Quiz not found')
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 } },
},
})
},
}),
}))
}
}

File diff suppressed because one or more lines are too long